about summary refs log blame commit diff
path: root/scripts/nix-collect-garbage.in
blob: 8f54ba20f3e4a4ff1254bf93870b2e5f73f6516e (plain) (tree)
1
2
3
4
5
6
7
8






                                          
                                                                                   
















                                                              
#! /usr/bin/perl -w

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

my %alive;

open HASHES, "nix --query --refs \$(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";
    }
}