nixos-rebuild: Add a convenience option ‘--upgrade’

This is equivalent to running ‘nix-channel --update nixos’ before
running ‘nixos-rebuild’.
This commit is contained in:
Eelco Dolstra 2012-06-25 16:17:34 -04:00
parent a85555cd27
commit cc357c7e64
2 changed files with 32 additions and 12 deletions

View file

@ -28,6 +28,7 @@
<arg choice='plain'><option>pull</option></arg>
</group>
<sbr />
<arg><option>--upgrade</option></arg>
<arg><option>--install-grub</option></arg>
<arg><option>--no-pull</option></arg>
<arg><option>--no-build-nix</option></arg>
@ -195,6 +196,14 @@ $ ./result/bin/run-*-vm
<variablelist>
<varlistentry>
<term><option>--upgrade</option></term>
<listitem>
<para>Fetch the latest version of NixOS from the NixOS
channel.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--install-grub</option></term>
<listitem>

View file

@ -22,6 +22,7 @@ The operation is one of the following:
Options:
--upgrade fetch the latest version of NixOS before rebuilding
--install-grub (re-)install the Grub bootloader
--pull do a nix-pull to get the latest NixOS channel
manifest
@ -51,6 +52,7 @@ action=
pullManifest=
buildNix=1
rollback=
upgrade=
while test "$#" -gt 0; do
i="$1"; shift 1
@ -73,6 +75,9 @@ while test "$#" -gt 0; do
--rollback)
rollback=1
;;
--upgrade)
upgrade=1
;;
--show-trace|--no-build-hook|--keep-failed|-K|--keep-going|-k|--verbose|-v|--fallback)
extraBuildFlags="$extraBuildFlags $i"
;;
@ -132,10 +137,16 @@ fi
if [ "$action" = pull ]; then exit 0; fi
# If --upgrade is given, run nix-channel --update nixos.
if [ -n "$upgrade" ]; then
nix-channel --update nixos
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.
if test -n "$buildNix"; then
if [ -n "$buildNix" ]; then
echo "building Nix..." >&2
if ! nix-build '<nixos>' -A config.environment.nix -o $tmpDir/nix $extraBuildFlags > /dev/null; then
if ! nix-build '<nixos>' -A nixFallback -o $tmpDir/nix $extraBuildFlags > /dev/null; then