Add --rollback option to nixos-rebuild.
svn path=/nixos/trunk/; revision=16771
This commit is contained in:
parent
ce030d6c35
commit
923f58794a
@ -31,6 +31,8 @@ Options:
|
|||||||
channel manifest
|
channel manifest
|
||||||
--no-build-nix don't build the latest Nix from Nixpkgs before
|
--no-build-nix don't build the latest Nix from Nixpkgs before
|
||||||
building NixOS
|
building NixOS
|
||||||
|
--rollback restore the previous NixOS configuration (only
|
||||||
|
with switch, boot, test, build)
|
||||||
|
|
||||||
Various nix-build options are also accepted, in particular:
|
Various nix-build options are also accepted, in particular:
|
||||||
|
|
||||||
@ -51,6 +53,7 @@ extraBuildFlags=
|
|||||||
action=
|
action=
|
||||||
pullManifest=1
|
pullManifest=1
|
||||||
buildNix=1
|
buildNix=1
|
||||||
|
rollback=
|
||||||
|
|
||||||
while test "$#" -gt 0; do
|
while test "$#" -gt 0; do
|
||||||
i="$1"; shift 1
|
i="$1"; shift 1
|
||||||
@ -65,6 +68,8 @@ while test "$#" -gt 0; do
|
|||||||
pullManifest=
|
pullManifest=
|
||||||
elif test "$i" = --no-build-nix; then
|
elif test "$i" = --no-build-nix; then
|
||||||
buildNix=
|
buildNix=
|
||||||
|
elif test "$i" = --rollback; then
|
||||||
|
rollback=1
|
||||||
elif test "$i" = --show-trace -o "$i" = --no-build-hook -o "$i" = --keep-failed -o "$i" = -K \
|
elif test "$i" = --show-trace -o "$i" = --no-build-hook -o "$i" = --keep-failed -o "$i" = -K \
|
||||||
-o "$i" = --keep-going -o "$i" = -k -o "$i" = --verbose -o "$i" = -v; then
|
-o "$i" = --keep-going -o "$i" = -k -o "$i" = --verbose -o "$i" = -v; then
|
||||||
extraBuildFlags="$extraBuildFlags $i"
|
extraBuildFlags="$extraBuildFlags $i"
|
||||||
@ -83,6 +88,11 @@ if test "$action" = dry-run; then
|
|||||||
extraBuildFlags="$extraBuildFlags --dry-run"
|
extraBuildFlags="$extraBuildFlags --dry-run"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test -n "$rollback"; then
|
||||||
|
pullManifest=
|
||||||
|
buildNix=
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
tmpDir=$(mktemp -t -d nixos-rebuild.XXXXXX)
|
tmpDir=$(mktemp -t -d nixos-rebuild.XXXXXX)
|
||||||
trap 'rm -rf "$tmpDir"' EXIT
|
trap 'rm -rf "$tmpDir"' EXIT
|
||||||
@ -126,17 +136,33 @@ fi
|
|||||||
# Either upgrade the configuration in the system profile (for "switch"
|
# Either upgrade the configuration in the system profile (for "switch"
|
||||||
# or "boot"), or just build it and create a symlink "result" in the
|
# or "boot"), or just build it and create a symlink "result" in the
|
||||||
# current directory (for "build" and "test").
|
# current directory (for "build" and "test").
|
||||||
if test "$action" = switch -o "$action" = boot; then
|
if test -z "$rollback"; then
|
||||||
nix-env -p /nix/var/nix/profiles/system -f $NIXOS --set -A system $extraBuildFlags
|
if test "$action" = switch -o "$action" = boot; then
|
||||||
pathToConfig=/nix/var/nix/profiles/system
|
nix-env -p /nix/var/nix/profiles/system -f $NIXOS --set -A system $extraBuildFlags
|
||||||
elif test "$action" = test -o "$action" = build -o "$action" = dry-run; then
|
pathToConfig=/nix/var/nix/profiles/system
|
||||||
nix-build $NIXOS -A system -K -k $extraBuildFlags
|
elif test "$action" = test -o "$action" = build -o "$action" = dry-run; then
|
||||||
pathToConfig=./result
|
nix-build $NIXOS -A system -K -k $extraBuildFlags
|
||||||
elif test "$action" = build-vm; then
|
pathToConfig=./result
|
||||||
nix-build $NIXOS -A vm -K -k $extraBuildFlags
|
elif test "$action" = build-vm; then
|
||||||
pathToConfig=./result
|
nix-build $NIXOS -A vm -K -k $extraBuildFlags
|
||||||
else
|
pathToConfig=./result
|
||||||
showSyntax
|
else
|
||||||
|
showSyntax
|
||||||
|
fi
|
||||||
|
else # test -n "$rollback"
|
||||||
|
if test "$action" = switch -o "$action" = boot; then
|
||||||
|
nix-env --rollback -p /nix/var/nix/profiles/system
|
||||||
|
pathToConfig=/nix/var/nix/profiles/system
|
||||||
|
elif test "$action" = test -o "$action" = build; then
|
||||||
|
systemNumber=$(
|
||||||
|
nix-env -p /nix/var/nix/profiles/system --list-generations |
|
||||||
|
sed -n '/current/ {g; p;}; s/ *\([0-9]*\).*/\1/; h'
|
||||||
|
)
|
||||||
|
ln -sT /nix/var/nix/profiles/system-${systemNumber}-link ./result
|
||||||
|
pathToConfig=./result
|
||||||
|
else
|
||||||
|
showSyntax
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user