diff options
-rw-r--r-- | scripts/Makefile.am | 2 | ||||
-rwxr-xr-x | scripts/nix-collect-garbage | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 4e2eada86b9d..4140cdf5b311 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -1,4 +1,4 @@ -bin_SCRIPTS = nix-generate-regscript nix-switch +bin_SCRIPTS = nix-generate-regscript nix-switch nix-collect-garbage install-exec-local: $(INSTALL) -d $(sysconfdir)/profile.d 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; |