diff --git a/doc/manual/nix-collect-garbage.xml b/doc/manual/nix-collect-garbage.xml
index a13e365a4..a97e3b7c6 100644
--- a/doc/manual/nix-collect-garbage.xml
+++ b/doc/manual/nix-collect-garbage.xml
@@ -20,6 +20,7 @@
nix-collect-garbage
+ period
@@ -35,13 +36,18 @@
The command nix-collect-garbage is mostly an
alias of nix-store
--gc, that is, it deletes all unreachable paths in
-the Nix store to clean up your system. However, it provides an
-additional option ()
-that deletes all old generations of all profiles in
+the Nix store to clean up your system. However, it provides two
+additional options: (),
+which deletes all old generations of all profiles in
/nix/var/nix/profiles by invoking
-nix-env --delete-generations old on all profiles.
-Of course, this makes rollbacks to previous configurations
-impossible.
+nix-env --delete-generations old on all profiles
+(of course, this makes rollbacks to previous configurations
+impossible); and
+ period,
+where period is a value such as 30d, which deletes
+all non-current generations that are older than the specified number of
+days in all profiles in /nix/var/nix/profiles.
+
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in
index 28b0c749f..55e0ba7a6 100755
--- a/scripts/nix-collect-garbage.in
+++ b/scripts/nix-collect-garbage.in
@@ -8,12 +8,19 @@ my $profilesDir = "@localstatedir@/nix/profiles";
# Process the command line arguments.
my @args = ();
+my $arg;
+
my $removeOld = 0;
+my $gen;
my $dryRun = 0;
-for my $arg (@ARGV) {
+while ($arg = shift) {
if ($arg eq "--delete-old" || $arg eq "-d") {
$removeOld = 1;
+ $gen = "old";
+ } elsif ($arg eq "--delete-older-than") {
+ $removeOld = 1;
+ $gen = shift;
} elsif ($arg eq "--dry-run") {
$dryRun = 1;
} elsif ($arg eq "--help") {
@@ -40,7 +47,8 @@ sub removeOldGenerations {
$name = $dir . "/" . $name;
if (-l $name && (readlink($name) =~ /link/)) {
print STDERR "removing old generations of profile $name\n";
- system("$Nix::Config::binDir/nix-env", "-p", $name, "--delete-generations", "old", $dryRun ? "--dry-run" : ());
+
+ system("$Nix::Config::binDir/nix-env", "-p", $name, "--delete-generations", $gen, $dryRun ? "--dry-run" : ());
}
elsif (! -l $name && -d $name) {
removeOldGenerations $name;