[SOLVED] Rust 1.5.0 on Nixos

I'm having some trouble running rust 1.5.0 on Nixos.

I use stable Nixos and a custom nix expression (based on @Ericson2314's, thanks a lot!) to install rust. Here is the gist.

While version 1.4.0 works fine, version 1.5.0 gives "error: can't find crate for std [E0463]" when I try compile anything :frowning:

I'm new to nix, so I am not even sure that this is a proper way of getting the latest stable rust to nix.

1 Like

There is an similar issue here Can't find create for std

Maybe that can give some pointers.

Cheers!

Yep, adding prePatch="mv rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/ rustc/lib/rustlib/" solved my issue.

Thanks, the hint was instrumental!

FYI, I had to add a condition to the prePatch directive to make it work otherwise mv would fail on the cargo package.

    prePatch=''
      if [ "$name" == "rustc" ]; then
	mv rust-std-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/ rustc/lib/rustlib/
      fi
    '';

Otherwise this fixed my issue on NixOS. Thanks!

Belated followup, I've tweaked the code to work again. Changes to how rustc vs stdlib is distributed, and, more recently, the multiple output paths PR for nixpkgs, both broke it. Happy Rust+Nix!

1 Like

@Ericson2314 is there any decent way to make rustup work with NixOs?

I've gave up on it recently and just sudo ln -s /run/current-system/sw/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 :frowning2:

The optimal solution is to statically link musl in all releases.
This is possible even when dynamic loading is involved (rustc could be statically linked against the musl dynamic loader, although it's not trivial).

I don't see any purpose for rustup on NixOS. All that home-directory installation stuff is a big hack in comparison IMO. Somebody could make something far smaller to grab the hashes for a specific day however (they are stored at static.rust-lang.org last I checked). Or just use the unsafe fetchurl.

1 Like

I would like the convenience of rustup coupled with nix-shell's semantics.
There might be a way to do this by passinga derivation (containing the URLs and the hashes) to nix-shell which would do some of the heavy lifting.
However, this would be a different rustup than what everyone else is using and I don't think it should exist unless it's very simple.

One cool thing about nix-shell though is that you make it run nothing (or true) to "install" a toolchain - the effect would be that it's cached until later garbage-collected.
Of course, you could also root it, not sure how painful that is with transient derivations.

What do you mean by simple? What I wrote is quite simple but harder to use because on needs to plug in dates and hashes. I could make it easier to use but then it would be more complex.

I think rooting dev environments should become easier with the new command line. The goal is to have separate tools for debugging derivations vs creating a temp dev environment? The former was nix-shell's original purpose but the latter is its much more common use-case.

Ok I added the ability to pull hashes from the build farm, so one doesn't need to specify them manually. [Security-wise since I do an unverified download to get them in the first place this does nothing, but the extra download of the hash could help guard against network errors I suppose.] One can still specify the hash as before if they want.

See https://github.com/RustOS-Fork-Holding-Ground/RustOS/blob/master/default.nix#L7-L37 for usage.

1 Like