Skip to content

Commit 1800547

Browse files
committed
feat: Only build the nixosSystem for the install phase
Gate `nixosSystem` build behind the `installPhase` flag. This ensures that the `nixosSystem` is only built when really needed by `nixos-anywhere`. This is especially useful if `nixpkgs.hostPlatform` is not set yet and building the derivation would error out. The build can be split in to phases with `nixos-facter` being run in the kexec phase. Potential Drawbacks: Since the `nixosSystem` is not built early in the invocation we can't fail fast on errors anymore. But this is only the case if the phases are already controlled from the "outside" eg. if `nixos-anywhere` is called without the install phase active.
1 parent e8e5d63 commit 1800547

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/nixos-anywhere.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,9 @@ main() {
726726
if [[ ${phases[disko]} == 1 ]]; then
727727
diskoScript=$(nixBuild "${flake}#${flakeAttr}.system.build.${diskoMode}Script")
728728
fi
729-
nixosSystem=$(nixBuild "${flake}#${flakeAttr}.system.build.toplevel")
729+
if [[ ${phases[install]} == 1 ]]; then
730+
nixosSystem=$(nixBuild "${flake}#${flakeAttr}.system.build.toplevel")
731+
fi
730732
fi
731733
elif [[ -n ${diskoScript} ]] && [[ -n ${nixosSystem} ]]; then
732734
if [[ ! -e ${diskoScript} ]] || [[ ! -e ${nixosSystem} ]]; then
@@ -799,7 +801,9 @@ main() {
799801
if [[ ${phases[disko]} == 1 ]]; then
800802
diskoScript=$(nixBuild "${flake}#${flakeAttr}.system.build.${diskoMode}Script")
801803
fi
802-
nixosSystem=$(nixBuild "${flake}#${flakeAttr}.system.build.toplevel")
804+
if [[ ${phases[install]} == 1 ]]; then
805+
nixosSystem=$(nixBuild "${flake}#${flakeAttr}.system.build.toplevel")
806+
fi
803807
fi
804808
805809
# Installation will fail if non-root user is used for installer.

0 commit comments

Comments
 (0)