Align dev-shell rustfmt with craneLib's cargo-fmt check #12

Closed
opened 2026-05-01 14:03:16 -07:00 by auto-review · 0 comments
Collaborator

Surfaced when CI rejected formatting that local cargo fmt --all -- --check accepted (commit fb19499 → CI run 19 → rustfmt diff in crates/ar-prompts/src/schema.rs and crates/ar-index/src/embed.rs).

The dev-shell and the flake check resolve to different rustfmt store paths, despite craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain in flake.nix:

  • Dev shell: /nix/store/.../rustfmt-preview-1.97.0-nightly-2026-05-01/bin/rustfmt
  • craneLib cargoFmt: /nix/store/.../rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz.drv (different package, same toolchain version)

Same toolchain version but different packages (rustfmt-preview from the rust-overlay bundle vs rustfmt-nightly from craneLib's own resolution). They diverge in formatting decisions. Result: a developer who runs cargo fmt --all -- --check locally and sees no diff still gets red CI.

User directive: whichever is stricter wins; the two should match.

Proposed fix: ensure craneLib.cargoFmt uses the same rustfmt binary the dev shell does. Either:

  1. Pass an explicit rustfmt derivation to craneLib.cargoFmt so it's pinned to the same one in the dev shell, or
  2. Add a project script scripts/fmt-check that invokes nix flake check .#cargo-fmt (the CI command) and document it as the only fmt gate; remove cargo fmt --all -- --check from contributor docs.

(2) is the lower-effort fix; (1) is the right fix because (2) requires every contributor to remember the special command.

Touches: flake.nix (around line 160 — the craneLib.cargoFmt invocation).

Surfaced when CI rejected formatting that local `cargo fmt --all -- --check` accepted (commit fb19499 → CI run 19 → rustfmt diff in `crates/ar-prompts/src/schema.rs` and `crates/ar-index/src/embed.rs`). The dev-shell and the flake check resolve to *different rustfmt store paths*, despite `craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain` in flake.nix: - Dev shell: `/nix/store/.../rustfmt-preview-1.97.0-nightly-2026-05-01/bin/rustfmt` - craneLib cargoFmt: `/nix/store/.../rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz.drv` (different package, same toolchain version) Same toolchain *version* but different *packages* (`rustfmt-preview` from the rust-overlay bundle vs `rustfmt-nightly` from craneLib's own resolution). They diverge in formatting decisions. Result: a developer who runs `cargo fmt --all -- --check` locally and sees no diff still gets red CI. User directive: whichever is stricter wins; the two should match. **Proposed fix:** ensure `craneLib.cargoFmt` uses the same rustfmt binary the dev shell does. Either: 1. Pass an explicit `rustfmt` derivation to `craneLib.cargoFmt` so it's pinned to the same one in the dev shell, or 2. Add a project script `scripts/fmt-check` that invokes `nix flake check .#cargo-fmt` (the CI command) and document it as the only fmt gate; remove `cargo fmt --all -- --check` from contributor docs. (2) is the lower-effort fix; (1) is the right fix because (2) requires every contributor to remember the special command. Touches: `flake.nix` (around line 160 — the `craneLib.cargoFmt` invocation).
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jwilger/auto_review#12
No description provided.