For a while now I've been wondering about Nix Flakes, what they are and how they are going to change how we use Nix.
This post is a summary of my understanding so far based on research (see resources below) and some light experimentation. Disclamer: I am quite new to flakes and by no means a Nix expert, so if something in this article is inaccurate or wrong please reach out and I'll fix it! Warning: The word flakes appears over 30 times in this blog post. Nix Flakes? Nix Flakes are an upcoming feature of the Nix package manager. Flakes allow to define inputs (you can think of them as dependencies) and outputs of packages in a declarative way. You will notice similarities to what you find in package definitions for other languages (Rust crates, Ruby gems, Node packages) - like many language package managers flakes also introduce dependency pinning using a lockfile . What can they do for everyone? The main benefits of flakes are: Reproducibility: Even if the Nix language is purely functional it is currently not possible to ensure that the same derivation will yield the same results. This is because a derivation can have undeclared external dependencies such as local configuration, $NIX_PATH , command-line arguments and more. Flakes tackle this issue by making every dependency explicit as well as pinning (or locking) their versions. Standardization: Every Flake implements a schema and defines clear inputs and outputs (see below for more details). This allows for better composability as well as avoiding the need for niv. Discoverability: Because all outputs are declared, it is possible to know what is exposed by a flake (i.e which packages). What can they do for me? On top of the above there are other practical benefits for day to day Nix use. Faster nix-shell(s) Nix Flakes add another layer of caching that was not possible before: the evaluation of Nix expressions. A very practical result of this change is that nix-shell gets a whole lot faster. The first run will take the usual time but any subsequent one will be practically instant! A new nix command Another…