Remove duplicates in the nix store

Thanks all - some helpful suggestions. I must admit I’m new so not 100% of what the output is telling me. But wind back a bit. The more I looked at ncdu output after a nix store optimise I realise it has done a lot of linking which, while there remain several copies of the same file (e.g. qemu-9.2.2 they all seem linked so each only only uses a few KB.

So if I ready right thats a win. The total size of my nix store seems to be about 40Gb, which may be normal?

However - I am still curious on some of the results. For reference, I cleaned up using garbage collection command, nix store optimise and then did a rebuild to clean up boot menu options. Then rebooted to ensure clean.

I ran some of the suggested commands:

❯ nix-store --gc --print-roots | grep result
/tmp/nh-osPkgJUR/result -> /nix/store/kjf349yggn1475w2v0v50rf0k6kn1s5f-nixos-system-john-laptop-25.05.20250412.2631b0b

Now I’m not sure what this is telling me exactly. However, when I then ran the suggested script Show closure size of garbage collector roots - #9 by uep

❯ ./closure.sh
  7.4KiB   /nix/store/pc6y12ccrlvmgfbp0rs34cbj8mbsyyvk-flake-registry.json
 20.3GiB   /nix/store/zaxdciv1llr4n2lw4d1lfjdm5bw4swlc-home-manager-generation
 26.7GiB   /nix/store/kjf349yggn1475w2v0v50rf0k6kn1s5f-nixos-system-john-laptop-25.05.20250412.2631b0b
 27.5GiB   /nix/store/hkwiphvp9d8r7hhg1f2758jg08mr2d6c-nixos-system-john-laptop-25.05.20250429.46e634b

Interestingly, there seems to be a reference to a version from 2025-04-12 hanging around. I’m guessing this should have been cleaned up by garbage collection, but for some reason isn’t.

I don’t know the impact of that hanging around but as I’m learning I’m curious why it remains and what I can do to further clean up.