Finding the reason for the presence of some /nix/store path

In my /nix/store there is path /f851smi41190sdqascv5z9wpfgnbdqkd-cudatoolkit-11.6.1 which takes up 4.5 GiB of memory. I would like to know the reason for his presence. I have already started cleaned old generations and garbage collect.

➜ sudo nix-collect-garbage -d

➜ sudo nix-store --gc

➜ sudo nix-env -p /nix/var/nix/profiles/system --list-generations
 195   2022-06-11 12:04:29   (current)
➜ sudo nix-store --query --roots /nix/store/f851smi41190sdqascv5z9wpfgnbdqkd-cudatoolkit-11.6.1
/nix/var/nix/profiles/per-user/denis/home-manager-107-link -> /nix/store/xd2i2q2rd5pv37612l9hgl6b53llapig-home-manager-generation
/nix/var/nix/gcroots/per-user/denis/current-home -> /nix/store/xd2i2q2rd5pv37612l9hgl6b53llapig-home-manager-generation
/proc/3765/environ -> /nix/store/f851smi41190sdqascv5z9wpfgnbdqkd-cudatoolkit-11.6.1
/proc/3774/environ -> /nix/store/f851smi41190sdqascv5z9wpfgnbdqkd-cudatoolkit-11.6.1
/nix/var/nix/profiles/per-user/denis/profile-99-link -> /nix/store/zrnhpwfc3mz55fjpy182s0jqg0y1rq0c-user-environment
/proc/1541/fd/18 -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1679/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1537/fd/22 -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/2117/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1541/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/2117/fd/15 -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/3342/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1500/fd/12 -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/2084/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/2049/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/2049/fd/42 -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1450/fd/15 -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1557/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1919/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1450/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1537/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1535/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1500/maps -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/proc/1535/fd/16 -> /nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/nix/var/nix/profiles/system-195-link -> /nix/store/7mbdi5dl8bl23iagcrk9agnb5ywq4shl-nixos-system-Denis-N-22.05.751.8b66e3f2ebc
/run/current-system -> /nix/store/7mbdi5dl8bl23iagcrk9agnb5ywq4shl-nixos-system-Denis-N-22.05.751.8b66e3f2ebc
/run/booted-system -> /nix/store/7mbdi5dl8bl23iagcrk9agnb5ywq4shl-nixos-system-Denis-N-22.05.751.8b66e3f2ebc

Whatever I do this path is still in the system. And apparently it is not connected with the old generations, but with the current one. So the question is whether it’s possible to know which part in configuration.nix causes this path to exist. Is there some command that can point to a line in configuration.nix?

Oh I found

➜ sudo nix-store --query --referrers-closure /nix/store/f851smi41190sdqascv5z9wpfgnbdqkd-cudatoolkit-11.6.1
/nix/store/f851smi41190sdqascv5z9wpfgnbdqkd-cudatoolkit-11.6.1
/nix/store/xp9nc9pqvnm7yzln29aw1cpv45hrp0nx-python3.9-pynvml-11.4.1
/nix/store/f3r1vhdmpwvm8vaii1fzc6nfzjxk83nx-python3-3.9.13-env
/nix/store/s4a4xqznfz70kk8j75qfbiwaqpv3md3k-gwe-0.15.4
/nix/store/svl722sii0h6f5lhdymhpwgi8cfmf0w7-home-manager-path
/nix/store/xd2i2q2rd5pv37612l9hgl6b53llapig-home-manager-generation
/nix/store/ksrfz869an1rabca0lrpn2vhyp7rrbif-unit-home-manager-denis.service
/nix/store/0n2v4g6hbafpfah12pna4x1s0ivyaqsh-system-units
/nix/store/4lfwflg4p4y0p7ibxd6ddviw80aw3b83-etc
/nix/store/7mbdi5dl8bl23iagcrk9agnb5ywq4shl-nixos-system-Denis-N-22.05.751.8b66e3f2ebc
/nix/store/9rlvqnjsx47474xdwy8bjsgkrh1p6pmq-env-manifest.nix
/nix/store/kwy6falfzhcpkz0zm444lj0g82g5ld0a-user-environment.drv
/nix/store/zrnhpwfc3mz55fjpy182s0jqg0y1rq0c-user-environment

Apparently it’s GreenWithEnvy that makes this path present. It’s a little strange that the dependency weighs 4.5 GiB, I don’t think that on other distributions gwe requires or at least fully installs cudatoolkit. Seeing 4.5 GiB, I could not help but suspect the remains of some dependencies for the ML environment.

Therefore, the question is actually valid, it would be convenient to see the very reason for the presence of a path in the system. For example, a line in configuration.nix or an old generation. Perhaps there is such a command?

More precisely, GreenWithEnvy uses pynvml to interact with the NVidia Management Library. And pynvml seems to pull in the whole CUDA Toolkit. This seems like a bit of overkill to me.

But since I’m not involved in NVidia packaging for Nix (just read here and there that it’s apparently not trivial), I can’t really judge if there would be better ways to tackle this.