Problem with a rust build (crane/fenix)

This is what effectively “fixes” it: fix: CARGO_HOME needs be set to stop the bleed from $HOME/.cargo · paisano-nix/mdbook-paisano-preprocessor@fffe203 · GitHub

It comes at the cost that the packages cache and indexes and all other things need to be kept in $PRJ_DATA_DIR/cargo, so first time using cargo needs a bit of downloading to that folder.

Overall, this issue is probably a typical one for an on-boarding story when the user already has been using the cargo toolchain in the traditional way (and likely didn’t clean up to try out Nix based workflows).

1 Like

There is an upstream rust issue for this

(Thanks @CobaltCause for linking me this in the nix rust matrix)

1 Like

You’re welcome! I didn’t have an account here before but I do now.

In general, if you can create a new place for $CARGO_HOME to live impurely, then you should also be able to symlink the right places back to the “real” one so you can still share the package cache and registry across all local projects. This does have the drawback of anything in your original $CARGO_HOME/bin no longer working the same, but if you’re using Nix then it’s pretty unlikely you have non-rust-toolchain tools in there anyway.

It’ll also bite you in certain CI systems; I first noticed this when trying to run a project’s CI in GitHub Actions because ubuntu-latest comes with a bunch of stuff pre-installed, including a rust toolchain. So, watch out for that too.