summary refs log tree commit diff
path: root/nixos/modules/installer
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-15 12:03:30 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-04-15 12:07:34 +0200
commit00372ca63890ed25543ffea2c4e625d365beff03 (patch)
treeced42aeb0e9acba8555a4641988359f3010f77f3 /nixos/modules/installer
parentf9e6181478ed851e1915ac478d8ed598397345a1 (diff)
downloadnixlib-00372ca63890ed25543ffea2c4e625d365beff03.tar
nixlib-00372ca63890ed25543ffea2c4e625d365beff03.tar.gz
nixlib-00372ca63890ed25543ffea2c4e625d365beff03.tar.bz2
nixlib-00372ca63890ed25543ffea2c4e625d365beff03.tar.lz
nixlib-00372ca63890ed25543ffea2c4e625d365beff03.tar.xz
nixlib-00372ca63890ed25543ffea2c4e625d365beff03.tar.zst
nixlib-00372ca63890ed25543ffea2c4e625d365beff03.zip
nixos-rebuild: Fallback for upgrading Nix
Previously, if the currently installed Nix is too old to evaluate
Nixpkgs, then nixos-rebuild would fail and the user had to upgrade Nix
manually. Now, as a fallback, we run ‘nix-store -r’ to obtain a binary
Nix directly from the binary cache.
Diffstat (limited to 'nixos/modules/installer')
-rw-r--r--nixos/modules/installer/tools/nixos-rebuild.sh21
1 files changed, 18 insertions, 3 deletions
diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh
index 4582028eb9b8..2d137dd52add 100644
--- a/nixos/modules/installer/tools/nixos-rebuild.sh
+++ b/nixos/modules/installer/tools/nixos-rebuild.sh
@@ -124,8 +124,7 @@ fi
 
 
 # First build Nix, since NixOS may require a newer version than the
-# current one.  Of course, the same goes for Nixpkgs, but Nixpkgs is
-# more conservative.
+# current one.
 if [ -n "$rollback" -o "$action" = dry-run ]; then
     buildNix=
 fi
@@ -134,7 +133,23 @@ if [ -n "$buildNix" ]; then
     echo "building Nix..." >&2
     if ! nix-build '<nixpkgs/nixos>' -A config.nix.package -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then
         if ! nix-build '<nixpkgs/nixos>' -A nixFallback -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then
-            nix-build '<nixpkgs>' -A nixUnstable -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null
+            if ! nix-build '<nixpkgs>' -A nix -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then
+                machine="$(uname -m)"
+                if [ "$machine" = x86_64 ]; then
+                    nixStorePath=/nix/store/d34q3q2zj9nriq4ifhn3dnnngqvinjb3-nix-1.7
+                elif [[ "$machine" =~ i.86 ]]; then
+                    nixStorePath=/nix/store/qlah0darpcn6sf3lr2226rl04l1gn4xz-nix-1.7
+                else
+                    echo "$0: unsupported platform"
+                    exit 1
+                fi
+                if ! nix-store -r $nixStorePath --add-root $tmpDir/nix --indirect \
+                    --option extra-binary-caches http://cache.nixos.org/; then
+                    echo "warning: don't know how to get latest Nix" >&2
+                fi
+                # Older version of nix-store -r don't support --add-root.
+                [ -e $tmpDir/nix ] || ln -sf $nixStorePath $tmpDir/nix
+            fi
         fi
     fi
     PATH=$tmpDir/nix/bin:$PATH