1.6 Nix garbage collection: cleaning up the store
Lesson 6 of 68 · 4:38
Video chapters
-
0:00 Where Nix Packages Live on Disk
-
0:58 Collecting Unused Store Paths
-
2:26 Deleting Old Generations with -d
-
3:25 When to Run Garbage Collection
Transcript
Where Nix Packages Live on Disk
0:00 Okay, after we installed a lot of packages, either using nix run, nix shell, nix profile or nix build, we were able to get rid of them easily by just exiting the shell or using nix profile remove or whatever, but we already have seen that when we just install the same package again, it's there immediately, so that means it must be somewhere still on the disk. Let's have a quick look at that. So on my system here, when I run ls/nix/store, there's a whole lot of paths there.
0:34 I mean, they have weird names, a few things that I didn't explicitly install, but yeah, it's quite a lot. When I say, let's calculate the size, it will be relatively large, multiple gigabytes at this point, or just to, I mean, it's a very fresh nix installation.
Collecting Unused Store Paths
0:58 The question is now how can we get rid of applications that we don't have any longer, right? Let's say nix profile list, let's remove all the applications that we have here, nix profile, remove log count, hello, ripgrep and bottom. And we have no shell active, we have no symlinks, nowhere, nothing. How do we get rid of that? We can say nix-collect-garbage, that will now find out all the packages that we have in the store, but not referencing from a profile or whatever.
The full transcript comes with the lesson.
About this lesson
Everything Nix ever downloaded is still on your disk, which is why removed packages reappear instantly, and why /nix/store grows into many gigabytes. This lesson shows how Nix garbage collection works, why the first nix-collect-garbage run frees less space than you expect, and which flag makes it thorough.
In this video
- A look inside
/nix/store: measuring its size and understanding why removed packages are still there - Running
nix-collect-garbageand reading its output, and the reason a big chunk of the store survives the first run - The extra flag that also deletes old profile generations, and exactly what you give up by using it
- When not to collect garbage: the flight and train rule
- How often cleanup makes sense in practice, with real store sizes from production machines, and a pointer to automatic garbage collection with limits
After this lesson
You know why your disk fills up, and you can free space deliberately without destroying the rollbacks you still want.