aboutsummaryrefslogtreecommitdiff
path: root/scripts/nix-collect-garbage.in
blob: 1506416b23a5e219c6bea92c4e0f818f05accb81 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/perl -w

my $linkdir = "@localstatedir@/nix/links";
my $storedir = "@prefix@/store";

my %alive;

open HASHES, "nix -qrh \$(cat $linkdir/*.hash) |" or die "in `nix -qrh'";
while (<HASHES>) {
	chomp;
	$alive{$_} = 1;
}
close HASHES;

opendir(DIR, $storedir) or die "cannot opendir $storedir: $!";
my @names = readdir(DIR);
closedir DIR;

foreach my $name (@names) {
    next if ($name eq "." || $name eq "..");
    $name = "$storedir/$name";
    if (!$alive{$name}) {
        print "$name\n";
    }
}