Skip to content

Instantly share code, notes, and snippets.

@jakobrs
Last active April 11, 2020 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakobrs/f4c94b589ffcb9a0fe4a8ae3a4e0c1a4 to your computer and use it in GitHub Desktop.
Save jakobrs/f4c94b589ffcb9a0fe4a8ae3a4e0c1a4 to your computer and use it in GitHub Desktop.
The section for `test`, `build`, `dry-build`, and `dry-activate` has been
split into two separate cases, one for `build` and one for the rest. The
handling for `build` is identical to how it was before, but the others use
--no-out-link to not create a result symlink in the current directory.
diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh
index 354274478a3..e336d31a2fe 100644
--- a/nixos/modules/installer/tools/nixos-rebuild.sh
+++ b/nixos/modules/installer/tools/nixos-rebuild.sh
@@ -408,7 +408,7 @@ fi
# Either upgrade the configuration in the system profile (for "switch"
# or "boot"), or just build it and create a symlink "result" in the
-# current directory (for "build" and "test").
+# current directory (for "build").
if [ -z "$rollback" ]; then
echo "building the system configuration..." >&2
if [ "$action" = switch -o "$action" = boot ]; then
@@ -422,13 +422,22 @@ if [ -z "$rollback" ]; then
fi
copyToTarget "$pathToConfig"
targetHostCmd nix-env -p "$profile" --set "$pathToConfig"
- elif [ "$action" = test -o "$action" = build -o "$action" = dry-build -o "$action" = dry-activate ]; then
+ elif [ "$action" = build ]; then
if [[ -z $flake ]]; then
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A system -k "${extraBuildFlags[@]}")"
else
nix build "$flake#$flakeAttr.config.system.build.toplevel" "${extraBuildFlags[@]}" "${lockFlags[@]}"
pathToConfig="$(readlink -f ./result)"
fi
+ elif [ "$action" = test -o "$action" = dry-build -o "$action" = dry-activate ]; then
+ if [[ -z $flake ]]; then
+ pathToConfig="$(nixBuild '<nixpkgs/nixos>' --no-out-link -A system -k "${extraBuildFlags[@]}")"
+ else
+ outLink=$tmpDir/result
+ nix build "$flake#$flakeAttr.config.system.build.toplevel" \
+ "${extraBuildFlags[@]}" "${lockFlags[@]}" --out-link $outLink
+ pathToConfig="$(readlink -f $outLink)"
+ fi
elif [ "$action" = build-vm ]; then
if [[ -z $flake ]]; then
pathToConfig="$(nixBuild '<nixpkgs/nixos>' -A vm -k "${extraBuildFlags[@]}")"
@@ -460,7 +469,7 @@ else # [ -n "$rollback" ]
sed -n '/current/ {g; p;}; s/ *\([0-9]*\).*/\1/; h'
)
pathToConfig="$profile"-${systemNumber}-link
- if [ -z "$targetHost" ]; then
+ if [ -z "$targetHost" -a "$action" = build ]; then
ln -sT "$pathToConfig" ./result
fi
else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment