mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 08:16:14 +02:00
eb2dd4815c
/nix/var/nix/profiles, not just in that directory itself. (NixOS puts profiles in /nix/var/nix/profiles/per-user.)
51 lines
1.1 KiB
Text
51 lines
1.1 KiB
Text
#! @perl@ -w
|
|
|
|
use strict;
|
|
|
|
my $profilesDir = "@localstatedir@/nix/profiles";
|
|
|
|
|
|
# Process the command line arguments.
|
|
my @args = ();
|
|
my $removeOld = 0;
|
|
|
|
for my $arg (@ARGV) {
|
|
if ($arg eq "--delete-old" || $arg eq "-d") {
|
|
$removeOld = 1;
|
|
} else {
|
|
push @args, $arg;
|
|
}
|
|
}
|
|
|
|
|
|
# If `-d' was specified, remove all old generations of all profiles.
|
|
# Of course, this makes rollbacks to before this point in time
|
|
# impossible.
|
|
|
|
sub removeOldGenerations;
|
|
sub removeOldGenerations {
|
|
my $dir = shift;
|
|
|
|
my $dh;
|
|
opendir $dh, $dir or die;
|
|
|
|
foreach my $name (sort (readdir $dh)) {
|
|
next if $name eq "." || $name eq "..";
|
|
$name = $dir . "/" . $name;
|
|
if (-l $name && (readlink($name) =~ /link/)) {
|
|
print STDERR "removing old generations of profile $name\n";
|
|
system("@bindir@/nix-env", "-p", $name, "--delete-generations", "old");
|
|
}
|
|
elsif (! -l $name && -d $name) {
|
|
removeOldGenerations $name;
|
|
}
|
|
}
|
|
|
|
closedir $dh or die;
|
|
}
|
|
|
|
removeOldGenerations $profilesDir if $removeOld;
|
|
|
|
|
|
# Run the actual garbage collector.
|
|
exec "@bindir@/nix-store", "--gc", @args;
|