Towards reproducibility: pinning Nixpkgs#

In various Nix examples, you’ll often see references to <nixpkgs>, as follows.

1{ pkgs ? import <nixpkgs> {}

This is a convenient way to quickly demonstrate a Nix expression and get it working by importing Nix packages.

However, the resulting Nix expression is not fully reproducible.

Pinning packages with URLs inside a Nix expression#

To create fully reproducible Nix expressions, we can pin an exact version of Nixpkgs.

The simplest way to do this is to fetch the required Nixpkgs version as a tarball specified via the relevant Git commit hash:

1{ pkgs ? import (fetchTarball "") {}

Picking the commit can be done via, which lists all the releases and the latest commit that has passed all tests.

When choosing a commit, it is recommended to follow either

  • the latest stable NixOS release by using a specific version, such as nixos-21.05, or

  • the latest unstable release via nixos-unstable.

Next steps#