Removing python2 from my system

As there are currently still 130 pathes in the store (straight after rebuild + GC), I am trying to find out where they come from:

$ ll /nix/store | grep python2 | wc -l
130
$ for p in /nix/store/*-python2.7-*; do nix why-depends /run/current-system/sw "$p"; done
'/nix/store/s2f4mc87cbkynifbl0fbkrkq90j2xr70-system-path' does not depend on '/nix/store/4gh9k680nd2x41z0lp0rz75h1mx2583d-python2.7-bootstrapped-pip-19.2.3'
[…]
$ for p in /nix/store/*-python2.7-*; do nix why-depends ~/.nix-profile "$p"; done
[…]

All printed lines are just “does not deped on”… So is there a way to ask nix for the reverse of why-depends? Such that it tells me which profile or gcroot is holding on those pathes?

As you don’t mention it, did you remove the old generations from /nix/var/nix/profiles/ before the garbage collection?

No, but shouldn’t --delete-older-than do that?

If there are no profiles newer than what you specified, it should work, but checking that directly might be useful to see if you have any left over generations that you did not expect.
There’s also /nix/var/nix/gcroots/ which may contain other roots that keep paths in the nix store. Some are removed automatically, but I usually have some old result links from manually running nix build or similar commands. So it might be worth checking those two directories anyway.

Thats exactly, why I asked for a way to ask a path for roots that might keep it from beeing deleted.

I do not want to go through all possible roots that might be spread across 4 users + the system.

Well, you could turn your above commands into a one-liner that iterrates over all paths in those two directories and then look at the results.
I do not know of a better way, but maybe someone else has an idea?

If you’re expecting something not to be in the store at all, nix-store -q --referrers does a pretty good job.

nix-store -q --tree /run/current-system is probably what you want to get remove Python 2 from your system closure.

Using the nix-tree package (i.e. nix-tree /run/current-system) is even better (quicker/easier to navigate - simply search for python2 using /, select an entry, and move up in the tree using h).

Good luck :wink: Let’s hope we can get rid of Python 2 soon :slight_smile:

As pointed out in the original post, there was no dependency on any of the python 2 related store pathes in the system and user profile.

As I am very tired since a couple of days and basically fall asleep after diner, there is currently no time to figure it out… Tomorrow I will check the store again, as I GC with a 5d threshold they will either be gone by then or I will delve again during the weekend…

I missed that, sorry :o

IIRC /run/booted-system/ will never be GCed (only the symlink for the generation) and also any “active” store paths (see e.g. lsof). But this probably doesn’t help either as I assume you did a reboot and then ran nix-collect-garbage --delete-old as root (which should GC everything old).

And if they’re still there something like nix-store -q --referrers-closure /nix/store/3na31g5fabchcfyb3iqys5ig9w6jm35q-python2.7-pycairo-1.18.2, which @Gaelan already mentioned, should reveal why (if not there’s likely a bug somewhere).