about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorRicardo M. Correia <rcorreia@wizy.org>2014-03-11T21·16+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-03-29T23·54+0100
commit034b6f60626be014d00f68e02d8614ddf7ba44a0 (patch)
tree19714e8562b651076a41673e292a52b0e000ff9d /scripts
parent7ef7597f71b282265a9f79afe4608cd3b1bc4127 (diff)
nix-collect-garbage: Add --delete-older-than option
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/nix-collect-garbage.in12
1 files changed, 10 insertions, 2 deletions
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in
index 28b0c749f125..55e0ba7a6fab 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;