Nix
Glossary
Section titled “Glossary”Evaluation
The initial phase of a Nix operation where Nix parses .nix expressions and resolves language constructs (functions, variables, and attributes) into a concrete set of build instructions. Evaluation happens purely in memory and does not compile software or write final outputs to disk.
Instantiation
The step immediately following evaluation—and often grouped with it—where Nix writes the evaluated build instructions to /nix/store as a .drv (store derivation) file. Can be triggered manually using nix-instantiate.
Derivation (.drv)
A low-level, self-contained build recipe stored in /nix/store. A derivation specifies all inputs, dependencies, environment variables, and the builder script required to produce a package output.
Realisation
The process of turning a derivation (.drv) into its actual materialized output path in /nix/store. Nix accomplishes this either by downloading a pre-built binary from a cache (substitution) or by executing the derivation’s builder script inside an isolated sandbox. Can be triggered directly via nix-store --realise.
Substitution
An optimization during realisation where Nix fetches pre-built store paths from a remote binary cache (such as cache.nixos.org) instead of compiling the derivation locally from source.
Building
The colloquial umbrella term for running the entire pipeline—evaluation, instantiation, and realisation—from start to finish using commands like nix build or nix-build.
Activation
The final deployment step that makes a realised configuration live on a running system or user environment. Because /nix/store is isolated, activation runs an activation script to bridge the store with the rest of the OS by:
- Updating symlinks (such as
/run/current-systemor~/.nix-profile) to point to new store paths. - Populating configuration files into standard locations (like
/etcor~/.config). - Restarting or reloading background services (systemd units or launchd services).
- Updating bootloader entries on NixOS so new generations are bootable.
Generation An immutable, numbered snapshot of a NixOS system or user profile created upon activation. Generations allow you to safely switch between configurations or roll back to a previous working state if an update breaks something.
- Evaluation: Turns Nix expressions (.nix) into build instructions (derivations) in memory.
- Instantiation: Writes those derivations into /nix/store as .drv files.
- Realisation: Turns stored .drv files into materialized outputs (packages, config files, or system trees) in /nix/store.
- Activation: Makes a realised profile or system live in the OS by updating symlinks, populating config files, and restarting services.
- Nix package is unique across: source, dependencies, build steps, architecture, platform
- Nix can determine the derivation and the final output path ahead of time (needed for caching)
- derivation is platform-specific way to build a package
- output of derivation depends only on the inputs and the build script, and each package has a unique hash
- NixOS boot process:
- Bootloader loads kernel and
initrd initrdmounts partitionsinitrdruns/run/current-system/activate- if first time, it populates POSIX directories (
/bin,/etc,/run,/usr,/var)
- Bootloader loads kernel and
- Nix binary cache
- NAR file is a serialized file format for packages used by the Nix package manager (v/s tar files) because they don’t contain any non-deterministic information
.narinfofiles contain metadata info about each package, such as dependencies
- Use of
mkIfwithin module system requires all options to be valid
Useful commands
Section titled “Useful commands”-
Terminal window sudo -i nix-store --gc --print-roots | egrep -v '^(/nix/var|/run/current-system|/run/booted-system|/proc|{memory|{censored)' -
Terminal window nix-store --query --roots /nix/store/... -
Find references, referrer, closures
nix-store -q --references $(which hello)nix-store -q --referrers $(which hello)nix-store -qR $(which hello)nix-store -q --tree $(which hello)Flakes
Section titled “Flakes”let pkgs = import nixpkgs { system = "x86_64-linux"; config.allowUnfree = true; };- Make
nixpkgsrefer to the same one in your flake enablednixos
nix.registry.nixpkgs.flake = inputs.nixpkgs;- IFD uses a nix expression to generate another nix expression as the output of its realization. The generated nix expression is then used to generate desired output.
- FOD(Fixed-Output Derivation) are derivation for which has of the output is already known, and therefore network access is allowed during derivation. This is typically used for bundling pre-fetched dependencies, when building an application that typically fetches dependencies during the build process, such as building a Scala mill project