I need some help reducing the size of the Nix store

Hi everyone,

I need some help reducing the size of /nix. I have been through the storage optimization article in the wiki, and have ran garbage collection, with and without root privileges, as well as nix-store --optimise, but /nix is still 140GB which seems far too much.

What are the next steps I can take?

  1. Check your GC roots in /nix/var/nix/gcroots and its children.
    Especially the autoroots which point to result symlinks or some direnv/lori managed shells can easily grow into infinity when forgotten.
  2. Remove old unneeded generations, either by manually using nix-env --profile … --delete-generations … as the appropriate user.
  3. If in doubt use nixos-collect-garbage --delete-older-than …
  4. do these on a regular basis or via cronjobs/systemd timers.

Thanks, removed GC roots helped a lot. Now down to 93GB, which still seems like a lot. I have already removed every generation except the currently booted one.

If you’ve done a lot of updates without rebooting, it’s possible the old running processes are keeping old store paths alive from the GC. Nix checks the executables and environment variables of running processes to avoid GC’ing anything they need. Just a guess.

I have rebooted, so this is not the case.