-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System-agnostic builders #6697
Comments
In cases like this I write For system agnostic fetchers we have
github.com/aakropotkin/ak-nix under And for I've used this same pattern for I went wild with I guess my point is: we have most of these features, they're just scarcely used in Nixpkgs and there aren't good guides or best practices on a lot of them, which might be a task worth focusing on. |
The problem is specifically in small derivations like these requiring a builder with specific platform, even though they could produce the same result on any platform. We could create builtin builders for them or just one that would provide some scripting interface to do simple stuff, but it seems like inventing a new VM. |
Gotcha. I see; yeah that makes things tough. I was fooling around with the builtin Yeah I agree with you, having builtins for dead simple derivations like |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/tweag-nix-dev-update-33/20048/1 |
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/use-a-reference-to-a-derivation-in-tofile/20259/2 |
Just brainstorming here. How about we add a new hashing mode to support this use case. It achieves system-independence by using an alternate hashing scheme similar to fixed-output derivations (but not actually fixed output). As a possible design point, this has the huge benefit that it avoids having to make wasm part of the (virtual) Nix specification for which we commit to reproducibility long term. I'll acknowledge right away that it can be abused to poke a hole in evaluation purity if you really want to, but to me this seems favorable compared to committing to a wasm implementation. This hashing scheme:
Instead of
Fair, but I do think it's at least as acceptable as making wasm part of Nix. Maybe that's just me though, or maybe neither idea is acceptable. Or both? A conversation to have.
We wouldn't have to! |
Triaged in the Nix team meeting 2023-03-23:
|
This issue has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-03-23-nix-team-meeting-minutes-43/26758/1 |
Problem description
nixpkgs
provides a set of trivial builders that allow you do create derivations for simple tasks like:All those tasks are very simple, and yet they are implemented as shell scripts that run on a specific system that
nixpkgs
has been instantiated with. It means that every time I want to rebuild NixOS system configuration on my macOS laptop, I have to:This also means that I cannot create NixOS VM without having Linux builder somewhere (see discussion in NixOS/nixpkgs#108984), even though you don't really need to run any Linux-specific tasks to build it, unless you're doing something exotic with your packages.
We could achieve this by overriding these trivial builders depending on the system where
nixpkgs
is being evaluated somehow, but then we would be getting different closures on different systems, because we don't trust thatcat
,mkdir
,mv
orln
produce the same result on Linux as on macOS.Proposed solution
I want to be able to create derivations that can run on any system where Nix can run, so that these most trivial builders don't require Linux to run. Because we still need to make sure that these builders produce reproducible results, we can't run native binaries as no amount of sandboxing can provide enough guarantees for those.
I propose to use WASM virtual machine for this. With WASI having quite enough APIs, I think we could allow user to specify
wasm32-wasi
platform and provide a.wasm
binary as a builder (or maybe.wat
as well?). Then we can use wasmtime to run these builders, providing only minimal set of capabilities (pretty much only access to files and environment variables from the derivation). We could also embed wasmtime in Nix, but it feels like an unnecessary bloat. We should probably just allow user to configure the path to wasmtime binary, and then allowwasm32-wasi
to run on this host.Note that in this scenario builders themselves will most likely be built in platform-dependant derivations, but they will most likely be cached (and with CA we could reuse them for all platforms) and can be used on any system afterwards. You won't have to build
writeText.wasm
for NixOS configuration on macOS machine, but you will be able to use it there. Although for such simple cases we might want to emit WASM text format (.wat
) from Nix specification.Possible alternatives
The text was updated successfully, but these errors were encountered: