NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.65k stars 1.51k forks source link

nix-collect-garbage --dry-run does not list deleted garbage #1751

Open jtojnar opened 6 years ago

jtojnar commented 6 years ago

Compare

# nix-collect-garbage --delete-older-than 10d --dry-run
removing old generations of profile /nix/var/nix/profiles/system
removing old generations of profile /nix/var/nix/profiles/per-user/root/channels
removing old generations of profile /nix/var/nix/profiles/per-user/jtojnar/profile
would remove generation 425
removing old generations of profile /nix/var/nix/profiles/per-user/jtojnar/channels
removing old generations of profile /nix/var/nix/profiles/default

with

# nix-collect-garbage --delete-older-than 10d
removing old generations of profile /nix/var/nix/profiles/system
removing old generations of profile /nix/var/nix/profiles/per-user/root/channels
removing old generations of profile /nix/var/nix/profiles/per-user/jtojnar/profile
removing generation 425
removing old generations of profile /nix/var/nix/profiles/per-user/jtojnar/channels
removing old generations of profile /nix/var/nix/profiles/default
finding garbage collector roots...
removing stale link from ‘/nix/var/nix/gcroots/auto/60vijjwplhs2ryrc4dajd3rjkm53mzxf’ to ‘/run/user/1000/nix-build.SXkyLF/derivation-50’
removing stale link from ‘/nix/var/nix/gcroots/auto/659v5p9mli2yz9kwmnqn0frk59jczajm’ to ‘/run/user/1000/nix-build.SXkyLF/derivation-49’
[...]
deleting garbage...
deleting ‘/nix/store/ps6w4s329lyz093r90pszqbb9ybnvzs4-evolution-data-server-3.26.3-dev.lock’
deleting ‘/nix/store/4f3vd9c4r5x43iw4rrd8jdfxbyak3zzh-evolution-data-server-3.26.3.lock’
deleting ‘/nix/store/yss2s8zxxqkcdipfysn1g6p9ymblxm7j-gnome-desktop-3.26.2.lock’
deleting ‘/nix/store/m4vq8y0q1y34mpp6dvj5yhsjif5kr86g-anjuta-3.26.0.lock’
[...]
deleting ‘/nix/store/trash’
deleting unused links...
note: currently hard linking saves -0.00 MiB
992 store paths deleted, 2725.86 MiB freed

I actually ran out of space in the middle of building something with nox review so I needed to clean something. Running the nix-collect-garbage command with --dry-run did not show anything suspect so I ran it for real, only to find all the downloaded sources and my build progress had been obliterated.

I am using Nix 1.11.16.

DavidEGrayson commented 5 years ago

I started looking into fixing this today. It seems like the --dry-run feature only shows you what user profile generations will be deleted, it never shows you anything about derivations it will delete. And it's been like that for years at least. The main code of nix-collect-garbage.cc, which is responsible for for deleting derivations has no apparent support for a dry run:

        // Run the actual garbage collector.
        if (!dryRun) {
            auto store = openStore();
            options.action = GCOptions::gcDeleteDead;
            GCResults results;
            PrintFreed freed(true, results);
            store->collectGarbage(options, results);
        }

There are three things needed to fix this:

If someone can just accomplish the first task, it would be pretty useful. We would add a check to make sure the user doesn't try to delete any generations and do a dry run at the same time, since those two options would be incompatible. Once the other two tasks are accomplished, that check could be removed.

DavidEGrayson commented 5 years ago

By grepping for PrintFreed I discovered that there is actually a way to do a dry run of garbage collection with the current codebase:

nix-store --gc --print-dead
stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info