Nix (package manager)

Nix is a cross-platform package manager for Unix-like systems, invented in 2003 by Eelco Dolstra.

Approach
The Nix package manager employs a model in which software packages are each installed into unique directories with immutable contents. These directory names correspond to cryptographic hashes that take into account all dependencies of a package, including other packages managed by Nix. As a result, Nix package names are content-identifying since packages with the same name will have had the same inputs and the same build platform, and therefore the same build result.

Implementation
Package recipes for Nix are written in the purpose-built "Nix language", a declarative, purely functional, lazily evaluated, dynamically typed programming language. Distinguishing features of the Nix language are strings with "context", string interpolation, first-class file system paths, and "indented strings", which in combination allow concisely expressing dependencies between file system data when specifying the contents of new files.

Dependencies between files, as declared in the Nix language, are automatically tracked and persisted in the "Nix store". New files in the Nix store are created through "derivations". A derivation is a persistent data structure that specifies an executable, arguments and environment variables for its invocation (see ), and other files to be read from the Nix store. The executable is then run in a sandbox that prohibits access to anything but the explicitly specified input files and only allows writing to the designated output path. Nix preserves dependency information in output files by scanning for the distinctive hashes used for package directory names.

Automatic reference tracking ensures integrity of packages, even when they are transferred across machines. It also enables garbage collection of unused packages when no other package depends on them. At the cost of greater storage requirements, all upgrades in Nix are guaranteed to be both atomic and capable of efficient rollback. Unique directory names allow installing many packages with differing versions of shared libraries, and is claimed to eliminate so-called dependency hell. This also lets multiple users safely install software on the same system without administrator privileges. As a result, the Nix package management and deployment model advertises more reliable, reproducible, and portable packages.

Nix has full support for Linux, macOS, and WSL, and can safely be installed side-by-side with another package manager.

Nixpkgs
Nixpkgs is the package repository built upon the Nix package manager. According to Repology, as of March 2023 it contains more than 80,000 packages and has a higher number of up-to-date packages than any other package repository. Architectures supported by Nixpkgs are x86_64-linux, aarch64-linux, x86_64-darwin and aarch64-darwin. Packages for these architectures are built regularly, using a continuous integration service called Hydra, and the results of these builds are uploaded to a public binary cache. When Nix installs a package, it checks this cache and downloads the binary package to avoid building it locally. Nixpkgs is developed in a single Git repository on GitHub. Beside packages, it also contains the source code for NixOS.

Projects using Nix
NixOS is a Linux distribution that uses Nix for managing the entire system configuration, including the Linux kernel.

Nix is used for software packaging and distribution in CERN's LHCb experiment. Nix underlies the distributed software development platforms Replit and Google IDX.

Forks and alternative implementations
The original implementation of Nix by Eelco Dolstra, written in C++, is referred to as CppNix for disambiguity.

In 2021, a reimplementation by the name Tvix was announced, with the goals of modularity, full compatibility with Nixpkgs, and improved evaluator performance. As of 2024, Tvix has an evaluator and a store implementation, though the authors do not consider the project yet stable or ready for use in production. Tvix is written primarily in Rust.

In 2024, a team of volunteers released the first version of Lix, a fork of CppNix focused on correctness and compatibility that uses the Meson build automation system. The project intends to gradually rewrite parts of the code in Rust.