On my NixOS desktop I use a combination of sudo nixos-rebuild switch --upgrade and sudo nix-collect-garbage --delete-older-than 30d to update the system, garbage collect, and update the boot menu to both add and remove generations.
I had assumed that the declarative “configuration.nix” equivalent would be:
Based on the output of journalctl -u nix-gc.service the garbage collect is running, and I can see that the boot menu is getting updated with new generations, however the old ones aren’t getting removed based on my experiments so far.
I have tried searching for an answer and browsed the systemd-boot NixOS options, but I haven’t found a solution yet.
I was hoping to find out if I’m doing something wrong, or if there’s some incantation I can add to my “configuration.nix” file that would remove the old garbage collected boot entries automatically.
Do you turn off the machine? As the GC timer is not persistent (according the snippet you have posted) that could be then a reason for what you observe . Non persistnt timers are not done if the timeslot was missed, if the machine was turned off
No, the machine is a VM that has been up for 21 days (not including reboots) mostly to confirm my expectations regarding auto update and garbage collect.
Thank you for the suggestion, however I really prefer the consistency of knowing how many generations I have vs managing by available storage.
I’ll leave my configuration the way it is and will continue monitoring it for now. Maybe I’ll eventually see what’s causing the delay in removing boot entries, however I’m content as long as it does removed them and the list doesn’t get too long.
there is a wrinkle in the definition of the “older than” parameter. It works based on when the generation was active, not when it was created, so that you can go back to what you were running at that time. So, if you delete older than 10 days, but go 11 days between updates, that generation will be ~21 days old before getting deleted.
Not sure if this is a factor in your case, but it may be
That wouldn’t automatically remove previous generations as they are linked somewhere in /nix/var/nix/profiles IIRC but this could delete derivations pulled from a nix-shell or nix-build.
I think that perfectly explains the delay I’m seeing, and why I initially thought the garbage collect wasn’t working correctly.
The generation was created 2023-06-06
The next generation was created 2023-06-14 (so the previous generation was in use up to this date)
The generation created on 2023-06-06 was garbage collected on 2023-07-15
2023-06-06 + 9 days in use + 30 day gc delay = 2023-07-15 (when I saw it getting removed)
I see, I didn’t realize that they have different uses. I imagine the normal garbage collect still would delete nix-shell and nix-build derivations though?