9.4 Starting a flake from scratch with nix flake init
Lesson 62 of 68 · 18:49
Up next in 5s…
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-unstableinstead ofmaster(the answer is caching) - The
builtins.mapAttrspattern that covers all architectures withoutflake-utilsorflake-parts - Creating a new package with
overrideAttrs, then gettingpkgsStaticandpkgsCrossvariants 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)