Flake schemas

Eelco Dolstra

Playlists: 'nixcon2023' videos starting here

Flakes are a format for distributing Nix-based assets such as Nix packages, development shells, CI jobs and NixOS modules. The flake specification doesn't impose any restrictions on the contents ("outputs") of a flake, and these can be arbitrary Nix values. While this makes flakes very flexible, it means that there is no generic way to find out what a flake provides, or to check its correctness. To work around this, tools such as `nix flake show` and `nix flake check` have built-in support for a fixed set of flake output types such as `packages` and `devShells`. Unfortunately, this set cannot be extended by users to handle new flake output types.

In this talk, I propose *flake schemas*, which are essentially Nix functions that enumerate the contents of a flake output, including documentation, checks and options. Flake schemas do not impose a type system on flake outputs - it is entirely up to the schema function how it checks the flake output. Flake schemas allow us to remove all output-specific code from commands like `nix flake {show, check, search}`, making it easier for developers to introduce new output