Pinning Dependencies Using Nix Flakes

To prevent the risk of installing software incompatible with our local code as the nixpkgs changes over time, we can use a Nix Flake to pin the package index to a specific version. This will ensure that we always use the package index as it was at a particular point in time.

A Nix Flake is a file flake.nix, containing code written in the Nix Expression Language, that declares a set of dependencies and contains build instructions for software using these dependencies. When pinning these dependencies, permanent references (e.g. permalinks, Git hashes) are recorded in a file called flake.lock. This is similar to how other language-specific package managers work: Stack has stack.yaml and pins dependencies in stack.yaml.lock, Cargo records dependencies in Cargo.toml and pins them in Cargo.lock.

Warning

Nix Flakes are an unstable feature of Nix. Things might've changed slightly since this tutorial was written.

In any case: Head over to the Wiki for instructions on how to enable Nix Flakes.

Note

This is not a tutorial on the Nix Language. Feel free to familiarize yourself with the language by either reading the superb Nix Pills series of tutorials, or Chapter on writing Nix expressions of the Nix manual.