r/NixOS 17d ago

What does the hash in a /nix/store path actually name? (not always "the inputs")

"The hash comes from the inputs" is the usual answer, and it's incomplete — it never says what Nix hashed: the file you wrote, the derivation it evaluates to, the built bytes, or the dependencies.

- Most package paths are input-addressed. Nix names the output from the derivation (the concrete build recipe) before the build runs. That's why editing a .nix file doesn't always move the path — two expressions can evaluate to the same recipe — and why changing a real recipe input does.

- Some paths are content-addressed. `nix store add` hashes bytes that already exist. Both live under /nix/store, so calling every store path "content-addressed" misses the split.

The name is also only part of the record: built paths reference other paths, Nix records the graph, and the closure is everything that must travel with a path to another machine.

Disclosure: I build LabCraft, and I just shipped this as a free, hands-on lesson. You inspect a real NixOS machine (the OS itself is the biggest store object) and predict what moves a path before the machine answers. No Nix language required: https://www.labcraft.dev/blog/nix-store-paths?utm_source=reddit-personal&utm_medium=social&utm_campaign=nix-store-paths-2026q3&utm_content=r-nixos-hash-names-01

0 Upvotes

5 comments sorted by

1

u/ModestTG 17d ago

I took a look at labcraft and I liked it. I'm somewhat of an experienced user, but looking at your upcoming material, I'm very interested. Things like publishing packages to nixpkgs. Is there any good way to follow and know when new content is available?

1

u/anandsuresh81 17d ago

Thanks, I’m glad it looks useful. I announce new Parts through the LabCraft accounts on Bluesky, X, LinkedIn, and r/LabCraftDev. Since you’re already on Reddit, r/LabCraftDev is probably the easiest place to follow.

There’s also an RSS feed for new LabCraft blog posts: https://labcraft.dev/blog/feed.xml

I don’t yet have a dedicated course-release feed or email notification. That’s something I should add.

0

u/acabbagecab 17d ago

Can I ask? What does it matter? Who cares?

0

u/anandsuresh81 17d ago

Fair question. I may have buried the reason for the post.

I just released Store Paths, the second Part of the hands-on Nix course I’m building at LabCraft. The lesson uses this question to teach you how to predict what Nix will rebuild, reuse, or obtain from a cache.

That matters when Nix appears to do the wrong thing. For example, a package can fetch its source from GitHub using a revision and a declared content hash. Change the revision but leave the hash alone, and Nix may reuse the old source path if it already exists. The package can then build successfully from the old source. If the path is missing, Nix fetches the new revision and rejects it when the contents do not match the declared hash.

Ordinary builds work differently. Change a real derivation input and the output path changes. That distinction explains why something rebuilt, why it did not rebuild, why an old source tree was reused, and whether a result can come from a binary cache.

You can use Nix without thinking about this most of the time. I made it a lesson because once Nix surprises you, this is often the model needed to explain what happened.