Realisation

The process whereby Nix turns the build instruction in a derivation into a build output in the Nix store

Concepts / Realisation

Realisation is the process whereby a Nix derivation is transformed into a package. While a derivation is essentially a plan for a package, realisation is the build process turns that plan into an actual output directory full of content.

.drv files

When you run nix build to build a package, the Nix CLI first looks at the derivation function for the function and transforms it into an intermediate .drv file, which is essentially a formal representation of the derivation function. All .drv files are stored in the Nix store with a hashed path, such as /nix/store/m2nb4d0pfydr8bq5ww1yqbrkvvf18zbl-perl-5.36.0.drv, which ensures that any change in a derivation function results in a new .drv file with a new path. The CLI then uses the .drv file as the blueprint for the actual build process, which always builds the package's entire dependency tree.

The build process

Once Nix has built a .drv file for the derivation, it uses the encoded instructions in the file to actually build the package in a sandboxed environment, which essentially means that realisation doesn't rely on or affect any global state on your machine, such as configuration files in /etc. Everything required for the build process is drawn from:

  1. The build instructions in the derivation. For example, commands like cat, touch, mkdir, and mv.
  2. Artifacts from the Nix store. If you write a derivation with Git as a build input, for example, the realisation process builds Git and stores the resulting package in the Nix store (if it isn't already built and stored there) and uses that package when the git command is invoked in the build logic, rather than a "global" Git at a path like /usr/bin/git.

Was this page helpful?