Introduction
Managing your NixOS system is not always a simple task. It sometimes requires you to look in directions that you have not previously thought of.
One of such examples is my recent encounter with the residues left floating around in both:
/nix/var/nix/profiles/per-user/
/nix/var/nix/gcroots/per-user/
Where both of these directories had retained my pre-flake setup (1 year old) and never complained about the garbage even though I had on many occasions used:
sudo nix-collect-garbage -d
sudo nix store gc
nix store optimise
After venturing inside my /nix/store
directory, I had found package builds
tracing back to 2021-08-26
, the date I used to run a non-flake based NixOS
configuration. That had me surprised and after continues questionings and
command pasting, I had came across the following command (output by Nix):
nix store query --roots /nix/store/dapkosdkaspokdqw-old-package
; a command
intended to help you unravel what could be using a certain package.
Apparently, nix-store
garbage collect had failed to recognize the status of my
old user and therefore thought it was still being used, although there had been
no mentions of it in my flake setup!
To counter this issue, manual intervention was required:
sudo rm /nix/var/nix/profiles/per-user/old-user/ -rf
sudo rm /nix/var/nix/gcroots/per-user/old-user/ -rf
And afterwards I had ran:
sudo nix-collect-garbage -d
sudo nix store gc
To later find out that 21962.08 MiB
had been freed from my system!
1 store paths deleted, 150.24 MiB freed
(nix-collect-garbage
)15027 store paths deleted, 21811.84 MiB freed
(nix store gc
)
Closing Statement
Be on a look-out for old information that could still be haunting you today. You never know what the garbage collector fails to clean-up!