scratch

In Nix (and therefore NixOS/Hydra builds like the zlib example ), there are multiple independent layers that together provide strong assurance that the source code has not been tampered with and that the resulting binary faithfully comes from the declared sources. No single mechanism is perfect on its own, but the combination makes supply-chain tampering extremely difficult and — in many cases — detectable.

1. Integrity of the original source tarball (upstream source code)

The line you see:

unpackingsourcearchive/nix/store/n22iqgfwr3jr08f9hl4140y3sqmrzf2z-zlib-1.3.1.tar.gz

This path is a fixed-output derivation (FOD) — specifically a fetchurl or fetchzip call in nixpkgs. Every source tarball in nixpkgs is declared with a cryptographic hash:

# Example from nixpkgspkgs/development/libraries/zlib/default.nix (roughly)
src = fetchurl {
  url = "https://zlib.net/zlib-1.3.1.tar.gz";
  hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";  # or sha256-..., outputHashAlgo = "sha256";
};

→ This cryptographically pins the exact bytes of the source tarball.
Tampering with zlib.net (or a MITM on the download) would be detected the first time anyone anywhere builds it (including Hydra). The wrong hash would cause mass build failures → very visible.

2. Integrity & authenticity of the binary you download (cache.nixos.org)

Hydra builds packages → if successful, it signs the .nar (Nix archive) of the result with the official cache key and uploads it to cache.nixos.org.

Your Nix client verifies:

→ You know the binary came from Hydra (or someone with the private key — which is tightly controlled).
The signing key has been the same for many years; rotating it would be a massive event.

3. Reproducible builds as the strongest tamper-detection mechanism

Even if someone compromised Hydra / the signing key / upload pipeline:

→ Reproducibility turns the binary itself into a verifiable proof.
You (or anyone) can re-execute the exact same derivation locally or on another machine and compare the output hash. For zlib-1.3.1 this is usually very reproducible.

Summary of control mechanisms

LayerMechanismDetects what?Who can verify?
Upstream source tarballFixed-output hash in nixpkgsChanged / malicious tarball from URLAnyone building once
Binary from cacheNarinfo signature + trusted keyBinary not produced by Hydra/key holderEvery Nix user (automatic)
Binary fidelity to sourceReproducible builds + independent rebuildsTampering after source fetch (Hydra compromise, etc.)Anyone (takes CPU/time)
Entire build graphSandbox + no network in normal buildsSneaky fetches or local tampering during buildNix sandbox + reviewers

Practical ways you can personally gain more confidence