|
24 | 24 |
|
25 | 25 | formatter = pkgs.nixfmt-rfc-style; |
26 | 26 |
|
27 | | - # Rust toolchain derived from rust-toolchain.toml |
28 | | - # Uses oxalica/rust-overlay to match the pinned channel/components. |
29 | | - rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; |
| 27 | + # Use rustup to manage toolchains so `cargo +nightly` works in dev shell |
| 28 | + rustup = pkgs.rustup; |
30 | 29 | in |
31 | 30 | { |
32 | 31 | inherit formatter; |
33 | 32 |
|
34 | 33 | devShells.default = pkgs.mkShell { |
35 | 34 | packages = with pkgs; [ |
36 | | - # Rust toolchain pinned via rust-toolchain.toml |
37 | | - rustToolchain |
| 35 | + # Rustup manages stable/nightly toolchains according to rust-toolchain.toml |
| 36 | + rustup |
38 | 37 | pkg-config |
39 | 38 | openssl |
40 | 39 |
|
|
49 | 48 | ]; |
50 | 49 |
|
51 | 50 | RUST_BACKTRACE = "1"; |
| 51 | + |
| 52 | + # Ensure rustup shims are used and install required toolchains on first entry |
| 53 | + shellHook = '' |
| 54 | + export RUSTUP_HOME="$PWD/.rustup" |
| 55 | + export CARGO_HOME="$PWD/.cargo" |
| 56 | + export PATH="$CARGO_HOME/bin:$PATH" |
| 57 | +
|
| 58 | + if ! command -v rustup >/dev/null 2>&1; then |
| 59 | + echo "rustup not found in PATH" 1>&2 |
| 60 | + else |
| 61 | + # Install toolchains if missing; respect pinned channel from rust-toolchain.toml |
| 62 | + if ! rustup toolchain list | grep -q nightly; then |
| 63 | + rustup toolchain install nightly --profile minimal >/dev/null 2>&1 || true |
| 64 | + fi |
| 65 | + # Ensure stable toolchain from rust-toolchain.toml exists (rustup will auto-select it) |
| 66 | + # Attempt to install channel specified in rust-toolchain.toml (fallback to stable) |
| 67 | + TOOLCHAIN_CHANNEL=$(sed -n 's/^channel\s*=\s*"\(.*\)"/\1/p' rust-toolchain.toml || true) |
| 68 | + if [ -n "$TOOLCHAIN_CHANNEL" ]; then |
| 69 | + if ! rustup toolchain list | grep -q "$TOOLCHAIN_CHANNEL"; then |
| 70 | + rustup toolchain install "$TOOLCHAIN_CHANNEL" --profile minimal --component rustfmt clippy >/dev/null 2>&1 || true |
| 71 | + fi |
| 72 | + fi |
| 73 | + fi |
| 74 | + ''; |
52 | 75 | }; |
53 | 76 | } |
54 | 77 | ); |
|
0 commit comments