Differences between revisions 155 and 156
Revision 155 as of 2014-03-05 23:21:40
Size: 21224
Comment: no need to specifically mention ZFS in this context
Revision 156 as of 2014-04-10 01:07:59
Size: 21343
Comment: more consistency in tarfiles
Deletions are marked like this. Additions are marked like this.
Line 268: Line 268:

For more consistency in tarfiles, the owner and group can be set using `--owner=1000 --group=1000 --numeric-owner`.

It should be possible to reproduce, byte for byte, every build of every package in Debian.

This is an on-going project. To participate, we recommend you create an account on this wiki, watch this page and join the reproducible-builds@lists.alioth.debian.org mailing list.

Alioth project


  • Lunar

Why do we want reproducible builds?

  • Allow independent verifications that a binary matches what the source intended to produce.
  • Help Multi-Arch: same packages co-installation (as they need every matching file to be byte identical).

  • Be able to generate debug symbols for packages which do not have a “debug package”.
  • Ensure packages can be built from source. The archive could be made to only accept reproducible uploads: the maintainer would stop uploading .deb files but keep them referenced in the .changes. A buildd would then build the source. Only if the hash matches the upload gets accepted.
  • Allow file-level deduplication on Debian mirror sites, or maybe snapshots.d.o, of .deb files whose contents didn't really change between versions.
  • Allow .deb deltas to be smaller.


  • Current focus in on the toolchain: trying to get as few changes as possibles in key packages to make as many builds as possible reproducible.
  • On 2013-09-07, a first rebuild of the archive was done by David Suárez with a modified version of dpkg varying build path and time. This has already uncovered several archive-wide issues that we can address.

  • A build tool that would reproduce a build environment using packages from snapshot.debian.org is still missing.

Useful things you (yes, you!) can do

  • Sort out the results of the latest rebuild. See some notes on how to do so.

  • Find a way to remove prevent jar from writing timestamps.
  • Fing a way to prevent javadoc from writing timestamps.
  • Find a way to prevent Epydoc from writing timestamps and output links in filesystem order.
  • Understand why binaries produced by Mono are different.
  • Write a patch for dpkg-buildpackage to export GZIP=-n (or maybe not, maintainers were quite unhappy with dpkg-buildflags exporting CFLAGS)

  • Write a patch for dh-python to have a ?stable order for Depends

  • Write a script to rebuild a package from a .changes file. It should only be about adding the version of snapshot.debian.org matching the time of the build to the pbuilder/sbuild chroot before starting the build process.
  • Write a script to rebuild a package from a list of binary packages and their respective versions. See below for some preliminary work by Lunar that has already been done. One way to do that is to download the deb files from snapshot.debian.org and then put them into a chroot with pbuilder, and then use pbuilder to do a build of the desired Debian package.
  • Research about other distributions: NixOS, SUSE (see build-compare), then write about it on your blog and link to it on this wiki page.

If you want to help with this, feel free to ping the mailing list or edit this wiki page.

Reported bugs

All bugs relevant to the reproducible builds project should use usertags with user reproducible-builds@lists.alioth.debian.org.

Current usertags in use:

affects a tool used by other package build systems
affects the whole Debian infrastructure or policies
time of build in recorded during the build process
build output varies with readdir() order
path of sources is recorded during the build process

Archive wide rebuilds

  • 2013-09-07 by David Suárez. 24% of 5240 source packages reproducible. Variations: time, build path.

  • 2014-01-26 by David Suárez. 67% of 6887 source packages reproducible. Variations: time, build path.

Reproducing builds

There are two sides to the problem: first we need to record the initial build environment, and then we need a way to set up the same environment.

Recording the environment

The right place to record the build environment is the .changes file. Rationale: it lists the checksums of the build products and is signed by either the maintainer or the buildd operator.

To add a field to the .changes file, we need to call dpkg-buildpackage using something like:

dpkg-buildpackage --changes-option="-DBuild-Environment=$(
COLUMNS=999 | dpkg -l | awk '
            /^ii/ { ORS=", "; print $2 " (= " $3 ")" }' |
        sed -e 's/, $//'

The idea is not new, see 138409. The above could eventually be integrated in dpkg proper if our experiments turn successful.

The dh-buildinfo script already captures the build environment quite nicely. It currently encode the information about the build environment in a buildinfo_$ARCH.gz in the doc directory. For our goal, we believe that such information should not be recorded in the binary package itself.

Lunar wrote on 2013-09-08 to Yann Dirson to ask his opinion. Yann agrees that what buildinfo produces should not be in the .deb file but rather a separate file. He's advocating for having an additional file as part as an upload rather than adding fields in .changes. He also agree that what dh-buildinfo produces should actually be done at the dpkg level.

In any cases, we should simply re-use or adapt dh-buildinfo, and turn it into dpkg-buildinfo. Either it should produce an extra file that is bundled together with a .changes or add some extra fields directly in .changes.

(See 719854 for the first attempt which tried using XC- field in debian/control.)

Reproduce the build environment


  • We need a script that would take a list of binary packages and their respective version, installs them in a chroot and starts the build. Maybe based on pbuilder?

Ruby script that generates URL to .deb on snapshot.debian.org from a list of binary packages and their respective version: http://people.debian.org/~paulproteus/lunar-verify-script.rb

Here's another potential piece of the puzzle. The following script will convert a RFC822 date (as found in a .changes) to the URL of the last known archive state recorded by snapshot.debian.org. This might be useful to debootstrap the proper chroot before installing packages…

require 'date'
require 'uri'
require 'net/http'
require 'nokogiri'

changes_date = 'Mon, 30 Jan 2012 12:52:28 +0100'

build_date = DateTime.rfc822(changes_date)
url = "http://snapshot.debian.org/archive/debian/?year=#{build_date.year}&month=#{build_date.month}"
response = Net::HTTP.get_response(URI.parse(url))

run = nil
doc = Nokogiri::HTML(response.body)
doc.css('p a').each do |link|
  date = DateTime.parse(link.content)
  break if date >= build_date
  run = link['href']
puts "http://snapshot.debian.org/archive/debian/#{run}"

Note : it would probably be a lot better of adding a new query to the machine interface of snapshot.d.o instead of parsing HTML.

Different problems, and their solutions

Build systems tend to capture information about the environment that makes them produce different results accross different systems, despite having the same architecture and software installed.

Ideally, such variations should be fixed in the build system itself, but it might sometimes not be possible.


  • You might think ELF binaries (e.g. /usr/bin/hello in the hello package) have embedded timestamps. Luckily, they don't!

Files in data.tar.gz contains build paths

These should really be patched out in one way or another. This is not useful information and can actually hide real bugs.

DWARF data

The build path is embedded in DWARF sections of ELF files. Like Fedora, we should replace actual build paths to a canonical location in /usr/src.

One option is to do so by adding two CFLAGS for GCC:

  1. -fdebug-prefix-map to replace the build path by a predetermined path.

  2. -gno-record-gcc-switches to prevent the previous option to be recorded in the debug file (as it changes with the build path).

Both are documented in GCC's manual.

We can pass both options using the dpkg-buildflags mechanism. Lunar's branch has a patch for that.

Problems with that approach:

  • ('minor') Some build systems do not build the objects in the same directory as the source. In that case, we get a stable name in DW_AT_comp_dir, but it does not match the source of an unpacked package in /usr/src.

  • ('major') Some build systems record the value of CFLAGS and reuse it to build extensions. This is what Ruby MRI does. This means that extensions will not get a stable Build Id without further work.

Another option is to use debugedit. Currently, it needs to be used together with -fno-merge-debug-strings because the hashtable used when strings are merged will output strings in a different order depending on the initial build path.

Files in data.tar.gz depends on readdir order

The build system needs to be patched to sort directory listings.


It looks like python-epydoc will produce links in an order that depends on the readdir order. This needs to be investigated.

Files in data.tar.gz varies with the locale

Builds should be made with LC_ALL=C.UTF-8.

It's quite unpractical to force such value in debian/rules and there is actually no reason this should not be the default.


  • We could make dpkg-buildpackage exports this variable; but we would need to change the policy to make dpkg-buildpackage be the canonical solution to build package.

Files in data.tar.gz contains hostname, uname output, username


  • We could write a LD_PRELOAD library that could answers consistent results for several system calls on the same model as libfaketime. Bdale suggested we call it liblietome.

Files in data.tar.gz contains timestamps

  • Recommended solution:
    • Use the timestamp of the of the last debian/changelog entry as reference.
    • touch all files to the reference timestamp before building the binary packages.
    • gzip -n when gzipping anything
    • get rid of non-determinisim (yup...)
    • Alternate solutions:
      • (or) libfaketime (probably breaks some things) (sudo apt-get install faketime)

For the worse cases, we could record the calls to gettimeofday() on the first build and have something like libfaketime replay them on rebuilds.

.a files

.a files are ar archive. GNU ar has a deterministic mode which will use zero for UIDs, GIDs, timestamps, and use consistent file modes for all files.

binutils can be built with --enable-deterministic-archives to make it the default.

jar files

See ReproducibleBuilds/TimestampInJarFiles.


python-epydoc will add timestamps to the HTML file it produces. This needs to be fixed.


javadoc will add timestamps to the HTML file it produces. This needs to be fixed.

PHP PEAR registry files

See ReproducibleBuilds/TimestampInPhpRegistryFiles.

Random variation

dh_ocaml md5sums files

See ReproducibleBuilds/RandomOrderInOcamlMd5sums.

Members of control.tar have varying mtime

We can fix this by giving tar the --mtime= option with the date of the last debian/changelog entry or a similar fixed point in time. Change to be done in dpkg-deb/build.c:do_build() around line 462.

Lunar's branch use a single timestamp for all mtimes of tar members and allow to preset it during rebuilds, see below. Except this uncovered a new issue coming straight from tar itself.

For more consistency in tarfiles, the owner and group can be set using --owner=1000 --group=1000 --numeric-owner.

{data,control}.tar.{gz,xz,bz2} does not have timestamps

  • dpkg 1.17.1 does not store a timestamp for the .gz versions of these files.
  • *.xz and *.bz2 seem to provide no ability to store a timestamp.

{data,control}.tar.{gz,xz,bz2} will store files in readdir order

This is dependent on an accident of filesystem layout at build time, so it would sometimes not be reproducible.

We should probably fix this in dpkg by sorting the contents of the tar files.

Changes are discussed in 719845. Test case patch for pkg-tests. Patches that fork `sort` to get a stable order for files in control and data archives.

.deb ar-archive header contains a timestamp

.deb are ar-archives. The header currently contains the “current time”. It is written by dpkg at line line 103 of lib/dpkg/ar.c.

Guillem said he would rather keep this.

Lunar's branch use a single timestamp for all ar headers and allow to preset it during rebuilds, see below.


dh-buildinfo used to encode a timestamp in the gzip file it produces, and also did not output the package list in the same order on every run. A patch had been submitted in 722186 and the packages should be good with version 0.10.

building the kernel

See dedicated page: SameKernel.

Custom build environment

We maintain a set of modifications to the toolchain to perform our experiments.


The pu/reproducible_builds debhelper branch in the reproducible repository makes dh_strip call debugedit to adjust the source path embedded in debug objects.


The pu/reproducible_builds dpkg branch in the reproducible repository makes:

  1. file order deterministic in control and data part of the .deb,
  2. uses a single timestamp for .deb mtimes and allows to preset the timestamp,
  3. adjust dpkg-buildflags to pass -fno-merge-debug-strings in CFLAGS and CXXFLAGS


binutils has been rebuilt with the --enable-deterministic-archives flag passed to ./configure.

Usage example

$ apt-get source hello
$ cd hello-2.8
$ dpkg-buildpackage
$ cp ../hello_2.8-4_amd64.deb ../hello_2.8-4_amd64.deb.orig
$ DEB_BUILD_TIMESTAMP=$(date +%s -d"$(sed -n -e 's/^Date: //p' ../hello_2.8-4_amd64.changes)") dpkg-buildpackage
$ sha256sum ../hello_2.8-4_amd64.deb ../hello_2.8-4_amd64.deb.orig
1e944abfceac7e593f6706da971e0444e5cee9aab680de5292d52661940ee9c4  ../hello_2.8-4_amd64.deb
1e944abfceac7e593f6706da971e0444e5cee9aab680de5292d52661940ee9c4  ../hello_2.8-4_amd64.deb.orig


bash script to compare two package builds

Usage: ./diffp r1/hello_2.8-4_amd64.changes r2/hello_2.8-4_amd64

The script is available in the misc.git repository.

How to build a deb using faketime

sudo apt-get install faketime
echo > /tmp/fakeroot-faketime << EOF
faketime "2013-08-15T11:02:00" fakeroot "$@"
chmod a+x /tmp/fakeroot-faketime
dpkg-buildpackage -r/tmp/fakeroot-faketime

Note that this retians *one* timestamp, which is the timestamp of the 'ar' container of the *.deb. To erase that, somehow regenerate the package within the fakeroot-faketime environment by using dpkg-deb to unpack it, then dpkg-deb to repack it.

Note also that this is a total hack and not something I (AsheeshLaroia) think it makes sense to do on the Debian build daemons. In particular, some programs (e.g., gpg) hang forever when time does not advance.

Upstream changes may solve the problems we face with faketime 0.9.1. (rbalint) Faketime upstream has been improved to advance time linearly at a preset pace per each time() call and save/load timstamps. We could try rebuilding many packages saving timestamps in the first build and replaying them in successive builds. For example gnupg 1.4.14-1 builds fine:

NO_FAKE_STAT=1  ~/projects/libfaketime.git/src/faketime -f '+0 i0.01' dpkg-buildpackage -rfakeroot -us -uc




This section lists URLs, people, and dates for when other people have publicly expressed interest, or shared information about, the project.

  • CARE monitors the execution of the specified command to create an archive that contains all the material required to re-execute it in the same context.