Open jtojnar opened 6 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:
collectGarbage
take a dryRun
argument and respect it.dryRun
is true, the code for deleting generations (called higher up in nix-collect-garbage.cc) needs to record what generations would be deleted instead of just printing a message.dryRun
is true, in collectGarbage
, take into account generations that would be dry-run deleted as mentioned above, so that you can accurately report all the derivations in those generations that would be deleted.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.
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
I marked this as stale due to inactivity. → More info
I marked this as stale due to inactivity. → More info
Compare
with
I actually ran out of space in the middle of building something with
nox review
so I needed to clean something. Running thenix-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.