Nix Cleanup Everything
In order to really understand Reflex package versions, I wanted to use a clean Nix environment. Since I have created Nix configuration to build various projects using many different versions of GHC, my Nix store had many versions of numerous packages. With a clean environment, I will be able to better appreciate what is going on.
I tried the obvious thing first. Since I generally use nix-build
and nix-shell,
I did not have much in my user profile. I just had nix
,
nix-thunk
, and obelisk-command
. I removed
nix-thunk
and obelisk-command
using nix-env
--uninstall
, updated my channel using nix-channel
--update
, and then upgraded nix
to the latest
version using nix-env
-iA nixpkgs.nix nixpkgs.cacert
, as described in the Upgrading
Nix section of the manual. I then ran nix-collect-garbage
-d
to remove the old software.
That did not work. The packages in my profile are as expected, but
there is still a lot of extra stuff in my Nix store. For
example, I still see old versions of nix
hanging around, as
well as derivation files for lots of old stuff.
$ nix-env --query
nix-2.7.0
nss-cacert-3.74
$ du -sh /nix/
1.3G /nix/
$ find /nix/store -maxdepth 1 -type d | grep -- '-nix-' | sort
/nix/store/4z4336r8yhyznz3fiscvz53wgdj43kjb-nix-2.3.11
/nix/store/gysnvgyj8dvscnbsb0mjchc0a03k255h-nix-prefetch-git
/nix/store/h538v75x5xgwzy31s5ia3ah7k6cdyzmy-nix-2.7.0
/nix/store/lnw985cbr209c34qx8dkv8c8ls65yar9-nix-2.7.0-man
/nix/store/qg38cyrahzdfd64mz1qb8bka7mmkhfj8-nix-2.3.11-man
/nix/store/rn9899jk59ckr4fkvxiax8abmb53kf53-nix-2.3.12
/nix/store/sfaic5bff9fi2348cxd392yrp4pvgaiv-nix-thunk-0.3.0.0
$ ls | grep -- '-ghc-' | wc -l
25
Perhaps I have some GC roots?
$ find /nix/var/nix/gcroots | sort
/nix/var/nix/gcroots
/nix/var/nix/gcroots/auto
/nix/var/nix/gcroots/auto/fdkzc380qi3y6mg2xr19ml69m9yfmzvq
/nix/var/nix/gcroots/per-user
/nix/var/nix/gcroots/per-user/tcard
/nix/var/nix/gcroots/profiles
The Nix Pill on the garbage collector has a section titled Cleanup
everything that suggests removing any auto
GC roots and
running nix-collect-garbage
-d
. I did this, but it did not help.
$ rm /nix/var/nix/gcroots/auto/*
$ nix-collect-garbage -d
removing old generations of profile /nix/var/nix/profiles/per-user/tcard/profile
removing old generations of profile /nix/var/nix/profiles/per-user/tcard/channels
finding garbage collector roots...
deleting garbage...
deleting unused links...
note: currently hard linking saves -0.00 MiB
0 store paths deleted, 0.00 MiB freed
The wiki has a page title Cleaning the nix
store. Running nix-store
--gc
did not delete anything, which is expected since I
already ran nix-collect-garbage.
$ nix-store --gc
finding garbage collector roots...
deleting garbage...
deleting unused links...
note: currently hard linking saves -0.00 MiB
0 store paths deleted, 0.00 MiB freed
I am careful about managing result
files, and I have
already checked my projects to make sure that none were forgotten.
Running nix-store
--gc --print-roots
indeed does not show any unexpected
roots. (The output is short enough that it fits on my screen and is easy
to check.) I read the resources linked to from the wiki page, but I did
not get any new ideas.
Out of ideas, I manually removed Nix and reinstalled from scratch. Since I recently had bad luck with multi-user Nix (see Uninstalling Multi-User Nix for details), I stuck with the single-user installation for now. My Nix environment is now clean.
$ nix-env --query
nix-2.7.0
$ du -sh /nix/
434M /nix/
$ find /nix/store -maxdepth 1 -type d | grep -- '-nix-' | sort
/nix/store/0n2wfvi1i3fg97cjc54wslvk0804y0sn-nix-2.7.0
Is there a better way to (really) remove old versions of software that are no longer being used?