summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-09-06 14:23:04 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-09-06 14:23:04 +0000
commit2e210b2387904ada0417ad5a7502e4e40b852e02 (patch)
tree1deee458f12afebfcfaba70a89049966425e1853
parent89ac8db74f1241c56b05f579cc1e04056de1a6ef (diff)
downloadguix-2e210b2387904ada0417ad5a7502e4e40b852e02.tar.gz
* Convenience option `nix-collect-garbage -d' (--delete-old): removes
  old generations of *all* profiles in /nix/var/nix/profiles, then
  runs the garbage collector.  Quick way to get rid of all old stuff.
  Of course, one cannot roll back to earlier points in time after
  this.

-rw-r--r--scripts/nix-collect-garbage.in44
1 files changed, 42 insertions, 2 deletions
diff --git a/scripts/nix-collect-garbage.in b/scripts/nix-collect-garbage.in
index 7ec9f349b1..81975d2d3c 100644
--- a/scripts/nix-collect-garbage.in
+++ b/scripts/nix-collect-garbage.in
@@ -1,2 +1,42 @@
-#! @shell@ -e
-exec @bindir@/nix-store --gc "$@"
+#! @perl@ -w
+
+use strict;
+
+my $profilesDir = "@localstatedir@/nix/profiles";
+
+
+# Process the command line arguments.
+my @args = ();
+my $removeOld = 0;
+
+for my $arg (@ARGV) {
+    if ($arg eq "--delete-old" || $arg eq "-d") {
+        $removeOld = 1;
+    } else {
+        push @args, $arg;
+    }
+}
+
+
+# If `-d' was specified, remove all old generations of all profiles.
+# Of course, this makes rollbacks to before this point in time
+# impossible.
+if ($removeOld) {
+
+    opendir DIR, $profilesDir or die;
+
+    foreach my $name (sort (readdir DIR)) {
+        $name = $profilesDir . "/" . $name;
+        if (-l $name && (readlink($name) =~ /link/)) {
+            print STDERR "removing old generations of profile $name\n";
+            system "@bindir@/nix-env", "-p", $name, "--delete-generations", "old";
+        }
+    }
+    
+    closedir DIR or die;
+    
+}
+
+
+# Run the actual garbage collector.
+exec "@bindir@/nix-store", "--gc", @args;