Incremental builds
Package builds that cut out unnecessary steps (and thus unnecessary build resources and time)
We recommend starting with the Nix quick start and consulting concept docs primarily for clarification. Feel free to click x to the right to disable this notification on all concept docs.
Incremental builds are build processes that don’t need to build the entire dependency tree of a software artifact every time because they use mechanisms like intelligent caching to avoid rebuilding artifacts that are already available. Nix is one of several available build systems that offers incremental builds.
How Nix provides incremental builds
Nix is one of several build systems that offers incremental builds for Nix packages by storing all build results in the Nix store.
Whenever Nix builds a package, it builds the entire closure, or dependency tree, of that package.
/nix/store/ 1. Nix store prefixsglc12hc6pc68w5ppn2k56n6jcpaci16 2. Hash part-git-2.27.3 3. Package name
The hash portion enables Nix to “know” what doesn’t need to be built.
If the package super-important-dependency
is necessary to build the package final-production-artifact
, Nix can inspect the derivation for super-important-dependency
and calculate a hash for that dependency and, thus, a Nix store path for it, something like this:
/nix/store/m7hsk1m4jkwy6pnns5gpn1kss22raan4-super-important-dependency
With that information in hand, Nix can then check to see if one of these places already has the artifact:
- The local Nix store
- One of your configured binary caches (if any)
Nix builds a given derivation only if it fails to discover a realised artifact in one of these places. This can make a huge difference when building large closures.
Consequences of incremental builds in Nix
Packages are in many ways the central organizing artifact in Nix. Nix development environments make packages available in a hermetically sealed way, NixOS is built with Nix packages as its basis, and so on. What that means is that incremental builds in Nix make pretty much everything associated with Nix much faster and less resource intensive.