How to get rid of unused home manager packages?

While it is hard to really break a Nix installation, I would be careful with that. At least build a new generation before running garbage collection.

With that said, it can easily happen that there are stray gcroots hidden in unexpected places (from building envs from shell.nix files, for example).

I usually use this snippet to find them:

sudo -i nix-store --gc --print-roots | egrep -v '^(/nix/var|/run/current-system|/run/booted-system|/proc|{memory|{censored)'
4 Likes