How to pin a generation to not be garbage collected

I do sudo nix-collect-garbage -d occasionally, which clears out all the old generations.
Let’s say I have generation 669, which is a stable system, and I want to pin it (so that it is not garbage collected ever, until I ‘unpin’ it). Therefore, even which garbage collection, if my system is fubard, I can go back to that pinned version.

How can I do this?

There is some stuff about gc’ing generations, but I couldn’t discern how to do the above.

Only option I can see to not delete an older generation, is by date, but that is not what I’m looking for. I want to gc everything expect current generation, and some pinned stable config.

1 Like

You want nix-env -p /nix/var/nix/profiles/myprofile --set result command to create a profile.