Reproducible Package Builds: A Practical Start
A build is reproducible when anyone, starting from the same source and the same toolchain, gets the same artefact bit for bit. For a package maintainer that sounds academic until someone asks "how do I know this tarball came from that commit?" Provenance attestations answer the question with a signature; reproducibility lets a third party answer it independently, by rebuilding and comparing hashes.
Where builds pick up differences
Packaging tools are mostly deterministic already. The drift almost always comes from the environment leaking into the archive:
| Source of drift | What happens | Usual fix |
|---|---|---|
| Timestamps | File modification times or "built at" strings are stored in the archive. | Set SOURCE_DATE_EPOCH; avoid embedding build dates in code. |
| File ordering | Directory listing order differs between filesystems, so archive members come out in a different order. | Tools that sort entries; check yours does. |
| Absolute paths | Your home directory ends up in source maps, debug info or compiled bytecode. | Path-trimming flags such as Go's -trimpath; relative source map roots. |
| Unpinned build tools | A newer bundler or build backend emits slightly different output. | Pin build dependencies; record tool versions in the release log. |
| Locale and umask | Sorting, text encoding or file permissions differ between machines. | Build in a container or CI image with fixed settings. |
SOURCE_DATE_EPOCH
The Reproducible Builds project defined SOURCE_DATE_EPOCH, an environment variable holding a Unix timestamp that build tools should use instead of the current time. Many Python build backends and archive tools honour it. Setting it to the time of the commit being built is the usual convention:
export SOURCE_DATE_EPOCH="$(git log -1 --format=%ct)"
python -m build
sha256sum dist/*
npm already normalises the timestamps inside the tarballs it packs, so for pure JavaScript packages the remaining risks are mostly in your own build step: bundler output, generated files, and anything that writes a date or a random identifier.
Checking your own build
- Build the artefact twice, ideally in two fresh directories with different paths, and compare hashes.
- If they differ, unpack both and diff the contents.
diffoscope, a tool from the Reproducible Builds project, recursively compares archives and shows exactly which bytes moved. - Fix one cause at a time and repeat until the hashes match.
- Once they do, add a CI job that builds twice and fails on a mismatch, so the property does not quietly regress.
Go is a helpful model here: with -trimpath and a pinned toolchain version, Go binaries are reproducible by default, and the Go project has worked to make its own toolchain releases reproducible too.
Where it fits with provenance
Reproducibility and attestations complement each other. A signed provenance statement, as described in the provenance deep dive, says "this CI run built this artefact". A reproducible build means that claim can be verified without trusting the CI system at all: rebuild from the referenced commit and the hash either matches or it does not. Frameworks such as SLSA treat reproducibility as a strong, optional property rather than a baseline requirement, which is a fair reflection of how much work it can take for compiled code.
A realistic goal
You do not need bit-for-bit reproducibility on every platform on day one. A reasonable first target for a small library is: the source distribution or tarball is reproducible from a tagged commit, and the build environment is recorded in the release notes. That alone makes the release pipeline easier to audit.