Introduction
Nix is a purely functional package manager where each package is built in isolation from a precise description of its dependencies. This model guarantees reproducible builds, atomic upgrades and rollbacks, and the ability to run multiple versions of any package side by side without conflicts.
What Nix Does
- Builds and installs packages in isolation under /nix/store with content-addressed paths
- Provides atomic upgrades and instant rollbacks for system and user profiles
- Manages per-project development environments via nix-shell or nix develop
- Powers NixOS, a Linux distribution where the entire system is declared in a single configuration file
- Caches and shares build results through binary substitution from remote caches
Architecture Overview
Every Nix package is defined by a derivation — a pure function from inputs (source, dependencies, build script) to a store path. The Nix store (/nix/store) holds all build outputs, each identified by a hash of its inputs. A build daemon executes derivations in sandboxed environments. Profiles are symlink trees pointing into the store, making switches atomic.
Self-Hosting & Configuration
- Install with the official installer on any Linux distribution or macOS
- Configure in /etc/nix/nix.conf or ~/.config/nix/nix.conf for substituters and features
- Enable Flakes with
experimental-features = nix-command flakesfor the modern CLI - Use binary caches (cache.nixos.org or custom) to avoid rebuilding from source
- Declare project dependencies in a flake.nix for portable reproducible environments
Key Features
- Content-addressed store ensures bit-for-bit reproducible builds
- Atomic upgrades with instant rollback to any previous generation
- Multiple package versions coexist without conflicts or containers
- Flakes provide hermetic, lockfile-based project definitions
- Cross-compilation support for dozens of target platforms
Comparison with Similar Tools
- Homebrew — simpler to start; no reproducibility guarantees or rollback support
- apt/dnf — distribution-native; global state makes version conflicts common
- Guix — similar functional model using Guile Scheme instead of the Nix language
- Docker — provides isolation via containers; heavier weight than Nix shells for development
FAQ
Q: Do I need NixOS to use Nix? A: No. Nix runs as a package manager on any Linux distribution and on macOS.
Q: What are Flakes? A: Flakes are a newer interface for defining Nix projects with a lockfile for pinned dependencies, making builds fully reproducible across machines.
Q: Does Nix work on macOS? A: Yes. Nix supports macOS with a dedicated installer and the nix-darwin module for system configuration.
Q: How much disk space does the Nix store use?
A: It varies. Run nix-collect-garbage -d to remove unused store paths and reclaim space.