From 006a3283e7063cfff4efd5dd69c0c86027fdcb1f Mon Sep 17 00:00:00 2001 From: smarm Date: Fri, 24 Jul 2026 00:18:49 +0200 Subject: [PATCH] chore(hooks): clippy gate falls back to a nix-shell toolchain Desktop migration: the home-manager rust here ships without the clippy component. Prefer an installed cargo-clippy; otherwise run clippy from an ephemeral nix-shell with a separate target dir (mixed-compiler artifacts are an E0514 hard error). MSRV keeps the shell's older toolchain a legitimate gate. --- .githooks/pre-commit | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index d09c049..627b114 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -2,7 +2,23 @@ # smarm pre-commit gate: clippy the library (src/) with warnings as errors. # unwrap_used / expect_used are denied (Cargo.toml [lints.clippy]): library # code must not hide a panic behind unwrap/expect. Tests/examples are not gated. +# +# Toolchain resolution: prefer an installed cargo-clippy; on machines whose +# rust comes without the clippy component (e.g. NixOS home-manager), fall +# back to an ephemeral nix-shell toolchain. The fallback uses its own target +# dir (target/clippy) because the shell's rustc version may differ from the +# default toolchain's — mixed-compiler artifacts in one target dir are an +# E0514 hard error. MSRV (Cargo.toml rust-version) keeps the older shell +# toolchain a legitimate gate. set -eu [ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env" cd "$(git rev-parse --show-toplevel)" -cargo clippy --lib -- -D warnings +if cargo clippy --version >/dev/null 2>&1; then + cargo clippy --lib -- -D warnings +elif command -v nix-shell >/dev/null 2>&1; then + nix-shell -p clippy -p cargo -p rustc \ + --run 'CARGO_TARGET_DIR=target/clippy cargo clippy --lib -- -D warnings' +else + echo "pre-commit: cargo clippy unavailable and no nix-shell fallback" >&2 + exit 1 +fi