Re:How Nix and NixOS get so close to perfect
by BaculumMeumEst on Sunday April 24, 2022 @08:52AM
(#31143481)
I’ve been trying out GUIX, but I wasn’t able to figure out a good way to do rust development on it. Tools like Cargo and Rust analyzer are extremely useful but introduce a lot of complexity which doesn’t seem to mix well with functional package managers like guix and nix.
[ Parent
| on HN ]
In Nix land I've been using naersk[1] to build Rust packages into Nix packages. Here's a minimal example of a Nix project that uses Rust, Naersk and puts cargo/rust analyzer in the devshell environment: https://tulpa.dev/cadey/printerfacts
Here are my two favorite (bookmarked) links for packaging and developing for rust. The trick is keep packaging and rust development separate and use specific dev environment flakes. So for dev work just bring cargo and rust as the nativeBuildInputs in mkShell (and any non rust dependencies) and then use standard cargo for development. But for packaging use one of the fancy tools.
1. https://srid.ca/rust-nix
2. https://discourse.nixos.org/t/cargo2nix-dramatically-simpler...
Re:How Nix and NixOS get so close to perfect
by tazjin on Sunday April 24, 2022 @08:57AM
(#31143509)
We use naersk[0] for Rust projects in our Nix monorepo (for example [1]). It's pretty hands-off in terms of the Nix code needed (you don't need to pin hashes inside of the Nix code as long as you have a Cargo lockfile) and all the existing tooling keeps working fine.
The main drawback of it is that it currently builds all of your dependencies in one big derivation, so any dependency changes cause a full rebuild. There's some other project I saw fly by which attempts to do a similar thing but split each crate into a separate derivation, but I forgot what it's called and have no experience with it.
[0]: https://github.com/nix-community/naersk
[1]: https://cs.tvl.fyi/depot/-/blob/ops/journaldriver/default.ni...
It's crate2nix: https://github.com/kolloch/crate2nix
Re:How Nix and NixOS get so close to perfect
by tazjin on Sunday April 24, 2022 @09:13AM
(#31143620)
No, unless something significantly changed there. There's another project like naersk which doesn't need to generate a "Cargo.nix" file.
Re:How Nix and NixOS get so close to perfect
by vbrandl on Sunday April 24, 2022 @11:39AM
(#31145089)
Maybe cargo2nix? https://github.com/cargo2nix/cargo2nix