Nix 101 Course / Section 4: How Nix actually builds: sandbox → derivation → hash → store
Premium

4.6 Why Nix rebuilds your unchanged package

Lesson 29 of 68 · 5:07

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

You run nix build on mini-hello twice in a row. Nothing changed, no file touched, and it compiles again anyway. This lesson finds the mistake in our own derivation that defeats the Nix cache, a mistake that shows up in real companies as whole teams rebuilding three hour product builds for no reason.

In this video

  • Watching an unchanged package rebuild on every nix build, plus the small warning that hinted at it all along
  • The source closure: what actually goes into the sandbox, and how one careless reference drags in files that have no business being there
  • The self feeding loop hiding in plain sight in the project folder
  • A small layout change that makes every following build come straight from the cache
  • Why source filtering matters far more at scale than in this tiny example

After this lesson

You can spot a derivation that pins too much source and fix it before it burns hours of build time. This keeps the caching that you came to Nix for actually working.

Builds on: Exercise: package mini-hello with builtins.derivation (4.4)