NixOS 101 Course / Section 1: Getting started: install NixOS and live with it
Premium

1.7 Reclaim disk space from old NixOS generations

Lesson 7 of 28 · 4:42

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Initial garbage collection cleanup
  2. 0:58 Bootloader generations and GC roots
  3. 2:29 Limiting system generations in NixOS
  4. 3:55 Final garbage collection results
Transcript

Initial garbage collection cleanup

0:00 Okay, so we have a system that's nicely installed. We added and removed a lot of software. It is now all pinned and whatnot. We also piled up a lot of file system space that's kind of wasted now. So natural reaction would be as a root user, we run "nix-collect-garbage". We already know that command from the Nix 101 class and with -d we can actually remove many roots.

0:34 And then this will remove a lot of things that we don't need any longer. And let's see how effective that is. When we scroll up we can see so many paths are being dumped, right? We just deleted 2.8 gigabytes.

Bootloader generations and GC roots

0:58 So we see that we are still using 11 gigabytes of the system and that's kind of weird because no chance that the current system with just XFCE is that large. So the question is, why is that so large and how can we get rid of more? Because "nix-collect-garbage" is the correct command to do that, right? I'm going to show you what is taking up so much space. So when we reboot the system we will come back into the bootloader.

The full transcript comes with the lesson.

About this lesson

You ran nix-collect-garbage -d, and NixOS still uses 11 gigabytes. This short lesson shows what keeps old packages alive on a NixOS system, and the one bootloader setting that cuts disk usage roughly in half.

In this video

  • Why garbage collection on NixOS frees less than you'd expect
  • Where system profiles live and how they keep old generations alive
  • Limiting the number of boot menu entries. How many to keep for a safe rollback

After this lesson

Your NixOS system stays lean without giving up the safety net of rolling back to the previous generation.