What are flakes?#
What is usually referred to as “flakes” is:
A policy for managing dependencies between Nix expressions.
An experimental feature in Nix, implementing that policy and supporting functionality.
Technically, a flake is a file system tree that contains a file named
flake.nix in its root directory.
Flakes add the following behavior to Nix:
flake.nixfile offers a uniform schema , where:
References to other flakes can be specified using a dedicated URL-like syntax. A flake registry allows using symbolic identifiers for further brevity. References can be automatically locked to their current specific version and later updated programmatically.
A new command line interface, implemented as a separate experimental feature, leverages flakes by accepting flake references in order to build, run, or deploy software defined as a flake.
Nix handles flakes differently than regular Nix files in the following ways:
flake.nixfile is checked for schema validity.
In particular, the metadata fields cannot be arbitrary Nix expressions. This is to prevent complex, possibly non-terminating computations while querying the metadata.
The entire flake directory is copied to Nix store before evaluation.
This allows for effective evaluation caching, which is relevant for large expressions such as Nixpkgs, but also requires copying the entire flake directory again on each change.
No external variables, parameters, or impure language values are allowed.
It means full reproducibility of a Nix expression, and, by extension, the resulting build instructions by default, but also prohibits parameterisation of results by consumers.
Why are flakes controversial?#
The subject is considered controversial among Nix users and developers in terms of design, development processes, and community governance. In particular:
The RFC was closed without conclusion, and some design and implementation issues are not yet resolved. Examples include the notion of a global flake registry, the impossibility of parameterising flakes, and the new command line interface and flakes being closely tied to each other.
New Nix users were and still are encouraged by various individuals to adopt flakes despite there being no concrete plan or timeline for stabilisation.
This led to a situation where the stable interface was only sparsely maintained for multiple years, and repeatedly suffered breakages due to ongoing development. Meanwhile, the new interface was adopted widely enough for evolving its design without negatively affecting users to become very challenging.
As of the 2022 community survey, more than half of the user base, a third of which were relative beginners, relied on experimental features.
Nixpkgs as a contrasting example, while featuring a
flake.nix for compatibility, does not depend on Nix experimental features in its code base.