How to specify the default nightly version (ie `+nightly`) with rustup?

The project I'm working has a lot of scripts that do things with both stable and nightly Rust builds. The scripts specify the nightly build with cargo +nightly, but the problem is that the latest nightly build has removed features that are depended on. Obviously that needs to be fixed at some point, but for now I just need to run the scripts.

I managed to make this work by hacking the install directory:

> rm -r ~/.rustup/toolchains/nightly-x86_64-apple-darwin
> cp ~/.rustup/toolchains/nightly-2024-02-05-aarch64-apple-darwin \

But what is the "proper" way to accomplish this?

In principle, the right thing to do here is to pin the nightly version in the scripts (cargo +nightly-2024-02-05).

Normally, you'll create a rust-toolchain.toml file that pins your project/directory/whatever to a specific version of Rust.

That said, having a project that uses multiple versions of Rust at the same time seems like a bad idea. If possible, you might want to re-work things to only use the one version (e.g. stable).


I don't have control over that. The project is large and uses unstable features in benchmarks, tests and some tooling. The actually binaries are built with stable.

I'll have a look at creating a toolchain file.

Coming back to this, the real problem is actually that I'm doing this in a docker image for CI. Builds use stable Rust but there are some tasks that use nightly. I don't have control over the different (existing and future) tasks that use the image, but I do know that some use cargo +nightly. I just want to find a foolproof way to make that work with a specific nightly toolchain that I've bundled into the image.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.