Automatic gc does not delete old bootloader entries

I have

  nix = {
    gc = {
      automatic = true;
      options = "--max-freed 1G --delete-older-than 7d";
    };
  };

in my configuration.nix. I think this should clean up my old generations. And yet, I still have a generation from over the week ago:

$ ls /boot/loader/entries/
.rwxr-xr-x 447 root 29 Apr 16:27  nixos-generation-215.conf
.rwxr-xr-x 447 root 29 Apr 16:27  nixos-generation-216.conf
.rwxr-xr-x 447 root 29 Apr 16:27  nixos-generation-217.conf
.rwxr-xr-x 447 root 29 Apr 16:27  nixos-generation-218.conf
.rwxr-xr-x 468 root 29 Apr 16:27  nixos-generation-219.conf

$ bat /boot/loader/entries/nixos-generation-215.conf
title NixOS
version Generation 215 NixOS 23.05.20230417.f00994e, Linux Kernel 6.2.11, Built on 2023-04-18

what I am missing? Why this entry is not deleted from the bootloader menu?

Are the generations deleted from the system profile?

And what version of nix are you using?

$ exa -l /nix/var/nix/profiles/
drwxr-xr-x  - root 17 May  2022 per-user
lrwxrwxrwx 15 root 29 Apr 16:27 system -> system-219-link
lrwxrwxrwx 87 root 18 Apr 22:11 system-215-link -> /nix/store/3241xh1axywimi05sqppgn5sgbjlim7f-nixos-system-Ishmael-23.05.20230417.f00994e
lrwxrwxrwx 87 root 27 Apr 21:25 system-216-link -> /nix/store/dh9hglmmq56xmwd3r2rcnxnwjz0myr7p-nixos-system-Ishmael-23.05.20230426.d6b863f
lrwxrwxrwx 87 root 27 Apr 21:37 system-217-link -> /nix/store/bh3yl2ri5m688ygfcam8yj1cbyh3pbg0-nixos-system-Ishmael-23.05.20230426.d6b863f
lrwxrwxrwx 87 root 29 Apr 14:04 system-218-link -> /nix/store/mik0hnrkrvlblpk6jy4v7p46ddyilpbf-nixos-system-Ishmael-23.05.20230428.937a9d1
lrwxrwxrwx 87 root 29 Apr 16:27 system-219-link -> /nix/store/qffs1v48gqp40rrp2lm69glh4mifr0w4-nixos-system-Ishmael-23.05.20230428.937a9d1

$ nix --version
nix (Nix) 2.13.3

You requested to clean all generations that haven’t been active in the last 7 days.

Today is the 29th.

So nix is allowed to delete all generations that haven’t been active after the 22nd.

Generations 216 and newer are obvious, as they have been created only 2 days ago.

Before that, on the 22nd the generation 215 has been active so it can’t be deleted as well.

There is no generation older that 215.

So it seems to be everything fine.

2 Likes

Ah, that makes sense, thanks!

Also, keep in mind, nix-collect-garbage does not clean up your boot loader entries. As far as the garbage collector is concerned, the store is the only thing that matters; nothing else, not even your boot loader. So even if the GC had deleted a bunch of generations, those generations would still appear in your boot loader (and fail to boot because they’re gone). The part that cleans up boot entries is nixos-rebuild switch/boot, so those obsolete entries will be removed when you run that.

5 Likes