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

View file

@ -22,6 +22,7 @@ The operation is one of the following:
Options: Options:
--upgrade fetch the latest version of NixOS before rebuilding
--install-grub (re-)install the Grub bootloader --install-grub (re-)install the Grub bootloader
--pull do a nix-pull to get the latest NixOS channel --pull do a nix-pull to get the latest NixOS channel
manifest manifest
@ -51,43 +52,47 @@ action=
pullManifest= pullManifest=
buildNix=1 buildNix=1
rollback= rollback=
upgrade=
while test "$#" -gt 0; do while test "$#" -gt 0; do
i="$1"; shift 1 i="$1"; shift 1
case "$i" in case "$i" in
--help) --help)
showSyntax showSyntax
;; ;;
switch|boot|test|build|dry-run|build-vm|build-vm-with-bootloader|pull) switch|boot|test|build|dry-run|build-vm|build-vm-with-bootloader|pull)
action="$i" action="$i"
;; ;;
--install-grub) --install-grub)
export NIXOS_INSTALL_GRUB=1 export NIXOS_INSTALL_GRUB=1
;; ;;
--pull) --pull)
pullManifest=1 pullManifest=1
;; ;;
--no-build-nix) --no-build-nix)
buildNix= buildNix=
;; ;;
--rollback) --rollback)
rollback=1 rollback=1
;; ;;
--upgrade)
upgrade=1
;;
--show-trace|--no-build-hook|--keep-failed|-K|--keep-going|-k|--verbose|-v|--fallback) --show-trace|--no-build-hook|--keep-failed|-K|--keep-going|-k|--verbose|-v|--fallback)
extraBuildFlags="$extraBuildFlags $i" extraBuildFlags="$extraBuildFlags $i"
;; ;;
--max-jobs|-j|--cores|-I) --max-jobs|-j|--cores|-I)
j="$1"; shift 1 j="$1"; shift 1
extraBuildFlags="$extraBuildFlags $i $j" extraBuildFlags="$extraBuildFlags $i $j"
;; ;;
--fast) --fast)
buildNix= buildNix=
extraBuildFlags="$extraBuildFlags --show-trace" extraBuildFlags="$extraBuildFlags --show-trace"
;; ;;
*) *)
echo "$0: unknown option \`$i'" echo "$0: unknown option \`$i'"
exit 1 exit 1
;; ;;
esac esac
done done
@ -129,13 +134,19 @@ if [ -n "$pullManifest" -o "$action" = pull ]; then
done done
fi fi
if [ "$action" = pull ]; then exit 0; 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 # 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. Of course, the same goes for Nixpkgs, but Nixpkgs is
# more conservative. # more conservative.
if test -n "$buildNix"; then if [ -n "$buildNix" ]; then
echo "building Nix..." >&2 echo "building Nix..." >&2
if ! nix-build '<nixos>' -A config.environment.nix -o $tmpDir/nix $extraBuildFlags > /dev/null; then 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 if ! nix-build '<nixos>' -A nixFallback -o $tmpDir/nix $extraBuildFlags > /dev/null; then