How to delete old NixOS boot configurations

24 March 2017

Every time you rebuild your NixOS configuration, a new entry is added to the bootloader. This is helpful if you ever make a configuration change that breaks on your machine because you can reboot into the last known working state and try something different.

If you don’t need to have access to all your old configurations, you can delete them:

1. Delete the old (excludes the current) package configurations for the NixOS system

       sudo nix-env -p /nix/var/nix/profiles/system --delete-generations old

2. Collect garbage

       nix-collect-garbage -d

3. View the remaining generation

       nix-env -p /nix/var/nix/profiles/system --list-generations

4. Remove unnecessary boot loader entries

       sudo vim /boot/grub/grub.cfg
(you might want to back up the entries somewhere to be safe)