about summary refs log tree commit diff
path: root/scripts/nix-collect-garbage
blob: adaba5b7c65b6445475c6104de6eaff465713818 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;