about summary refs log tree commit diff
path: root/scripts/nix-collect-garbage
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-04-09T13·03+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-04-09T13·03+0000
commitf7526febe4e60e3da61664a5fb58ff19a5882ded (patch)
treef96acde8e85954fde8c8cfb25fd5c9aaee2d55b0 /scripts/nix-collect-garbage
parent30a6122f8061e8c3ac2d96078b75aafa63101f02 (diff)
* A garbage collector for installed packages. nix-collect-garbage
  doesn't actually delete any packages, it just prints their
  descriptor hashes.  So we can do

    nix info $(nix-collect-garbage)

  to print out the ids of the packages that would be deleted, and

    nix delpkg $(nix-collect-garbage)

  to actually delete them.

Diffstat (limited to 'scripts/nix-collect-garbage')
-rwxr-xr-xscripts/nix-collect-garbage22
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/nix-collect-garbage b/scripts/nix-collect-garbage
new file mode 100755
index 000000000000..adaba5b7c65b
--- /dev/null
+++ b/scripts/nix-collect-garbage
@@ -0,0 +1,22 @@
+#! /usr/bin/perl -w
+
+my $prefix = $ENV{"NIX"} || "/nix"; # !!! use prefix
+my $linkdir = "$prefix/var/nix/links";
+
+my %alive;
+
+open HASHES, "nix closure \$(cat $linkdir/*.hash) |";
+while (<HASHES>) {
+	chomp;
+	$alive{$_} = 1;
+}
+close HASHES;
+
+open HASHES, "nix listinst |";
+while (<HASHES>) {
+	chomp;
+	if (!$alive{$_}) {
+	    print "$_\n";
+	}
+}
+close HASHES;