chore: pin the exact nightly toolchain used for rustfmt - #681
Open
varex83agent wants to merge 1 commit into
Open
chore: pin the exact nightly toolchain used for rustfmt#681varex83agent wants to merge 1 commit into
varex83agent wants to merge 1 commit into
Conversation
`cargo +nightly fmt` floated to whatever nightly happened to be installed, so a newly released nightly could silently change formatting and break the `--check` gate in CI. Introduce `rustfmt-toolchain` as a single source of truth (`nightly-2026-08-30`, the nightly the tree is currently formatted with) and have every consumer read it: - .github/workflows/linter.yml: install and run the pinned dated toolchain; add `rustfmt-toolchain` to the path triggers. - .githooks/pre-push and .claude/hooks/check-formatting.sh: use the pinned toolchain under rustup, keep the wrapped `cargo +nightly fmt` under Nix. - flake.nix: pin the dev-shell rustfmt to the same date instead of `selectLatestNightlyWith`. - AGENTS.md: document the pin. Bump the version by editing the single `rustfmt-toolchain` file. Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
emlautarom1
requested changes
Sep 1, 2026
emlautarom1
left a comment
Collaborator
There was a problem hiding this comment.
It kind of works but:
- Running the formatting from the terminal is non standard:
cargo fmtis incorrect,cargo +nightly fmtis also incorrect, you need to know the specific version to use resulting incargo +"$(cat rustfmt-toolchain)" fmtincantations. - On this, the PR updated docs are incorrect.
- Editors won't immediately know how to format - the command to use is non-standard.
- Nix users can use
cargo +nightly fmt, but that is due to a hack and unexpected in many ways.
If we go this route we need a wrapper script that runs the specific formatter so it's consistent across all environments (rustup, CI, Nix, etc) with no intervention (the suggested example project uses a wrapper over cargo itself)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Formatting runs via
cargo +nightly fmt, which resolves to whatever nightly happens to be installed in each environment. A newly released nightly can silently change formatting output and break thecargo +nightly fmt --all -- --checkgate in CI — with no change to our code.The float was happening in four independent places, each resolving nightly on its own: CI (
rustup +nightly), the gitpre-pushhook, the Claude formatting hook, and the Nix dev shell (selectLatestNightlyWith).Fix
Add
rustfmt-toolchainas a single source of truth:2026-08-30is the nightly the tree is currently formatted with — verified thatcargo +nightly-2026-08-30 fmt --all --checkreports zero diffs, so this pin causes no reformatting churn.Every consumer now reads that file:
.github/workflows/linter.ymlrustfmt-toolchainto path triggers.githooks/pre-pushcargo +nightly fmtunder Nix.claude/hooks/check-formatting.shflake.nixselectLatestNightlyWithAGENTS.mdThe Nix subtlety
The Nix dev shell has no rustup — it wraps
cargo +nightly fmtvia a shell script. So the scripts detect that wrapper (command -v cargo-+nightly) and keep usingcargo +nightly fmtthere (pinned by the flake), while rustup/CI use the dated toolchain name. Both resolve to the same nightly.Bumping later
Edit the single line in
rustfmt-toolchain, runcargo fmtwith the new nightly, commit.Testing
bash -n; the Claude hook runs and verifies the tree clean with the pinned toolchain.+nightly(rustfmt build9085017724) differs from the pinned build (fd7ed57dfd) — the drift is real and now controlled.flake.nixnot evaluated locally (nonixavailable). On firstnix develop, ifrust-overlaydoesn't know the pinned date, runnix flake update rust-overlay(noted in a comment in the flake).🤖 Generated with Claude Code