Support a reproducible build via Nix#1
Support a reproducible build via Nix#1juliusikkala merged 1 commit intojuliusikkala:mainfrom samestep:nix
Conversation
|
Interesting! Before merging this, I'd like to fix the issues with this repo with newer compiler versions. I managed to narrow it down to the Slang compiler sometimes dropping the upper 32 bits from pointers (again). After I've got that fixed, I'd like to try this Nix build and potentially merge it if it's good. I know next to nothing about Nix, but I have a friend who has hyped it up a lot over the years (pinging @jansol for opinions on this PR). Is there an easy way to test the Nix build without installing NixOS? |
Just to clarify, by "newer compiler versions" do you mean newer than the latest v2025.12.1 release, which is the current Slang version used in Nixpkgs (and used by the flake in this PR)? If so, then I'll also point you to the discussion around NixOS/nixpkgs#424153 (comment) if you're interested; I did some delta debugging and determined that the specific change preventing the build in Nixpkgs from working on newer Slang commits is shader-slang/slang#7577. But of course, that's only an issue for using Nix.
Yes, absolutely! My personal desktop machine is NixOS, but the machine I'm typing this on is Ubuntu with Nix installed, and I also have Nix installed on my MacBook. So if you're already on Linux or macOS, you can very easily install Nix via the official installer; or you could alternatively use the Determinate Nix installer which comes with flakes enabled by default. I've used both and they're both easy and work fine; I don't know much about the differences between them, except that the Determinate one is supposed to be easier to uninstall (can confirm that it's very easy to uninstall Determinate; but I've also never tried uninstalling from the official one). Once you have Nix installed and flakes enabled, you can run the Nix build in this PR using the commands I wrote in If you're interested in using Nix beyond that, I'd personally recommend Home Manager and direnv (both of which I use in my personal Nix setup in case you want to take a look at a more fleshed-out example setup), but I won't bore you with more details here unless you're interested. |
jansol
left a comment
There was a problem hiding this comment.
Looks fine.
Worth nothing, SDL2 is actually aliased to sdl2-compat in nixpkgs, but it runs fine anyway.
| @@ -0,0 +1,50 @@ | |||
| { | |||
| inputs = { | |||
| nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | |||
There was a problem hiding this comment.
Since there's a lockfile with pinned versions I'd prefer using a stable nixpkgs channel (say, nixos-25.04) so we get to use cached dependency builds for a longer time without updating the lockfile.
There was a problem hiding this comment.
Oh interesting, I wasn't aware that the cache on a release channel like nixos-25.05 lasts longer than the cache for nixpkgs-unstable. Out of curiosity, is there some documentation about the Nixpkgs cache policy that I can read?
Unfortunately switching this from nixpkgs-unstable to nixos-25.05 doesn't currently work, because the Slang version there is still only v2025.8.1, which is too old to compile this demo.
There was a problem hiding this comment.
I don't know of an official policy, the closest thing I know is https://nixos.wiki/wiki/Nix_channels
Anyway the idea is that stable gets fewer updates in general so it's more likely that a given build hash is still relevant.
| inherit nativeBuildInputs buildInputs CPATH; | ||
| installPhase = '' | ||
| mkdir -p $out/bin | ||
| cp *.spv demo $out/bin/ |
There was a problem hiding this comment.
Having the .spv files in PATH if someone were to launch a (non-dev) shell with this or even install it globally... would get a bit awkward. I guess one option would be to wrap the demo to cd to a data dir in $out/usr/share before launching the actual binary? Alternatively changing the demo code so it explicitly looks there would be even nicer.
Anyway that's a fair bit of work for just a simple demo so that can also be done later if someone feels like it.
There was a problem hiding this comment.
Fair enough! This was just a minimal attempt with the goal of making no changes to the rest of the code. If I were making other changes then I would have also gotten rid of the pip install command that tries to run and times out in nix build, for instance.
There was a problem hiding this comment.
This demo also doesn't even work when running the built binary with cwd outside this repo clone, because it assumes that $PWD/data/Slang_LogoBug.png exists.
Looks like v2025.12.1 should be fine, it seems that none of the problematic stuff has hit a release yet.
Well, I just installed whatever |
|
Oh god, that's awful! Never had that experience, sorry to have (indirectly) caused it for you :( |
|
Well, I mostly just lost configuration files, so it's a setback of a few hours. No need to feel too bad over it. Everything that is "irreplaceable" has a backup. |
|
I installed NixOS in a VM and managed to build and run this successfully, so I'm merging this! |
Useful demo, thanks for making it!
This PR adds a Nix flake to allow building reproducibly in isolation.
No worries if you'd rather not merge this, I can still refer back to the PR regardless :)