NixOS 101 Course / Section 2: NixOS configuration and the module system
Premium

2.1 Reading NixOS configurations and finding options on search.nixos.org

Lesson 8 of 28 · 14:17

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 How NixOS Modules Work
  2. 2:00 Finding Options in search.nixos.org
  3. 5:00 Configuring OpenSSH Declaratively
  4. 7:50 Reading Module Source and Documentation
  5. 10:20 More NixOS Module Examples
Transcript

How NixOS Modules Work

0:00 Okay, so in the last videos we've been playing with a real NixOS system and we've been installing and uninstalling things, we've been upgrading it and garbage collecting stuff. So let's have a more theoretical view now on how the NixOS modules that we have been writing actually work, because that will be vital for understanding what else is there so that you're not dependent on tutorials any longer, and how to write your own, which is the ultimate goal of this training in the end.

0:32 So in general, a NixOS module looks like this. We have seen this basically as our configuration.nix in our installed system. It always looks the same. If you go with the normal installer, have some kind of hardware configuration.nix, you'll define your host name, what kind of packages you want, and the system state version. Let's discuss this one piece here again. So because this is really important and many people don't really get correctly what this stands for.

1:02 If I basically install the system like this here, like multiple years ago on this old release and I want to upgrade it, it might be tempting to set this to the more modern number. This would be 26.05 or 26.11, and then you would rebuild the system and see that there's no difference, because this doesn't do updating. It basically says, this is like a token that says what state, what was this system initialized in.

The full transcript comes with the lesson.

About this lesson

Where do attribute paths like services.openssh.enable come from, and how do you find the ones you need? This lesson takes apart a typical configuration.nix, searches options on search.nixos.org, and follows them into the nixpkgs source that defines them. Along the way you enable and configure an SSH server.

In this video

  • The structure that every NixOS module shares, from function header to imports
  • Searching options instead of packages, and picking the right release channel
  • services. versus programs., and why a configured program beats a bare package
  • Why NixOS options are half NixOS knowledge and half knowledge of the program itself
  • Examples beyond services: declarative users with SSH keys, running ARM and Windows binaries on x86, and shipping a kernel patch together with its config

After this lesson

You can find, read, and use any NixOS option, and you know where to look when the documentation is not enough.

Links: