about summary refs log tree commit diff
path: root/nixos/modules/installer/tools
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2019-02-20 20:02:20 -0500
committerMatthew Bauer <mjbauer95@gmail.com>2019-02-20 20:02:20 -0500
commit475c8aa018bbdd99e7e9d693c7207cdccdcde7b3 (patch)
tree4a2ed195e12c78ee1f6e9947eb990e1434051a00 /nixos/modules/installer/tools
parent266315c91d5e4a6d7b8465eb44d4f6af30d90b30 (diff)
downloadnixlib-475c8aa018bbdd99e7e9d693c7207cdccdcde7b3.tar
nixlib-475c8aa018bbdd99e7e9d693c7207cdccdcde7b3.tar.gz
nixlib-475c8aa018bbdd99e7e9d693c7207cdccdcde7b3.tar.bz2
nixlib-475c8aa018bbdd99e7e9d693c7207cdccdcde7b3.tar.lz
nixlib-475c8aa018bbdd99e7e9d693c7207cdccdcde7b3.tar.xz
nixlib-475c8aa018bbdd99e7e9d693c7207cdccdcde7b3.tar.zst
nixlib-475c8aa018bbdd99e7e9d693c7207cdccdcde7b3.zip
nixos-rebuild: get Nix from channel
If our old Nix can’t evaluate the Nixpkgs channel, try the fallback
from the new channel /first/. That way we can upgrade Nix to a newer
version and support breaking changes to Nix (like seen in the upgrade
o Nix 2.0).

This change should be backported to older NixOS versions!
Diffstat (limited to 'nixos/modules/installer/tools')
-rw-r--r--nixos/modules/installer/tools/nixos-rebuild.sh12
1 files changed, 11 insertions, 1 deletions
diff --git a/nixos/modules/installer/tools/nixos-rebuild.sh b/nixos/modules/installer/tools/nixos-rebuild.sh
index 361c2e49e05c..63559502bb0d 100644
--- a/nixos/modules/installer/tools/nixos-rebuild.sh
+++ b/nixos/modules/installer/tools/nixos-rebuild.sh
@@ -260,6 +260,14 @@ if [ -n "$rollback" -o "$action" = dry-build ]; then
     buildNix=
 fi
 
+nixSystem() {
+    machine="$(uname -m)"
+    if [[ "$machine" =~ i.86 ]]; then
+        machine=i686
+    fi
+    echo $machine-linux
+}
+
 prebuiltNix() {
     machine="$1"
     if [ "$machine" = x86_64 ]; then
@@ -279,7 +287,9 @@ if [ -n "$buildNix" ]; then
     nixDrv=
     if ! nixDrv="$(nix-instantiate '<nixpkgs/nixos>' --add-root $tmpDir/nix.drv --indirect -A config.nix.package.out "${extraBuildFlags[@]}")"; then
         if ! nixDrv="$(nix-instantiate '<nixpkgs>' --add-root $tmpDir/nix.drv --indirect -A nix "${extraBuildFlags[@]}")"; then
-            nixStorePath="$(prebuiltNix "$(uname -m)")"
+            if ! nixStorePath="$(nix-instantiate --eval '<nixpkgs/nixos/modules/installer/tools/nix-fallback-paths.nix>' -A $(nixSystem) | sed -e 's/^"//' -e 's/"$//')"; then
+                nixStorePath="$(prebuiltNix "$(uname -m)")"
+            fi
             if ! nix-store -r $nixStorePath --add-root $tmpDir/nix --indirect \
                 --option extra-binary-caches https://cache.nixos.org/; then
                 echo "warning: don't know how to get latest Nix" >&2