Skip to content

feat: enhance Nix build and switch commands to support named and auto-detected hosts - #715

Merged
shunkakinoki merged 1 commit into
mainfrom
makefile-detect-host
Feb 3, 2026
Merged

feat: enhance Nix build and switch commands to support named and auto-detected hosts#715
shunkakinoki merged 1 commit into
mainfrom
makefile-detect-host

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Feb 3, 2026

Copy link
Copy Markdown
Owner

Changes

  • Enhanced nix-build and nix-switch Makefile targets to support named host configuration via HOST variable
  • Added auto-detection support using DETECTED_HOST variable
  • Falls back to NIX_SYSTEM when neither HOST nor DETECTED_HOST is set
  • Added informational echo statements to display which host is being built/switched
  • Updated dotagents submodule

Technical Details

The changes improve flexibility in building and switching Nix configurations by:

  • Prioritizing explicitly named hosts (HOST) for targeted builds
  • Supporting auto-detected hosts (DETECTED_HOST) for convenience
  • Maintaining backward compatibility with existing NIX_SYSTEM usage
  • Providing clear console output for debugging and transparency

Both nix-build and nix-switch targets now follow the same host resolution logic, ensuring consistency between build and activation workflows.

Testing

  • Verified host selection logic with HOST variable
  • Confirmed auto-detection works with DETECTED_HOST variable
  • Tested fallback to NIX_SYSTEM when both variables are unset
  • Validated informational output displays correctly for all scenarios

Generated with Claude Code by glm-4.7


Summary by cubic

Add host selection to nix-build and nix-switch using HOST and DETECTED_HOST, with fallback to NIX_SYSTEM and clearer logs. This makes targeted builds/switches easier and keeps behavior consistent.

  • New Features

    • Host resolution order: HOST → DETECTED_HOST → NIX_SYSTEM.
    • Echo which host is being built/switched.
    • Same host logic for both build and switch targets.
  • Dependencies

    • Updated dotagents submodule.

Written for commit bee485f. Summary will update on new commits.

Copilot AI review requested due to automatic review settings February 3, 2026 12:20
@shunkakinoki shunkakinoki added the enhancement Indicates new feature requests. label Feb 3, 2026
@coderabbitai

coderabbitai Bot commented Feb 3, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Build and switch operations now support automatic host detection and configuration routing.
  • Chores

    • Updated submodule dependency.

Walkthrough

The pull request modifies the Makefile to add host-aware routing logic for nixosConfigurations builds and switches, conditionally selecting targets based on HOST or DETECTED_HOST variables. Additionally, the dotagents submodule pointer is updated to a newer commit.

Changes

Cohort / File(s) Summary
Makefile host-aware nixosConfigurations routing
Makefile
Added conditional logic to honor HOST or DETECTED_HOST in nix-build and nix-switch targets for nixosConfigurations, routing to the appropriate flake target with corresponding host messages. Non-CI behavior preserved for other NIX_CONFIG_TYPE branches and CI paths.
Submodule update
dotagents
Updated submodule pointer to a newer commit (565bbe58ded57d48484c1e81c9731085761e66b8).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • #714: Adds host detection and target selection logic to Makefile, overlapping with the host-aware routing introduced here.
  • #712: Updates the dotagents submodule pointer, directly matching the submodule change in this PR.
  • #613: Modifies Makefile host-related behavior and dotagents integration, intersecting with both changes in this PR.

Poem

🐰 A rabbit hops through the Makefile maze,
HOST-aware builds set nixos ablaze,
DETECTED_HOST finds the right way to go,
Submodules leap where the dotagents flow! 🌙✨

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch makefile-detect-host

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shunkakinoki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the flexibility and clarity of managing NixOS configurations by introducing advanced host selection capabilities for both building and activating systems. It allows users to specify a target host, leverage auto-detection, or default to the system's configured host, ensuring a more streamlined and transparent workflow for multi-host Nix environments.

Highlights

  • Enhanced Nix Build/Switch Host Selection: The nix-build and nix-switch Makefile targets for NixOS configurations now support explicit host selection via a HOST variable and automatic detection using a DETECTED_HOST variable.
  • Host Resolution Priority: Host resolution logic has been implemented to prioritize an explicitly provided HOST, then an auto-detected DETECTED_HOST, falling back to the existing NIX_SYSTEM if neither is set.
  • Informational Output: Informative echo statements have been added to both nix-build and nix-switch targets to clearly display which host configuration is being built or switched.
  • Submodule Update: The dotagents Git submodule has been updated to a newer commit, reflecting upstream changes.
Changelog
  • Makefile
    • Modified the nix-build target for nixosConfigurations to incorporate conditional logic that checks for the presence of HOST, then DETECTED_HOST, before using NIX_SYSTEM.
    • Added echo commands within the nix-build target to output the name of the host being built.
    • Implemented similar conditional logic within the nix-switch target for nixosConfigurations to prioritize HOST, then DETECTED_HOST, and finally NIX_SYSTEM.
    • Added echo commands within the nix-switch target to output the name of the host being switched.
  • dotagents
    • Updated the dotagents submodule reference from commit 25b1492f463c3ea56609315e786f2530771a71ca to 565bbe58ded57d48484c1e81c9731085761e66b8.
Activity
  • The pull request was generated by Claude Code by glm-4.7.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mesa-dot-dev

mesa-dot-dev Bot commented Feb 3, 2026

Copy link
Copy Markdown

Mesa Description

TL;DR

Enhanced Nix build and switch commands to support named and auto-detected hosts.

What changed?

  • Enhanced nix-build and nix-switch Makefile targets to support named host configuration via HOST variable
  • Added auto-detection support using DETECTED_HOST variable
  • Falls back to NIX_SYSTEM when neither HOST nor DETECTED_HOST is set
  • Added informational echo statements to display which host is being built/switched
  • Updated dotagents submodule

Description generated by Mesa. Update settings

@shunkakinoki
shunkakinoki merged commit 86e9ac0 into main Feb 3, 2026
32 of 34 checks passed
@shunkakinoki
shunkakinoki deleted the makefile-detect-host branch February 3, 2026 12:21

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the nix-build and nix-switch Makefile targets to support named and auto-detected hosts, which is a great improvement for flexibility. The implementation, however, introduces significant code duplication in both targets. My review includes suggestions to refactor this logic by using a shell variable to store the target host, which simplifies the code and improves maintainability. The same refactoring pattern is applicable to both nix-build and nix-switch targets.

Comment thread Makefile
Comment on lines +297 to +305
if [ -n "$(HOST)" ]; then \
echo "Building named host: $(HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(DETECTED_HOST) --impure; \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(NIX_SYSTEM) --impure; \
fi; \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if/elif/else block contains duplicated code. The sudo nixos-rebuild command is repeated in each branch with only a different host. To improve maintainability and reduce redundancy, you can determine the host to use in a shell variable first, and then execute the command once with that variable.

_host_to_build="$(NIX_SYSTEM)"; \
if [ -n "$(HOST)" ]; then \
	echo "Building named host: $(HOST)"; \
	_host_to_build="$(HOST)"; \
elif [ -n "$(DETECTED_HOST)" ]; then \
	echo "Auto-detected host: $(DETECTED_HOST)"; \
	_host_to_build="$(DETECTED_HOST)"; \
fi; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$$_host_to_build --impure; \

Comment thread Makefile
Comment on lines +383 to +391
if [ -n "$(HOST)" ]; then \
echo "Switching named host: $(HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(HOST); \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(DETECTED_HOST); \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(NIX_SYSTEM); \
fi; \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the nix-build target, this block for nix-switch also has significant code duplication. The sudo nixos-rebuild command is repeated across branches. Refactoring this to use a shell variable for the host will make the code cleaner and easier to maintain.

_host_to_switch="$(NIX_SYSTEM)"; \
if [ -n "$(HOST)" ]; then \
	echo "Switching named host: $(HOST)"; \
	_host_to_switch="$(HOST)"; \
elif [ -n "$(DETECTED_HOST)" ]; then \
	echo "Auto-detected host: $(DETECTED_HOST)"; \
	_host_to_switch="$(DETECTED_HOST)"; \
fi; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$$_host_to_switch; \

@mesa-dot-dev mesa-dot-dev Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performed full review of 0c79f76...bee485f

Analysis

  1. Inconsistent implementation patterns between homeConfigurations and nixosConfigurations with different approaches for host selection could create maintenance confusion

  2. Lack of error handling and validation for host configurations - no checks if specified HOST exists or contains valid identifiers, leading to potential cryptic failures rather than clear error messages

  3. Informational echo statements may interfere with CI/CD pipelines, scripts, or automated tools that parse stdout without proper stderr redirection

  4. Missing documentation for the HOST variable - its purpose, expected values, relationship to other variables, and usage examples are not explained in the code

  5. Duplicated host resolution logic could be extracted into a dedicated variable to improve maintainability

Tip

Help

Slash Commands:

  • /review - Request a full code review
  • /review latest - Review only changes since the last review
  • /describe - Generate PR description. This will update the PR body or issue comment depending on your configuration
  • /help - Get help with Mesa commands and configuration options

2 files reviewed | 1 comments | Edit Agent SettingsRead Docs

Comment thread Makefile
elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(NIX_SYSTEM) --impure; \
if [ -n "$(HOST)" ]; then \
echo "Building named host: $(HOST)"; \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium

Consider adding validation to check if the specified HOST configuration actually exists in the flake. Currently, if a user sets HOST=nonexistent, they'll get a late-stage Nix error rather than a clear validation message. Example:

if ! nix flake show --json 2>/dev/null | grep -q "nixosConfigurations.$(HOST)"; then \
  echo "Error: Host configuration '$(HOST)' not found in flake"; \
  exit 1; \
fi; \

Fix in Cursor • Fix in Claude

Prompt for Agent
Task: Address review feedback left on GitHub.
Repository: shunkakinoki/dotfiles#715
File: Makefile#L298
Action: Open this file location in your editor, inspect the highlighted code, and resolve the issue described below.

Feedback:
Consider adding validation to check if the specified HOST configuration actually exists in the flake. Currently, if a user sets `HOST=nonexistent`, they'll get a late-stage Nix error rather than a clear validation message. Example:

```make
if ! nix flake show --json 2>/dev/null | grep -q "nixosConfigurations.$(HOST)"; then \
  echo "Error: Host configuration '$(HOST)' not found in flake"; \
  exit 1; \
fi; \

</details>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enhances the Makefile’s Nix build/switch workflows to support explicitly named hosts and auto-detected hosts, improving flexibility and transparency when working with flake-based NixOS configurations.

Changes:

  • Added host resolution priority for HOSTDETECTED_HOSTNIX_SYSTEM in nix-build and nix-switch (NixOS configs).
  • Added informational output indicating which host is being built/switched.
  • Updated the dotagents submodule pointer.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
Makefile Adds host selection logic and log output for nix-build/nix-switch NixOS paths.
dotagents Bumps submodule commit to a newer revision.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Makefile
Comment on lines +299 to +304
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(DETECTED_HOST) --impure; \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(NIX_SYSTEM) --impure; \

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(HOST) / $(DETECTED_HOST) are interpolated unquoted into the shell command line. If either contains whitespace or shell metacharacters, the command can break or be abused (e.g., argument splitting / shell injection). Wrap the --flake argument in shell quotes so it’s passed as a single argument (and consider similarly quoting any other interpolations that become standalone args).

Suggested change
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(DETECTED_HOST) --impure; \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(NIX_SYSTEM) --impure; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake '.#$(HOST)' --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake '.#$(DETECTED_HOST)' --impure; \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake '.#$(NIX_SYSTEM)' --impure; \

Copilot uses AI. Check for mistakes.
Comment thread Makefile
Comment on lines +385 to +390
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(HOST); \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(DETECTED_HOST); \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(NIX_SYSTEM); \

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nix-build passes --impure to nixos-rebuild (after --), but nix-switch currently passes --impure only to nix run (before --). If nixos-rebuild needs --impure for consistent flake evaluation/behavior, nix-switch may not behave the same as nix-build. Consider passing --impure to nixos-rebuild in the switch path as well (or consistently choose one approach in both targets).

Suggested change
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(HOST); \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(DETECTED_HOST); \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(NIX_SYSTEM); \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(DETECTED_HOST) --impure; \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(NIX_SYSTEM) --impure; \

Copilot uses AI. Check for mistakes.
Comment thread Makefile
Comment on lines +297 to +305
if [ -n "$(HOST)" ]; then \
echo "Building named host: $(HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(HOST) --impure; \
elif [ -n "$(DETECTED_HOST)" ]; then \
echo "Auto-detected host: $(DETECTED_HOST)"; \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(DETECTED_HOST) --impure; \
else \
sudo $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(NIX_SYSTEM) --impure; \
fi; \

Copilot AI Feb 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same host-resolution decision tree (HOST → DETECTED_HOST → NIX_SYSTEM, plus logging) now exists in multiple targets (nix-build and nix-switch). To reduce drift and simplify future updates, consider centralizing this into a single Make variable (e.g., a resolved host name) or a small shared Make macro used by both targets.

Copilot uses AI. Check for mistakes.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Indicates new feature requests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants