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.
This commit is contained in:
parent
f9e6181478
commit
00372ca638
|
@ -124,8 +124,7 @@ fi
|
||||||
|
|
||||||
|
|
||||||
# First build Nix, since NixOS may require a newer version than the
|
# First build Nix, since NixOS may require a newer version than the
|
||||||
# current one. Of course, the same goes for Nixpkgs, but Nixpkgs is
|
# current one.
|
||||||
# more conservative.
|
|
||||||
if [ -n "$rollback" -o "$action" = dry-run ]; then
|
if [ -n "$rollback" -o "$action" = dry-run ]; then
|
||||||
buildNix=
|
buildNix=
|
||||||
fi
|
fi
|
||||||
|
@ -134,7 +133,23 @@ if [ -n "$buildNix" ]; then
|
||||||
echo "building Nix..." >&2
|
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 config.nix.package -o $tmpDir/nix "${extraBuildFlags[@]}" > /dev/null; then
|
||||||
if ! nix-build '<nixpkgs/nixos>' -A nixFallback -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
|
||||||
fi
|
fi
|
||||||
PATH=$tmpDir/nix/bin:$PATH
|
PATH=$tmpDir/nix/bin:$PATH
|
||||||
|
|
Loading…
Reference in New Issue