-
Notifications
You must be signed in to change notification settings - Fork 0
fix(makefile): honor detected NixOS host in CI builds #2105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -544,7 +544,15 @@ nix-build: nix-connect nix-trust ## Build Nix configuration. | |
| HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#$(NIX_CONFIG_TYPE).runner.system $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \ | ||
| fi; \ | ||
| elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \ | ||
| HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.runner.config.system.build.toplevel $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \ | ||
| if [ -n "$(HOST)" ]; then \ | ||
| echo "Building named NixOS host: $(HOST)"; \ | ||
| $(SUDO) env HOST=$(HOST) HOSTNAME=$(HOST) $(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) env HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) nixpkgs#nixos-rebuild -- build --flake .#$(DETECTED_HOST) --impure; \ | ||
| else \ | ||
| HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) build .#nixosConfigurations.runner.config.system.build.toplevel $(NIX_FLAGS) --impure --no-update-lock-file --show-trace; \ | ||
| fi; \ | ||
| elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \ | ||
| if [ -n "$(HOST)" ]; then \ | ||
| echo "Building named home config: $(HOST)"; \ | ||
|
|
@@ -689,8 +697,16 @@ nix-switch: ## Activate Nix configuration. | |
| if [ "$(OS)" = "Darwin" ]; then \ | ||
| $(SUDO) env CI="$$CI" IN_DOCKER="$$IN_DOCKER" HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(DARWIN_REBUILD) switch --flake .#runner --impure --no-update-lock-file; \ | ||
| elif [ "$(NIX_CONFIG_TYPE)" = "nixosConfigurations" ]; then \ | ||
| echo "⏭️ NixOS switch skipped in CI as the runner is not a NixOS system"; \ | ||
| $(SUDO) env HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#runner --no-update-lock-file || exit 0; \ | ||
| if [ -n "$(HOST)" ]; then \ | ||
| echo "Switching named host: $(HOST)"; \ | ||
| $(SUDO) env HOST=$(HOST) HOSTNAME=$(HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(HOST) --no-update-lock-file || exit 0; \ | ||
| elif [ -n "$(DETECTED_HOST)" ]; then \ | ||
| echo "Auto-detected host: $(DETECTED_HOST)"; \ | ||
| $(SUDO) env HOST=$(DETECTED_HOST) HOSTNAME=$(DETECTED_HOST) $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#$(DETECTED_HOST) --no-update-lock-file || exit 0; \ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Silent failure masking on real hosts in CI switch: The |
||
| else \ | ||
| echo "⏭️ NixOS switch skipped in CI as the runner is not a NixOS system"; \ | ||
| $(SUDO) env HOST=runner HOSTNAME=runner $(NIX_ALLOW_UNFREE) $(NIX_EXEC) run $(NIX_FLAGS) --impure nixpkgs#nixos-rebuild -- switch --flake .#runner --no-update-lock-file || exit 0; \ | ||
| fi; \ | ||
| elif [ "$(NIX_CONFIG_TYPE)" = "homeConfigurations" ]; then \ | ||
| if [ "$$SKIP_HOME_MANAGER_SWITCH" = "true" ]; then \ | ||
| echo "⏭️ Home-manager switch skipped (SKIP_HOME_MANAGER_SWITCH=true)"; \ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistency in CI NixOS Build Commands
There is a significant inconsistency in how NixOS configurations are built in CI:
nix build .#nixosConfigurations.<host>.config.system.build.topleveldirectly withoutsudoornixos-rebuild.$(SUDO) ... nixos-rebuild -- buildvianix run nixpkgs#nixos-rebuild.Using
sudoandnixos-rebuildin CI for building (not switching) is problematic because:sudocan cause permission issues in the workspace or build cache (e.g., root-owned files).nix run nixpkgs#nixos-rebuilddownloads and evaluatesnixos-rebuildfromnixpkgs, adding unnecessary network dependency and overhead in CI.Recommendation
Use
nix builddirectly, matching the fallback and Darwin branches.Note: Since the spec test
spec/make_build_host_resolution_spec.sh(not in this diff) asserts on--flake .#matic, you will need to update it to expect.#nixosConfigurations.matic.config.system.build.toplevelinstead.