mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 00:06:16 +02:00
47 lines
1 KiB
Perl
Executable file
47 lines
1 KiB
Perl
Executable file
#! /usr/bin/perl -w
|
|
|
|
use strict;
|
|
use IPC::Open2;
|
|
|
|
my $linkdir = "@localstatedir@/nix/links";
|
|
my $storedir = "@prefix@/store";
|
|
|
|
my %alive;
|
|
|
|
my $keepsuccessors = 1;
|
|
my $invert = 0;
|
|
|
|
foreach my $arg (@ARGV) {
|
|
if ($arg eq "--no-successors") { $keepsuccessors = 0; }
|
|
elsif ($arg eq "--invert") { $invert = 1; }
|
|
else { die "unknown argument `$arg'" };
|
|
}
|
|
|
|
my $extraarg = "";
|
|
if ($keepsuccessors) { $extraarg = "--include-successors"; };
|
|
my $pid = open2(\*READ, \*WRITE, "nix --query --requisites $extraarg \$(cat $linkdir/*.id)")
|
|
or die "determining live paths";
|
|
close WRITE;
|
|
while (<READ>) {
|
|
chomp;
|
|
$alive{$_} = 1;
|
|
if ($invert) { print "$_\n"; };
|
|
}
|
|
close READ;
|
|
|
|
waitpid $pid, 0;
|
|
$? == 0 or die "determining live paths";
|
|
|
|
exit 0 if ($invert);
|
|
|
|
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";
|
|
}
|
|
}
|