I prefer to keep all the build inputs in the store through GCs. Nix nominally supports that:
gc-keep-outputs = true
gc-keep-derivations = true
However, there is a catch. For fixed-output derivations there are multiple derivations for the same output path, depending on different stdenv
versions. They are all kept, so I keep accumulating glibc/fetchers/etc across mass-rebuilds.
Does anyone has a script or something to collect the old fetcher but keep the freshest ones?
Recording a command of possible use to measure the scale of the problem…
sqlite3 /nix/var/nix/db/db.sqlite “select x.path from ValidPaths as x inner join DerivationOutputs as xo on xo.drv = x.id, ValidPaths as y inner join DerivationOutputs as yo on yo.drv = y.id where xo.id = ‘out’ and yo.id = ‘out’ and xo.path = yo.path and x.registrationTime < y.registrationTime;”
Interesting problem. Rather than having keep-outputs = true
(btw keep-derivations = true
is default), you could leave it false and make a script that does a GC dry run. Then you query the closures of the latest generation’s derivation, query their outputs, and remove all those from the set returned by the dry run. The delete the paths that remain from the dry run. Very manual process, but I think it accomplishes what you want.
Interesting problem. Rather than having keep-outputs = true
(btw keep-derivations = true
is default), you could leave it false and make a script that does a GC dry run. Then you query the closures of the latest generation’s derivation, query their outputs, and remove all those from the set returned by the dry run. The delete the paths that remain from the dry run. Very manual process, but I think it accomplishes what you want.
In the meantime, I managed to get a situation where «nix-store --delete» says a path is live but «nix-store -q --roots» with the same settings says it is nto reachable from any roots…
I think I could set keep-outputs without keep-derivations and just manage a set of derivations as roots in addition to their outputs, with less effort (at least in my situation) and less fragility. But I have not yet got around to it, and I hoped there is an actually reasonable solution. Of course after getting a presumably impossible result from Nix I am less sure (I have not yet got around to reproducing such things from scratch, so I guess it’s too early to report as a bug…)
That’s an interesting solution. I have no idea what Nix does if you have a gc root pointing to a derivation. But if it does what I hope (treats the drv as live so that with keep-outputs
all the needed build inputs are live), then keeping just a root to the current generation’s drv and setting keep-derivations = false
would do the trick.
This part’s very very weird though and I can’t say I’ve ever seen that 
This part’s very very weird though and I can’t say I’ve ever seen that 
I might have seen more so it doesn’t surprise me as very weird, but indeed I have not seen exactly this issue before.