Nix 101 Course / Section 6: Composing nixpkgs: callPackage, override, project layout
Premium

6.1 How to structure a real Nix project

Lesson 40 of 68 · 7:56

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Project Structure and Nix Patterns
Transcript

Project Structure and Nix Patterns

0:00 So in this section, we will talk about project patterns. The idea is to motivate some new theory with new functionality that gives us a lot of power that is especially interesting in project structure and context. So until now, we just wrote individual Nix expressions, like one by one. And in real projects, you would have plenty of those. And then they feed into each other and stuff like that. And later, you will even potentially build deployments or system images or whatnot from that.

0:34 And then it's interesting to be able to manipulate what the package does without having to fork or rewrite it thoroughly. So at first, we will discuss project structure and how it is typically designed. So in a normal Nix project, where you have more than just one Nix expression, of course, you do that when there's libraries, multiple applications, maybe some Python subproject, maybe some Go, subproject Rust, whatever.

1:04 Many real life projects just mix tech stacks where it fits. And so the idea is that you will in the future have some subproject A, subproject B, subproject C. And they will typically describe themselves, how to build this and how to build that. And the whole idea here is that when A consumes B, they both shouldn't know from each other where they are each. And then later, we will have a flake.nix file if you use Flakes or which is practically the same thing, but slightly simpler, release.nix, default.nix, and shell.nix.

The full transcript comes with the lesson.

About this lesson

One Nix expression is easy. A real Nix project has many: multiple subprojects, mixed languages, tests, docs, tooling. This lesson lays out the standard Nix project structure, what default.nix, shell.nix, release.nix and flake.nix are each for, and why a good layout shrinks rebuild times and keeps your CI config from growing forever.

In this video

  • Why each subproject should describe its own build, and why subproject A should never know where B lives
  • The entry point files every outside consumer expects, and the job each one does
  • How small per-package sandboxes improve build times and caching compared to one big build
  • Turning CI into a plain Nix build runner instead of ever-growing YAML files
  • Documentation, test coverage reports, formatters and linters as buildable outputs anyone can discover with two commands

After this lesson

You can open any repository in your company, no matter the language, and know where the builds, shells, tests and docs live. And you know the shape your own projects should grow into, with or without flakes.