Nix 101 Course / Section 9: Flakes
Premium

9.6 Flake outputs in depth: packages, apps, checks and more

Lesson 64 of 68 · 20:45

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Flake output categories overview
  2. 1:51 Packages and apps in practice
  3. 5:00 Checks and CI validation
  4. 8:54 Formatter and treefmt setup
  5. 12:15 Overlays and reusable package definitions
  6. 15:30 NixOS modules and configurations
  7. 19:00 Custom outputs and wrap-up
Transcript

Flake output categories overview

0:00 Okay, we have seen that a Flake can emit packages and dev shells and we already hinted that there's even more to that. And then there's different commands to actually use those different kinds of output. Let's discuss what other categories Flakes provide and also play with them. In general, we have already seen packages, right? So if you have a Flake output that's inside the packages category, then you will have an attribute path like packages.architecture.package_name.

0:32 And imagine the package name is my_package, then you could just say nix build my_package. And then it depends, like, if the Flake is in your local folder, you would just make a dot here to say this folder, #my_package. And then it would just build that. There's also an output at the attribute category called apps. So everything that is an app can be run with nix run, flake, my_app.

1:02 Although that also works on packages automatically if the packages metadata contains the executable name. We'll have a look at that. There's NixOS modules and configurations. That is for clustering system configurations and also modules that you reuse across different systems. And they are accessible with the nixos-rebuild command. So as soon as you point nixos-rebuild to a Flake using the --flake parameter, you can point it to the folder with configurations and then the nixosConfigurations.my_config attribute would be built here.

The full transcript comes with the lesson.

About this lesson

Packages and dev shells are only two of the output categories a flake can provide. This lesson walks through the whole set: apps, checks, overlays, nixosModules, nixosConfigurations and formatter, each connected to the command that consumes it. One well-filled checks attribute turns your entire CI into a single nix flake check.

In this video

  • When you need an apps entry and when meta.mainProgram already does the job for nix run
  • Building every test in parallel with nix flake check, and why this is the cheapest CI setup you will find
  • One formatter definition so nix fmt runs the right tools in any checkout, including a treefmt setup driving several formatters at once
  • Why exposing an overlay next to your packages gives users a choice most flakes deny them
  • Which output categories skip the architecture level, how to merge them with the per-system ones, and what happens with custom categories you invent yourself

After this lesson

You know every standard flake output, which command picks it up, and how to lay out a flake that other people enjoy consuming.

Builds on: Anatomy of a flake: inputs, outputs and the lock file (9.2)