aboutsummaryrefslogtreecommitdiff
path: root/scripts/nix-collect-garbage.in
blob: f1ea09b8ee93fab6a6e3f99e6c24c1bc081ee17d (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! @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.
if ($removeOld) {

    opendir DIR, $profilesDir or die;

    foreach my $name (sort (readdir DIR)) {
        $name = $profilesDir . "/" . $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");
        }
    }
    
    closedir DIR or die;
    
}


# Run the actual garbage collector.
exec "@bindir@/nix-store", "--gc", @args;