Demystifying Nix: fixed-output derivations
Published: 2026-11-06
Over the course of this series attempting to demystify Nix concepts, I’ve focused primarily on what the Nix documentation calls `input-addressed` derivations. Declaring build sources and build inputs, both fall into that domain. And, frankly, just that knowledge is powerful enough to confidently build software with Nix.
But there’s one key concept I learned the hard way, after dealing with countless build failures, that I believe is essential: fixed-output derivations.
The Nix build process is hermetically sealed; nothing can get in and nothing can get out. While this setup is brilliant for ensuring reproducibility, this seal also completely precludes network access. So how are we supposed to build software that relies on fetching dependencies over the network, like a Node or Cargo project?
Fixed-output derivations solve this core issue with Nix’s sandboxing strategy by creating a separate and more relaxed environment to make those network requests. This “fetching” process comes with its own set of strict rules to ensure reproducibility. In this installment of Demystifying Nix, we’ll cover what those rules are, and explore the options you have to properly manage them.
The anatomy of the fixed-output derivation
So, what the heck even is a fixed-output derivation, and what makes it so different from the input-addressed derivation?
From a higher level of abstraction, fixed-output derivations flip the script in regards to how reproducibility is guaranteed. Input-addressed derivations follow a standard principle of deterministic functional programming: the same inputs will always produce the same outputs. Fixed-output derivations, on the other hand, rely on comparing outputs to create their guarantee. These derivations, much like a unit test, assert that their computed output must match an expected output or else the build fails.
To achieve this behavior, fixed-output derivations leverage Nix’s built-in hashing system to compare outputs. Each `/nix/store` path is identified with a Nix Archive (NAR) hash. This hash id now becomes the fixed-output derivation’s guarantee of reproducibility.
We can see this in action using this buildGoModule example:
{pkgs, ...}: let
goBuild = pkgs.buildGoModule {
pname = "my-go-package";
version = "0.1.0";
src = ./.;
# buildGoModule vendors your go dependencies as a fixed-output derivation.
# This hash now becomes the guarantee of reproducability for Nix.
vendorHash = "sha256-f91JruZ2lv5OLHPU1xGf/bcchXfsKDV8kzJeHoIGCyU=";
};
in {...}
This is great! But how do we get get that hash value in the first place? To compute the NAR hash, we unfortunately have to attempt a build first, retrieving the hash from the failed build log:
{pkgs, ...}: let
goBuild = pkgs.buildGoModule {
pname = "my-go-package";
version = "0.1.0";
src = ./.;
# empty hash to coerce a build faiure
vendorHash = "";
};
in {...}
Running nix build . should then produce an error:
hash mismatch in fixed-output derivation: specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA= got: sha256-f91JruZ2lv5OLHPU1xGf/bcchXfsKDV8kzJeHoIGCyU=
While this behavior ensures reproducibility, the chicken-and-egg scenario it introduces creates a suite of headaches and is challenging to integrate with modern software infrastructure. The reliance on an initial build failure, combined with the fact that a change in the fixed-derivation output mandates a full NAR hash recalculation, can completely break CI pipelines and automated dependency updates. This is a core tradeoff, and admittedly, it can feel like a massive investment of time and effort. While understandably unappealing, this burden is one we can manage, and a few tools exist to ease this process.
Managing the mess
The Nix community has a great collection of libraries that not only allow you to manage your build inputs but also avoid defining fixed-output derivations for your project. Many of these libraries are able to do this is through abstracting NAR hash handling in ways specific to that language. Additionally, to give you the same level of control as the standard library, it’s a common pattern within these libraries to pass any unhandled options to an underlying stdenv.mkDerivation call. Here are some fun libraries that I would recommend:
- crane: Rust library that comes with the added benefit of incremental builds. Not only are NAR hashes unnecessary to manually define, but the vendored dependency derivation is only affected by changes to
Cargo.tomlandCargo.lock. - go-overlay: Go toolchain overlay that automates NAR hash calculation and relaxes the matching requirements. It’s configurable to allow the developer to detect NAR hash drifts and control whether it should cause CI workflows to fail. While it doesn’t remove NAR hash management from the build, it prevents any system that doesn’t expect it from failing.
Finally, as a lower-level solution, nixpkgs provides nix-update, a CLI specifically designed to automate NAR hash updates. With the right setup, nix-update CI workflows can be established to function similarly to go-overlay.
Final thoughts
Given that tools exist to circumvent fixed-output derivation management, it can be tempting to write them off or ignore their crucial role in the broader ecosystem, which I have done in the past.
While awkward to deal with, fixed-output derivations are still an important pillar to how reproducibility is guaranteed within a Nix build. They are also a core mechanism that allows Nix to compile software projects utilizing package managers. I’d also argue that understanding fixed-output derivations gives you insight into how those abstracting tools truly work.