Using cargo-binstall in buildRustPackage

Has anyone tried speeding up rust package builds using cargo-binstall. Scanning the manual, I did not see any hints for its use. And I don’t see anyone using it in nixpkgs, yet.

There is already a cargo-binstall package. (Which, I suppose could use cargo-binstall to install itself for a real “turtles all the way down”/Inception sort of feeling.)

1 Like

The concept of cargo-binstall - loading binaries built and packaged by another origin with a different trust model - works against the primary philosophy of nix/nixpkgs IMO. Instead we generally prefer to build from sources, using Nix, wherever source is available and licensing permits it. Sidestepping the packaging process and skipping our Hydra-based binary caches in favor of cargo-binstall is fine to do in personal configs of course, but it wouldn’t be very welcome in Nixpkgs contributions and it also means you’re throwing much of the value proposition of Nix away for that particular artifact. That’s why you haven’t found existing examples of doing so.

If you’re concerned with build times, some of the community Nix projects in this space make better use of incremental caching in a Nix-store based way instead than stdlib does and this may help, but they have other tradeoffs that prevent them from being unconditionally the superior tactic. It’s also a really diverse space for Nix library development, so I undoubtedly didn’t link every candidate here.

There’s also Dream2Nix and I’m afraid I’m OOTL but under the impression it’s under significant churn/rewrite at present.

I personally treat these as tactics for consuming off the shelf Rust software but I don’t use any of them for Rust projects where I’m an active contributor. There I just use devShells and regular old Cargo, and none of them are deployed with Nix anyway, but if I had to pick one approach to start integrating tomorrow it would very likely be Crane.

1 Like

Thank you; that makes a great deal of sense, @shanesveller. If I truly get impatient, I can certainly look into cargo2nix and the others you mentioned. Much appreciated!