Nix 101 Course / Section 9: Flakes
Premium

9.4 Starting a flake from scratch with nix flake init

Lesson 62 of 68 · 18:49

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

Time to write your own flake. Starting in an empty folder, nix flake init generates a template, and this lesson explains every line of it, then grows it into something real: your own patched package, a dev shell for nix develop, and static and cross builds. You also meet a second template that reimports nixpkgs, for the day you need your own config options or overlays.

In this video

  • Why your flake inputs should point at nixos-unstable instead of master (the answer is caching)
  • The builtins.mapAttrs pattern that covers all architectures without flake-utils or flake-parts
  • Creating a new package with overrideAttrs, then getting pkgsStatic and pkgsCross variants almost for free with one small change
  • When the standard template is not enough: unfree packages, nixpkgs config, and the template that handles them
  • The boilerplate problem that made everyone's flakes look different again, and the two styles worth sticking to

After this lesson

You can start a flake for a new project in minutes and pick the right template for it, without pulling in helper libraries.

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