I use nix profile to install some packages in a user-level Nix installation (on top of Debian Stable). Flakes and the “new” CLI are enabled. The whole thing generally works very well, but I ran into a bit of trouble while trying to trim the size of /nix/store after a few updates. In particular, I noticed that some large derivations look orphaned but do not get cleaned up.
One such is ghc-9.2.4. It’s large, and I didn’t explicitly install it, and I don’t know what lists it as a dependency. I thought that nix why-depends would help here, so I did this:
$ nix why-depends /nix/var/nix/profiles/per-user/cv/profile-104-link /nix/store/50h3rrcly4gvxh6xi2g16yxm7zv7ihvr-ghc-9.2.4
'/nix/store/c1b7az76zqll57xqn3lndx4vvvdbl847-profile' does not depend on '/nix/store/50h3rrcly4gvxh6xi2g16yxm7zv7ihvr-ghc-9.2.4'
Nix version 2.13.3 installed here. All combinations of nix profile wipe-history, nix store gc, nix-env --delete-generations old, and nix-store --gc show they’ve already cleaned up everything they can. What gives? I want to get back the 1.5 GB of space.
Despite attempts to get clean up disk space with nix-du and nix why-depends, I’ve got about 20GB used (down from an unaccounted 50GB) and have no idea why.
A few things that helped me reduce it:
find ~ -iname .direnv | xargs rm -rv
find /root/ -iname .direnv | xargs rm -rv
removing any of ls -larth /nix/var/nix/gcroots/ I wasn’t sure about
rebooting after this and running sudo nixos-collect-garbage -d, but sometimes for unknown reasons I feel like some generations stick around
I mixed up disk usage, 20GB was just large video files that I misattributed to “probably /nix/store”
Sorry I can’t be more directly helpful, but hopefully one of those things may help or others could chime in with their experience and we can get find some answers.
Update: deleting everything installed in my nix profile and running gc got rid of the unexplained ghc installation. So that’s good, I guess? It was clearly a dependency somewhere not a leak. It’s still bad that I haven’t found any tools for tracking down why it was there.
Update 2: It looks like I needed this incancation: nix-store --query --referrers-closure /nix/store/path. I can’t verify it would have helped track down that specific leak because I destructively modified that system. I’ll try it next time.