From 00372ca63890ed25543ffea2c4e625d365beff03 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 15 Apr 2014 12:03:30 +0200 Subject: [PATCH] nixos-rebuild: Fallback for upgrading Nix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../modules/installer/tools/nixos-rebuild.sh | 21 ++++++++++++++++--- 1 file 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 '' -A config.nix.package -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then if ! nix-build '' -A nixFallback -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then - nix-build '' -A nixUnstable -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null + if ! nix-build '' -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