Can't find out what takes so much space in my store

Hello :wave:
I have a 40 GB server and my store is 26 GB big so I need to make some space.
I already did:

sudo rm /run/booted-system
sudo rm /nix/var/nix/gcroots/auto/*
sudo nix-collect-garbage -d
sudo nix-store --optimise

Here are the 15 biggest store paths:

❯ sudo du -sh /nix/store/* | sort -hr | head -n 15
1.9G    /nix/store/x1b3zc6mz3qwv33illj7rmri1vq3w3mj-ghc-binary-8.10.7
1.6G    /nix/store/xbq6cqqiibnjqfw13g3wrmc422c8854x-ghc-9.0.2
891M    /nix/store/c8vk231dg7p72kavkp44m6f44pwjhld3-source
854M    /nix/store/qb90xrcx6cn18gicpwysg84way2yvjm2-source
846M    /nix/store/bb31257f8d8b4pipnqgpf23hcjpnk67k-rustc-1.63.0
683M    /nix/store/af31ls6z3r51gd0yhricblr9gx2qp64p-llvm-src-14.0.6
681M    /nix/store/26lg59zjav1irl0znfx5rx3liv47n1r7-source
653M    /nix/store/xwlps0yr4zvkr8yc236498qqd6xkvgj0-source
652M    /nix/store/p9kzd1np5g2q13alw7l9hpiiydgnyi2r-clang-14.0.6-lib
633M    /nix/store/ys42n4m9vpw0cs04c407nyk336g4brqs-gdb-12.1
618M    /nix/store/5qyjmd1c52bzhbyxcy3kll5hi4zlwbnm-ghc-9.0.2-doc
606M    /nix/store/fh99h1c7p8khsan0paca8p2vlyrx54g2-rustc-1.63.0-doc
546M    /nix/store/p2kb2whrhxydnmzq8xv71lvf05w3fwh5-clang-11.1.0-lib
490M    /nix/store/2msq36arf15jv424bldfq4spxyas5pdm-go-1.19.2
421M    /nix/store/9bbzszb1qiqxb8zjg05h0liz1i1wlq37-ocaml-4.14.0

The gc roots:

❯ sudo nix-store --query --roots /nix/store/x1b3zc6mz3qwv33illj7rmri1vq3w3mj-ghc-binary-8.10.7
/proc/108711/environ -> /nix/store/x1b3zc6mz3qwv33illj7rmri1vq3w3mj-ghc-binary-8.10.7
/proc/108715/environ -> /nix/store/x1b3zc6mz3qwv33illj7rmri1vq3w3mj-ghc-binary-8.10.7
/nix/var/nix/profiles/per-user/sweenu/sweenu-7-link -> /nix/store/p4va1g03aqxppd3zd1gmsigvj3k6h3rg-activatable-home-manager-generation
/nix/var/nix/profiles/system-98-link -> /nix/store/06vgpjfpklcpv5pghba409fdviqxxhb4-activatable-nixos-system-benoni-22.11.20221008.c592415
/nix/var/nix/profiles/per-user/sweenu/home-manager-41-link -> /nix/store/zvzi40b8rz4z1n6w5jvp35fa8abr0kiq-home-manager-generation
/nix/var/nix/gcroots/per-user/sweenu/current-home -> /nix/store/zvzi40b8rz4z1n6w5jvp35fa8abr0kiq-home-manager-generation
/run/current-system -> /nix/store/z7kfsabwg5hx3cmz4y7cd84jgjscfi6k-nixos-system-benoni-22.11.20221008.c592415

So then I try to understand why it depends on my system:

❯ nix why-depends /run/current-system /nix/store/x1b3zc6mz3qwv33illj7rmri1vq3w3mj-ghc-binary-8.10.7
'/nix/store/z7kfsabwg5hx3cmz4y7cd84jgjscfi6k-nixos-system-benoni-22.11.20221008.c592415' does not depend on '/nix/store/x1b3zc6mz3qwv33illj7rmri1vq3w3mj-ghc-binary-8.10.7'

It doesn’t :frowning: . So I am quite confused.

What’s even more. If I use nix-tree (sudo nix-tree) I get these two parent closures:

nixos-system-benoni-22.11.20221008.c592415               2.95 GiB (2.95 GiB)
profile                                              191.53 MiB (191.53 MiB)

The closure size is 10 times smaller that what my nix store actually weights and I can not find any trace of ghc or rust or go or ocaml or anything else that takes so much space in my store.

And finally, here’s a referrers query:

❯ nix-store --query --referrers /nix/store/x1b3zc6mz3qwv33illj7rmri1vq3w3mj-ghc-binary-8.10.7

So how to find out why those paths are there and how to know which of my explicitly installed packages (in environment.defaultPackages) I should remove to free the most space I could?

Start by looking into what those processes are, and why it’s linked in their environment, I guess…

1 Like

looks related to this issue Cannot delete a store path when sudo-ing nix-store --delete $storePath · Issue #7053 · NixOS/nix · GitHub

1 Like

That could be, for the query output above - but should not have affected the prior GC?

Is /nix/var/nix/profiles/system-98-link the generation you are currently booted into? nix-collect-garbage --delete-old will not delete the currently active, and currently booted generations.

Check readlink /nix/var/nix/profiles/system-98-link and readlink /run/booted-system.

Also, the prefix activatable in the resolved link makes me think, that not the resulting generation but only the activation script have a dependency on GHC here.

Your HM seems to have the same…

Try to use why-depends directly on the links or their targets.

Everytime I run the command, it’s a new process with a higher pid, so I think it is the command itself that creates the gc root. I still have all the other gc roots that are there for a reason I’m trying to understand.

❯ ls -la /nix/var/nix/profiles/
total 20
drwxr-xr-x 3 root root 4096 Oct 18 09:29 .
drwxr-xr-x 9 root root 4096 Oct 16 21:57 ..
lrwxrwxrwx 1 root root   14 May 30 23:03 default -> default-3-link
lrwxrwxrwx 1 root root   60 May 30 23:03 default-3-link -> /nix/store/s8k24gzxjiph8afnxggabsjdkdf0jfra-user-environment
drwxr-xr-x 5 root root 4096 Oct 13 21:23 per-user
lrwxrwxrwx 1 root root   14 Oct 17 21:45 system -> system-98-link
lrwxrwxrwx 1 root root   98 Oct 17 21:45 system-98-link -> /nix/store/06vgpjfpklcpv5pghba409fdviqxxhb4-activatable-nixos-system-benoni-22.11.20221008.c592415
❯ readlink /run/current-system

❯ readlink /nix/var/nix/profiles/system-98-link

I deleted /run/booted-system.
I tried why depends on the directly on the target of the links and each time does not depend on.

Yes, that’s likely based on the issue Solene linked. Red herring, sorry.

How large is the closure of this profile? Going by the date, even if there are only a few things in it directly, the dependency tree is probably full of old stuff that has been replaced, and could easily be freed otherwise.

Did you at some time in the past install stuff via nix-env as root?

I had a 200 MB big closure. Uninstalled the packages installed with nix-env and re-ran sudo nix-collect-garbage -d and freed 300 MB so still not the problem. :confused: