Skip to content

feat(nix): guard the mkRustProject consumer path and close two gaps - #1452

Merged
gerchowl merged 3 commits into
feature/1400-rust-language-packfrom
feature/1450-rust-pack-consumer-hardening
Aug 12, 2026
Merged

gerchowl merged 3 commits into
feature/1400-rust-language-packfrom
feature/1450-rust-pack-consumer-hardening

Conversation

@gerchowl

Copy link
Copy Markdown
Contributor

Targets feature/1400-rust-language-pack, not dev — these are fixes to the pack before it ships, so a reader of the released notes never sees the behaviour being corrected.

Everything here came out of adopting #1429 on a second consumer, gerchowl/squelch: a single-crate library, no binaries, heavily feature-gated (browser/logs default; gh-cli, endpoint, serde optional), wired from scratch rather than migrated. Full adoption report is the comment on #1429. Closes #1450.

Two guards

Both replace a failure that was opaque, partial, or both. Both follow the toolchainHash error's shape, which is the best error in the pack: say what happened, say why no default could be right, give the exact line to add.

pkgs without overlays.default. mkProjectShell pulls nix/devtools.nix, which resolves vig-utils from devkit's overlay. Without it the shell died on undefined variable 'vig-utils' — an error inside devkit, naming something the consumer has never seen, from a file they did not open.

The reason this is a guard and not a docs fix: checks and packages never touch mkProjectShell, so they evaluate fine without the overlay. Unguarded, that is a repo with a green nix flake check and a dev shell that has never once evaluated. Checked lazily, on the dev shell alone — an eager throw would break a configuration that legitimately uses only the checks.

Missing Cargo.lock. A flake's src is the git tree, so a repo that gitignores its lockfile — the long-standing library convention, and what cargo new --lib wrote for years — hands crane a source without one. crane's own message is good, but only reachable from the derivations that vendor: cargoFmt takes src alone and passed, which made a total failure look partial. The guard sits on cleanSrc so fmt fails with the rest.

Two gaps the suite did not admit to

checks.doctest. #1400's stage table assigns pre-push nextest and cargo test --doc. nextest cannot run doctests (process-per-test has nowhere to put them) and cargoDoc only lints rustdoc, so nothing executed them — a consumer whose doctests ran under cargo test lost them on adoption, silently. crane already ships cargoDocTest; this is one optionalAttrs block.

cargoExtraArgs. The checks built default features only, and nothing reached buildDepsOnly / nextest / doc / the package builds — clippyExtraArgs covers clippy alone, and carries lint flags rather than feature selection. On squelch that was 55 of 59 tests, with the gated code never compiled and therefore never linted. The suite reported success over the gap.

Composed with -p <crate> in buildCrate rather than overwriting it, so a workspace's per-crate builds cannot end up with a different feature set from the checks that ran against them.

The seam that worked before this was buildEnv = { cargoExtraArgs = …; }, since buildEnv is a raw commonArgs merge wearing an env-var name. Left in place, now commented as what it actually is.

Verified

  • uv run pytest tests/test_flake_modules.py -k "rust or mk_rust" — 13 passed, including the zero-module parity invariant.
  • The four new tests were committed failing first, and each fails for its own reason before the implementation commit.
  • End-to-end on the consumer, with --override-input devkit pointed at this branch: nix flake check green on 6 checks, doctest executing squelch's 3 doctests, and cargoExtraArgs = "--all-features" replacing the buildEnv workaround.

Note on scope

The fixture crate is written to tmp_path at test time rather than committed under tests/fixtures/, deliberately: a Cargo.toml inside devkit would make devkit look like a Rust consumer to its own language detection.

Refs: #1450

Four eval-time tests from adopting the Rust pack on a second consumer
(single-crate library, no binaries, heavily feature-gated):

- a pkgs without devkit's overlay must name overlays.default rather than
  dying on `undefined variable 'vig-utils'` inside devtools.nix
- a tree with no Cargo.lock must fail through fmt too, which took only
  `src` and so passed while the other five derivations failed
- checks must include a doctest entry, which #1400's stage table assigns
  to pre-push and #1429 did not ship
- cargoExtraArgs must reach commonArgs, so the checks can build features
  other than the default set

A dependency-free fixture crate keeps the lockfile a literal, so all four
run at eval — no vendoring, no network, no compile.

Refs: #1450
Two guards and two additions, all from a second consumer's adoption.

The guards replace failures that were opaque or partial:

- a pkgs without devkit's overlay now names overlays.default and says
  which outputs need it, instead of dying on `undefined variable
  'vig-utils'` inside devtools.nix. Checked lazily, on the dev shell
  alone: checks and packages never reach mkProjectShell and are usable
  against a plain nixpkgs, so an eager throw would break a working
  configuration to improve a message.
- a source tree with no Cargo.lock now says so, and says why a git-tree
  source is the reason. The check sits on cleanSrc so fmt fails with the
  rest rather than passing alone and making a total failure look partial.

The additions close gaps the suite did not admit to:

- checks.doctest runs `cargo test --doc`, which #1400 assigned to
  pre-push. nextest cannot run doctests and cargoDoc only lints rustdoc,
  so adopting the pack silently dropped them.
- cargoExtraArgs reaches every derivation, so the checks can build
  features other than the default set. Composed with `-p <crate>` in
  buildCrate rather than overwritten, so a workspace's per-crate builds
  cannot end up with a different feature set from the checks that ran
  against them.

Refs: #1450
Folded into the existing Rust language pack entry rather than opened as a
separate one: the fixes land before the pack has shipped, so a reader of
the released notes never saw the behaviour being corrected.

Refs: #1450
@gerchowl
gerchowl force-pushed the feature/1450-rust-pack-consumer-hardening branch from 441540f to 4be5e00 Compare August 12, 2026 09:45
@gerchowl
gerchowl merged commit 9072c91 into feature/1400-rust-language-pack Aug 12, 2026
@gerchowl
gerchowl deleted the feature/1450-rust-pack-consumer-hardening branch August 12, 2026 13:04
gerchowl added a commit to gerchowl/squelch that referenced this pull request Aug 12, 2026
…around

The pack now takes feature selection as a first-class argument, so the
checks build --all-features through the supported seam rather than by
smuggling it through buildEnv, which is documented as carrying
CMAKE_*/PKG_CONFIG_PATH and merely happens to be a raw commonArgs merge.

Also picks up the doctest check, so squelch's three doctests run in
nix flake check — they were not executed by any check before, since
nextest cannot run doctests and the doc check only lints rustdoc.

Points at vig-os/devkit#1452 (which targets the pack branch) until that
merges.
gerchowl added a commit to gerchowl/squelch that referenced this pull request Aug 12, 2026
…rged

vig-os/devkit#1452 landed on feature/1400-rust-language-pack, so the
branch this repo was pinned to no longer exists. Points at the pack
branch itself; a release tag once the pack lands on devkit's dev.
gerchowl added a commit that referenced this pull request Aug 12, 2026
…craneArgs

Follow-ups from the second-consumer review in #1452, both on things that
review either surfaced or deliberately left to me.

THE SENTINEL NEEDED ITS OTHER HALF. #1452's overlay guard is right and
the error is good, but `hasOverlay = pkgs ? vig-utils` is a PROXY: it
infers "the overlay was applied" from one package name. Proxies drift.
If devkit's overlay ever renames or drops vig-utils, the guard starts
throwing "you did not apply the overlay" at consumers who did — and the
shipped test would still pass, because it asserts a throw.

That is the rule this whole branch is built on, applied to the branch
itself: a gate is unverified until it has fired on known-bad input AND
stayed quiet on known-good. The guard arrived with only the first half.
The new positive test evaluates rust.devShell WITH the overlay, so the
day the sentinel stops tracking what it stands for, something fails.

BUILDENV WAS A LIE OF OMISSION. #1452 found that feature selection had
exactly one seam reaching buildDepsOnly, and it was an argument
documented as holding CMAKE_* and PKG_CONFIG_PATH. They added a real
`cargoExtraArgs` and left the naming question to me, correctly.

It is now `craneArgs`, documented as what it is: raw attrs merged last
into every crane derivation, beating everything above them. `buildEnv`
stays accepted as a deprecated alias so the second consumer's flake
keeps evaluating — merged after craneArgs, on the reasoning that anyone
still passing the old name means it.

Reviewed the rest of #1452 by running it rather than reading it: the
pinned crane does expose cargoDocTest, filesender's check set is 11 with
`doctest` present and executing (zero doctests there, so vacuous on this
consumer but live on squelch's three), and the rust suite is 16 green,
19 with these two.

Refs: #1450, #1400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant