More fine grained control about garbage collection

I currently use nix-collect-garbage --delete-older-than 14d to delete old generations. For my user this works quite well, though for the system I do an update only one or two times a month, leading to the fact, that I often don’t have a previous generation to boot into.

This leads to the situation, that I could either use sudo with a larger timespan to keep, and then run a GC for each user individually with a short time span which would be tedious to do (even when scripted and/or croned).

Alternatively I could just use a longer timespan for all users, which would roughly double the required diskspace for the store (tried it for 2 months).

Then I could use the short timespan even for the system, but, yes, no previous generation then to boot into…

Therefore, I’d like to ask, if there is any option to say “keep at least 5 generations of each profile”. Plus points if I could combine it with --delete-older-than in a way, that I always have at least 5 generations, but a generation from the last 14 days get never deleted?

2 Likes

Personally I like the nix.extraOptions => min-free approach to garbage collection, garbage is only collected when I’m running out of space. Perhaps you could combine this with max-free and realize indirectly what you want to achieve?

1 Like

I do not like giving this in the hands of some automatism.

I prefer regular manual GC over waiting for it to happen, especially as GC in your scenario is only applied when space would be low because of some operations on the store, not because the PostgreSQL Data files grew massively.