The Ur Project

Documenting the craft of stacking things so they remain stacked. For a very long time.

Verifying reproducible builds

Every package in Sandcastle comes with a signed record of how it was built: the sources, the recipe, and every package that was in the buildroot. pkg provenance rebuild reads that record, builds the package again on your machine, offline, and compares the result byte for byte with what was published.

You don't need to install anything first, and you don't need the package installed either. pkg fetches the record and its inputs from the repositories you already have configured.

The rebuild runs in a sandbox, which needs user namespaces. It also needs disk space: the inputs and the build tree go under ~/.cache/pkg/rebuild and are removed when it's done. For a big package, point it somewhere with room using --work.

Packages in Sandcastle-Common

Every package in Sandcastle-Common can be reproduced directly:

$ pkg provenance rebuild jq

The build log scrolls by, and then the report. Its first line says rebuild REPRODUCED when it worked, and every output of the package is listed below it. Every one of them has to say ok. Anything else is a non-zero exit, and the outputs that differ are listed with what changed.

Packages in Sandcastle-Base

Packages in Sandcastle-Base were built on a Buildroot-N.R repository: the compilers and tools that every other package is built with. Your system doesn't have that repository configured, and it shouldn't, because nothing on it should ever be installed from there. So the rebuild needs to be told where to find it.

First, find out which buildroot the package was built on. Without the buildroot repository, pkg provenance verify fails, and every input it can't find is listed with the name of the repository it should come from:

$ pkg provenance verify gzip
error: provenance: reproduction-INCOMPLETE: 192 problem(s) across 112 input(s):
  - Buildroot-6.4:autoconf/bin payload MISSING (...)
  - Buildroot-6.4:autoconf/bin pkg-meta MISSING (...)
  - Buildroot-6.4:autoconf/data payload MISSING (...)
  ... 189 more

That's what you'll see for every package in Sandcastle-Base until you add its buildroot. Here it's Buildroot-6.4.

The buildroot changes every few weeks, when a new one is built and the floor moves up. Since October 2026, Sandcastle-Base builds on Buildroot-7.4, so newer packages need pkg-repo-buildroot-7-4, while packages built before then still need pkg-repo-buildroot-6-4. Always go by the name in the error.

Then install the package that describes that repository. They're named pkg-repo-buildroot-N-R, with a - instead of a .. For Buildroot-6.4, that's pkg-repo-buildroot-6-4:

$ sudo pkg install pkg-repo-buildroot-6-4

This puts two files on your system:

  • /etc/pkg/repo-extra.d/buildroot-6.4.toml, the repository definition.
  • /etc/pkg/buildroot-6.4.root.json, the trust anchor it's checked against.

The definition sits in repo-extra.d, not in repos.d, so pkg never loads it by itself. It's also marked provenance_only = true, so even if it ends up in repos.d, nothing gets installed from it. The only way to use it is to name it with --with-extra-repo:

$ pkg provenance rebuild gzip \
    --with-extra-repo /etc/pkg/repo-extra.d/buildroot-6.4.toml

After the build log, the end of a clean run looks like this:

rebuild REPRODUCED gzip-1.15 rel 3  (full-manifest)
  record         0efe8cd9ec8e1fe23b686c289cdb041e43250736539fc7ef3b854e6a6c1dd470
  signed_by      36558dbbdc9ca7cf7b98b0a25cf96fa97725460cead87ac91b0672c24e5a7c85
  buildroot      Buildroot-6.4
  outputs        6 matched, 0 diverged, 0 missing, 0 extra, 0 unverified (of 6)
    ok         gzip/bin 1.15-3.x86_64
    ok         gzip/data 1.15-3.noarch
    ok         gzip/debug 1.15-3.x86_64
    ok         gzip/debugsrc 1.15-3.noarch
    ok         gzip/info 1.15-3.noarch
    ok         gzip/man 1.15-3.noarch

Every one of the six outputs was built again and came out byte for byte the same as the published one.

--with-extra-repo adds that repository for this one command only. The inputs are fetched from it as needed, and each one is still checked against the hash in the signed record, so the download itself doesn't have to be trusted.

The same flag works for pkg provenance verify, which checks that every input is still there without rebuilding anything. With it, the reproduction-INCOMPLETE error from above goes away.

More

pkg-provenance(1) describes all three pkg provenance commands, every option, the JSON output, and a few scripts, like a reproducibility sweep over everything installed. pkg-repos.d(5) describes the repository definition format and provenance_only.