NixOS 101 Course / Section 4: Building and deploying NixOS systems
Premium

4.1 How nixos-rebuild works under the hood

Lesson 17 of 28 · 12:14

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Introduction to nixos-rebuild
  2. 1:35 Flake-based system configuration
  3. 3:50 Non-flake builds with default.nix and Nixtamal
  4. 6:30 Top-level derivation and system contents
  5. 9:20 How nixos-rebuild maps to switch-to-configuration
Transcript

Introduction to nixos-rebuild

0:00 Okay, so let's have a closer look at the nixos-rebuild tool now. The nixos-rebuild tool is generally quite the Swiss army knife. We can use it to locally build and deploy a system. We can also use it to locally build and remotely deploy a system. We can use it to remotely build and locally deploy and remotely build and remotely deploy somewhere else. And the thing is that many people don't really understand how the nixos-rebuild tool really works under the hood.

0:30 And so we're going to do that now in the next videos. And then you can have a better decision if you need another tool or not. Because I've seen in practice many, many people use tools like krops, Colmena, NixOps and so on and so on, which are all good for their use cases. But oftentimes you actually don't need them. And then sometimes people prematurely switch to such tools, inherit their design decisions and then do things that they shouldn't have to just to get the same result as they could also have with nixos-rebuild.

1:03 So in order to help you not fall into that trap and only use the external tools if you really need them, let's have a quick look at how nixos-rebuild really works. In general, the nixos-rebuild tool basically accesses with multiple parameters whatever you need. The thing is here we have the flake parameter that points into a system flake folder and then extracts the system configuration from there.

The full transcript comes with the lesson.

About this lesson

nixos-rebuild is the deployment tool you already have. It does less magic than it seems. This lesson builds a system with and without flakes, takes the result apart, and shows the few steps behind switch, boot, and test. Knowing them helps you judge whether you need Colmena, NixOps, or any other tool at all.

In this video

  • Keeping your configuration in your home folder and needing root only for the very last step
  • --flake versus --file: the same system with and without flakes, pinned with Nixtamal
  • What is inside the toplevel derivation, and why several system versions fit on one disk
  • The script that nixos-rebuild really calls, and doing the same thing by hand

After this lesson

You can build and activate a NixOS system with or without nixos-rebuild. You know what each of its subcommands does.