diff --git a/doc/manual/command-ref/nix-channel.xml b/doc/manual/command-ref/nix-channel.xml
index 63ecba8f3..c4cc04ce2 100644
--- a/doc/manual/command-ref/nix-channel.xml
+++ b/doc/manual/command-ref/nix-channel.xml
@@ -24,6 +24,7 @@
urlnames
+ generation
@@ -80,6 +81,14 @@ condition="manual">See also
+ [generation]
+
+ Reverts the previous call to nix-channel
+ --update. Optionally, you can specify a specific channel
+ generation number to restore.
+
+
+
@@ -104,10 +113,54 @@ respectively.
To subscribe to the Nixpkgs channel and install the GNU Hello package:
-$ nix-channel --add http://nixos.org/channels/nixpkgs-unstable
+$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable
$ nix-channel --update
$ nix-env -iA nixpkgs.hello
+You can revert channel updates using :
+
+
+$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.nixpkgsVersion'
+"14.04.527.0e935f1"
+
+$ nix-channel --rollback
+switching from generation 483 to 482
+
+$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.nixpkgsVersion'
+"14.04.526.dbadfad"
+
+
+
+
+Files
+
+
+
+ /nix/var/nix/profiles/username/channels
+
+ nix-channel uses a
+ nix-env profile to keep track of previous
+ versions of the subscribed channels. Every time you run
+ nix-channel --update, a new channel generation
+ (that is, a symlink to the channel Nix expressions in the Nix store)
+ is created. This enables nix-channel --rollback
+ to revert to previous versions.
+
+
+
+ ~/.nix-defexpr/channels
+
+ This is a symlink to
+ /nix/var/nix/profiles/username/channels. It
+ ensures that nix-env can find your channels. In
+ a multi-user installation, you may also have
+ ~/.nix-defexpr/channels_root, which links to
+ the channels of the root user.
+
+
+
+
+
diff --git a/scripts/nix-channel.in b/scripts/nix-channel.in
index 8e07821c4..b8c93df18 100755
--- a/scripts/nix-channel.in
+++ b/scripts/nix-channel.in
@@ -199,6 +199,20 @@ while (scalar @ARGV) {
last;
}
+ elsif ($arg eq "--rollback") {
+ die "$0: ‘--rollback’ has at most one argument\n" if scalar @ARGV > 1;
+ my $generation = shift @ARGV;
+ my @args = ("$Nix::Config::binDir/nix-env", "--profile", $profile);
+ if (defined $generation) {
+ die "invalid channel generation number ‘$generation’" unless $generation =~ /^[0-9]+$/;
+ push @args, "--switch-generation", $generation;
+ } else {
+ push @args, "--rollback";
+ }
+ system(@args) == 0 or exit 1;
+ last;
+ }
+
elsif ($arg eq "--help") {
exec "man nix-channel" or die;
}