Nix Profile GC

nix-collect-garbage --delete-older-than is too aggressive.

Consider this scenario: A machine has been out of service for awhile -- a laptop on a shelf. Upon starting it up again, it does a software update, and then nix-collect-garbage --delete-older-than 90d deletes everything, leaving only what it has just updated to. All your rollback options are gone. If anything's wrong with that latest update, the machine will need tedious manual recovery.

Age isn't the only criterion for whether I'm done with a profile or not. I also want to keep the last few known-good profiles. As a zero-effort, automate-able approximation to 'known-good', I'll settle for keeping around the last few profiles that the machine ran on for awhile. Say if the machine typically has weekly updates, keep profiles that were active for 5 days. This would require a mechanism that keeps track of how much 'active' time each profile accumulates.

I made a thing that does this. It records the currently-active profiles periodically and then attaches an ExecStartPre to the normal nix-gc service where it goes through those logs and more carefully cleans up old profiles before the normal nix-collect-garbage runs.