What if every Nix build were bit-reproducible?

Disclaimer: AI used for SVG generation

17 Likes

Does reproducibility promise of Rewind extend to CPU-feature-detecting builds reproduced on an underlying CPU with different feature support (let’s say same vendor but different generations)?

2 Likes

Yes, the CPUID is set to a fixed variant to make the hardware detection reproducible as well.

2 Likes

So there is an implicit «how far back CPUs are supported» not exposed explicitly (and needing to add the list of available functionality to change, probably)?

The guest’s CPU is a named model, --cpu, and the model is one of the inputs for the replay.
There is support for “v3” which x86-64-v3 is roughly Haswell and Zen 1 onward.
(We could add more like v4 with AVX-512)

The vendor is also an input (AMD vs Intel). The branch counter used for the clock behaves differently on AMD and Intel, so a run is tied to its vendor.

1 Like

Bootstrapping the Verified Software Stack | Theorem seems very relevant, both because reproducibility might be something interesting to formally prove and because it seems like a lot of their findings would apply to pretty much any “closure property” you are trying to apply.

Based on their analysis, if we could go reproducible for just a small set of key packages, the number of sweeping rebuilds in nixpkgs might drop severely.

5 Likes

cool, i’d heard talk of deterministic VMs but hadn’t actually seen any implementations in open-source.
it would sound like a good use-case of such a VM might be CI runs where in case of failures one could easily reproduce them.
i’d wonder if there have been any such CI setups out there then.

As long as your CI workers advertise KVM it works wonderfully.
There is also an online viewer Rewind VM viewer you can hyperlink to in the PR comment so that you can see the trace (more limited then running it locally)

1 Like

What about thread parallelism? How deterministic is the kernel scheduler in this VM?

I’ve done work on making rust builds determistic and sometimes what happens is the multithreaded lto generates a different result each time.

1 Like

That’s the whole motivation of projects like these.
The signals and thread schedule are deterministic.

The app even shows you the context switches and you can replay it and fork it at any point and generate new interleavings (to find bugs)

6 Likes

Sounds a lot like anitithesis’s program

3 Likes

ah, no networking just yet, huh?
maybe that sounds different from traditional CI jobs then. :sweat_smile:

1 Like

If we are talking about the nix-wrapped version, networking would be for fixed-output builds only anyway!

1 Like

If you need network access all sources are downloaded first like mentioned (FOD).
If your tests call out to the Internet… You have bigger fish to fry :sweat_smile:

2 Likes

Cool stuff!

I randomly found out that hermit (a user space deterministic runner) has something very similar as an example!

Oh interesting; it looks newly added.
Hermit is really cool so is the underlying library reverie.