Building reproducible development environments

Snowflake

© Photo by Marc Newberry on Unsplash

© Photo by Marc Newberry on Unsplash

Article from Issue 299/2025
Author(s):

Nix flakes modernize the Nix package manager's promise of reproducible builds with structured project definitions and built-in dependency locking, making Nix code more shareable across projects.

Nix [1] is a purely functional package manager and environment manager known for its reproducible builds and ability to install multiple versions of software side-by-side. Unlike traditional package managers (e.g., APT or Yum), Nix builds packages in isolation and stores them in the Nix store (/nix/store) with unique hash identifiers, ensuring that each build is immutable and isolated. This approach eliminates dependency interference (no more "DLL hell") and enables atomic upgrades and rollbacks of software environments. Advanced users leverage Nix to create development shells, manage system configurations, and even build Docker images – all in a declarative, reproducible manner.

Nix flakes [2], a newer feature (introduced experimentally in Nix 2.4), address several shortcomings of traditional Nix workflows. Flakes introduce a standard project structure and a lock file mechanism to pin dependencies, making the evaluation of Nix expressions as reproducible as the builds themselves. In classic Nix, evaluation could be influenced by external factors (like the NIX_PATH, environment variables, or impure file accesses), meaning two users could get different results from the same Nix code if their environments differed. Flakes enforce hermetic, self-contained Nix projects by requiring explicit declarations of all inputs and locking them to exact versions. Flakes ensure that any machine using a given flake sees the same dependency versions, thus guaranteeing reproducible development environments.

Improved Reproducibility and Dependency Locking

Traditional Nix workflows often relied on channels or the NIX_PATH to obtain Nix expressions (e.g., import <nixpkgs> {}). Channels are essentially pointers to a Nixpkgs version that update over time. This led to a major reproducibility problem: Two machines could evaluate the same import <nixpkgs> expression at different times and end up pulling different commits of Nixpkgs. Channels undermined reproducibility, because there was no guarantee that each developer had the exact same Nixpkgs snapshot unless they manually pinned it. Tools like niv provided manual pinning, but Nix lacked a built-in, convenient way to lock dependencies until the arrival of flakes.

[...]

Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • NixOS 22.5 Is Now Available

    The latest release of NixOS with a much-improved package manager and a user-friendly graphical installer.

  • News

    HP and System76 Announce the Dev One Laptop; NixOS 22.5 Is Now Available; Titan Linux Is a New KDE Linux Based onDebian Stable; Next-Generation HTTP/3 Protocol Arrives as a Standard; The Next Linux Kernel Could Be a Big Deal and Millions of MySQL Servers Exposed

  • Docker Open Source Developer Tools

    Docker provides the open source tools and resources for compiling, building, and testing containerized applications.

  • Static Code Analyzers

    Admins daily use scripts to automate tasks, generate web content, collect and parse data, and perform many other tasks. A few sophisticated tools can tell admins where script problems lurk.

  • Tutorials – Docker

    You might think Docker is a tool reserved for gnarly sys admins, useful only to service companies that run complicated SaaS applications, but that is not true: Docker is useful for everybody.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News