This seems like an obvious questions but I can’t find in manual / on discourse how to list all NixOS generations on my laptop and delete some.
I know about
nix store gc but I’d like to for example delete generations from yesterday when I was experimenting but keep a generation from the day before.
I found some mention of
nix-env that can do that but I’d prefer to use
nix (the new version) if possible.
/nix/var/nix/profiles/ and remove symlinks for generations you want to delete, then
nix store gc.
Indeed I didn’t see an obvious place where this is documented - either I didn’t look in the right place yet or that might be something that’s worth improving
nix profile history --profile /nix/var/nix/profiles/system
sudo nix profile wipe-history --profile /nix/var/nix/profiles/system --older-than 14d.
man nix3-profile-history and
Thank you very much both! I’ve just rebuilt twice in a row and
nix profile history is showing only one new number - not two. So it’s working as I hoped it will.
Is it possible to see if I’m on the latest generation? For example if I run
nixos-rebuild boot --flake ... I shouldn’t be and if I run
nixos-rebuild switch --flake ... I should be.
You could check if
/run/booted-system/ point to the same system as
Maybe something like this:
diff <(ls -l /run/current-system/ | sort) <(ls -l /run/booted-system/ | sort)
Could you please confirm that this is supported / safe method? Asking since this is not a CLI command and I worry that I that brake something by messing with symlinks.
And I don’t want to use
sudo nix profile wipe-history --profile /nix/var/nix/profile/system --older-than 14d since I want to keep a few older generations.
Deleting symlinks from
/nix/var/nix/profiles/ is mostly safe. It might leave you with some broken entries in Grub, but those should be cleaned up with the next