Is there a way to prevent the first generation (or some other generations) to be garbage collected by nix-collect-garbage?
Thanks,
AM
Is there a way to prevent the first generation (or some other generations) to be garbage collected by nix-collect-garbage?
Thanks,
AM
for a generation to be collected it first has to be deleted. donât delete generations you want to keep?
nix-collect-garbage doesnât delete any gcroots. Perhaps you meant nix-collect-garbage -d, or another alternate mode?
Also, the âfirst generationâ is a very strange thing to want to keep, assuming that means âoldest generationâ. If that means ânewest generationâ instead, then donât worry, nix-collect-garbage -d and its companions never delete that.
Yes, I meant the oldest generation. Also as my disk space is limited, I periodically run nix-collect-garbage -d.
Well, wanting to keep the oldest generation and running nix-collect-garbage -d are not compatible.
If you want a pattern of generation deletion not supported by nix-collect-garbageâs options, youâll need to write something yourself that deletes the right profile symlinks, then run nix-collect-garbage with no options.
I think a feature to pin/freeze/protect a given generation that nix-garbage-collect skips would be nice.
Why? Seriously, this seems like a really strange thing to wantâŚ
Why is it strange?
I want nix-garbage-collect -d to skip certain flagged generations.
It is for convenience.
Convenience of what?
I think you mean that you want to delete selected generations and after that run ânix-garbage-collectâ
sudo nix-env -p /nix/var/nix/profiles/system --delete-generations 2 3 5 99
and i found a sh on wiki
Convenience of running nix-garbage-collect -d, and knowing certain generations wonât get deleted (1, 13, 17, 73, etc.), without memorizing them.
Of course I can write a bash script to do it, but having it built-in would be nice.
For example:
nix-protect-generations 1 13 17 73
after which nix-garbage-collect -d skips those generations automatically.
Also why are you so angry?
It doesnât seem convenient because why would you want to boot into the first generation? That doesnât make sense, it will be insecure and completely different, missing any programs and changes you made since then. If you have a working recent generation you should keep that instead.
Also, keeping really old generations will use more disk space as they will have less overlap with the current generation even with store optimisation enabled.
Even if I donât want to keep the first generation, I might want to keep some of the later generations.
Youâre still avoiding the real question: why would you want to keep specific generations around beyond normal time/count constraints?
Iâm not angry. Sorry if it seems that way. I am mildly frustrated because this feels distinctly like an XY Problem, and youâre avoiding giving me the information I need to actually help you.
not really I imagine saving a good one before testing a whole lot of potentially breaking changes makes a lot of sense
Better to use nixos-rebuild test for that, so they donât go in the generation list at all.
To be fair in some cases that isnât possible, especially if the new generation needs a reboot.
I think generations with a profile name nixos-rebuild switch --profile-name <name here> do not get deleted by nix-collect-garbage
(and I think also usually show up lower down in the boot menu)
So that might be the solution for you
(but as others have said, apart from temporarily testing something else, there is little reason to keep previous generations around, especially if you put your .nix file in a git repo)