There’s a rust crate (mediasoup_sys) I want to use on NixOS, but it fails to build because it tries to call pip install in it’s Makefile in an attempt not to depend on system-wide dependencies.
Obviously, this seems contrary to the nix philosophy where dependencies are provided to a package, and builds are sandboxed to prevent network access.
I’m just wondering if anyone has thoughts, ideas, or examples about how to write a nix derivation for such a package. Replies related to or unrelated to rust crates are welcome.
Well I feel pretty silly to report that when building using cargo directly (not via nix build), simply providing the pip binary via nix is sufficient to build successfully. This also works when mediasoup_sys is a dependency of the current cargo project (rather than the project itself).
However, I think that if I were to actually want to distribute my package (which depends on mediasoup_sys) via nix, I would have to figure out something more clever because the pip commands would fail inside of a nix build.
Thanks @FRidh, that’s the direction I was thinking of as well.
I’m still not 100% sure how to go about using the patched dependency in my rust package, though.
Cargo.toml has a patches section for dependencies, although it doesn’t accept patch files, only replacing the whole source. Do I just need to fork mediasoup_sys apply the patch in a new branch, and refer to my fork? That seems excessive.
I noticed that buildRustPackage also has a cargoPatches option that might be helpful.
I’ll continue browsing through nixpkgs for other inspiration, just wanted to post a quick update.
What FRidh certainly means is to keep your src attribute as it is and patch the source during the nix compilation. You can either write a patchPhase that calls for instance sed to remove the unwanted lines in the makefile, or directly apply patch files using the patches = [ . /mypatch.patch ] ( cargoPatches is typically used instead to update the cargo lock file before fetching cargo’s library as patchPhase/patches is applied once the dependencies are already fetched, and at build time both patches and cargoPatches are applied). To generate those patch files you can use the typical tools to generate patch files including git diff as explained here Documentation for how to create patch files · Issue #31684 · NixOS/nixpkgs · GitHub (there is also a video tutorial somewhere).