From 550a81d4de53b9132b0526c152756ed7e127e1f5 Mon Sep 17 00:00:00 2001 From: Thomas Yau Date: Mon, 20 Jul 2026 18:48:56 +0800 Subject: [PATCH] build: pin stable Rust version via rust-toolchain.toml The stable Rust version lived only in the Earthfile's base image tag. Local builds were left unpinned, and the nix flake floated on rust-overlay's latest stable, so the three could silently drift onto different compilers. Add a rust-toolchain.toml that rustup honours for both local builds and the Earthfile image, and pin the nix stable toolchain to that same channel (rustLatest -> rustStable) rather than tracking latest. The nightly updater now rewrites the toml alongside the Earthfile and refreshes the rust-overlay input in flake.lock, so nix can resolve the freshly pinned version within the same PR. --- .github/workflows/nightly-rust-update-check.yaml | 11 +++++++++++ nix/modules/checks.nix | 4 ++-- nix/modules/common.nix | 9 +++++++-- nix/modules/cross.nix | 4 ++-- nix/modules/devshells.nix | 6 +++--- nix/modules/native.nix | 14 +++++++------- rust-toolchain.toml | 2 ++ 7 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 rust-toolchain.toml diff --git a/.github/workflows/nightly-rust-update-check.yaml b/.github/workflows/nightly-rust-update-check.yaml index 3faabfc9..f24f30e4 100644 --- a/.github/workflows/nightly-rust-update-check.yaml +++ b/.github/workflows/nightly-rust-update-check.yaml @@ -31,6 +31,17 @@ jobs: - name: Update Rust version in Earthfile run: sed -i -E 's/^(\s*FROM rust):(:?[0-9\.]+)(-.+)?$/\1:${{ steps.check-version.outputs.rust }}\3/g' Earthfile + - name: Update Rust version in rust-toolchain.toml + run: sed -i -E 's/^(channel = ")[0-9\.]+(")$/\1${{ steps.check-version.outputs.rust }}\2/' rust-toolchain.toml + + # nix (rust-overlay) can only resolve the pinned stable version once flake.lock points at a + # rust-overlay revision that carries it, so refresh that input in the same PR. + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v21 + + - name: Update rust-overlay in flake.lock + run: nix flake update rust-overlay + - uses: peter-evans/create-pull-request@v6 with: token: ${{ secrets.SERVICE_ACCOUNT_PAT }} diff --git a/nix/modules/checks.nix b/nix/modules/checks.nix index fd90c1e2..d20ea9c5 100644 --- a/nix/modules/checks.nix +++ b/nix/modules/checks.nix @@ -4,7 +4,7 @@ { lib, pkgs, - rustLatest, + rustStable, ... }: let @@ -12,7 +12,7 @@ src = ../..; # Rust toolchain with rustfmt component - rust = rustLatest.default.override { + rust = rustStable.default.override { extensions = [ "rustfmt" ]; }; diff --git a/nix/modules/common.nix b/nix/modules/common.nix index b0c3c156..342a5517 100644 --- a/nix/modules/common.nix +++ b/nix/modules/common.nix @@ -6,15 +6,20 @@ cargoToml = builtins.fromTOML (builtins.readFile ../../Cargo.toml); msrv = cargoToml.workspace.package.rust-version; + # Pinned stable version, shared with the Earthfile and local dev via rust-toolchain.toml. + # rust-overlay does not read rust-toolchain.toml itself, so parse the channel and pin explicitly. + rustToolchain = builtins.fromTOML (builtins.readFile ../../rust-toolchain.toml); + rustStableVersion = rustToolchain.toolchain.channel; + # Rust toolchains (shared across all modules) - rustLatest = pkgs.rust-bin.stable.latest; + rustStable = pkgs.rust-bin.stable.${rustStableVersion}; rustMsrv = pkgs.rust-bin.stable.${msrv}; rustNightly = pkgs.rust-bin.nightly.latest; in { # Export via _module.args for use in other modules _module.args = { - inherit rustLatest rustMsrv rustNightly; + inherit rustStable rustMsrv rustNightly; }; }; } diff --git a/nix/modules/cross.nix b/nix/modules/cross.nix index 7ab6797d..c9da767e 100644 --- a/nix/modules/cross.nix +++ b/nix/modules/cross.nix @@ -6,7 +6,7 @@ pkgs, pkgsDarwinX64, system, - rustLatest, + rustStable, ... }: let @@ -91,7 +91,7 @@ mkCrossToolchain = targetName: config: let - rust = (config.rustBin or rustLatest).minimal.override { targets = [ config.rustTarget ]; }; + rust = (config.rustBin or rustStable).minimal.override { targets = [ config.rustTarget ]; }; in { inherit (config) pkgsCross rustTarget isStatic; diff --git a/nix/modules/devshells.nix b/nix/modules/devshells.nix index d2999be6..eab54273 100644 --- a/nix/modules/devshells.nix +++ b/nix/modules/devshells.nix @@ -5,7 +5,7 @@ config, lib, pkgs, - rustLatest, + rustStable, rustMsrv, rustNightly, system, @@ -16,7 +16,7 @@ default = config.devShells.stable; stable = pkgs.callPackage ../shell.nix { - rustc = rustLatest.default; + rustc = rustStable.default; }; nightly = pkgs.callPackage ../shell.nix { rustc = rustNightly.default; @@ -57,7 +57,7 @@ .${system} or null; in pkgsCross.callPackage ../shell.nix ({ - rustc = rustLatest.minimal.override { + rustc = rustStable.minimal.override { targets = [ "aarch64-linux-android" "armv7-linux-androideabi" diff --git a/nix/modules/native.nix b/nix/modules/native.nix index 49b78881..037b5b87 100644 --- a/nix/modules/native.nix +++ b/nix/modules/native.nix @@ -5,15 +5,15 @@ lib, pkgs, system, - rustLatest, + rustStable, rustMsrv, ... }: let # Rust platforms - rustPlatformLatest = pkgs.makeRustPlatform { - cargo = rustLatest.minimal; - rustc = rustLatest.minimal; + rustPlatformStable = pkgs.makeRustPlatform { + cargo = rustStable.minimal; + rustc = rustStable.minimal; }; rustPlatformMsrv = pkgs.makeRustPlatform { cargo = rustMsrv.minimal; @@ -44,9 +44,9 @@ # Native packages for all platforms nativePackages = { - # Latest stable builds - "lightway-client-${nativeSuffix}" = mkPackage "lightway-client" pkgs rustPlatformLatest; - "lightway-server-${nativeSuffix}" = mkPackage "lightway-server" pkgs rustPlatformLatest; + # Pinned stable builds + "lightway-client-${nativeSuffix}" = mkPackage "lightway-client" pkgs rustPlatformStable; + "lightway-server-${nativeSuffix}" = mkPackage "lightway-server" pkgs rustPlatformStable; # MSRV builds "lightway-client-${nativeSuffix}-msrv" = mkPackage "lightway-client" pkgs rustPlatformMsrv; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000..72436043 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.97.1"