Skip to content

feat(nix): Rust language pack — capability module + lib.mkRustProject - #1429

Merged
gerchowl merged 12 commits into
devfrom
feature/1400-rust-language-pack
Aug 12, 2026
Merged

gerchowl merged 12 commits into
devfrom
feature/1400-rust-language-pack

Conversation

@gerchowl

Copy link
Copy Markdown
Contributor

Ships the Rust language pack as two pieces, and the split between them is the design. Implements the A + D + assert resolution recorded in #1427.

Closes #1400. Refs #1427.

How to test it

# flake.nix
inputs.devkit.url = "github:vig-os/devkit/feature/1400-rust-language-pack";

# perSystem
rust = devkit.lib.mkRustProject {
  inherit pkgs;
  src = ./.;
  toolchainHash = "sha256-…";       # for your rust-toolchain.toml
  crates = [ "my-cli" ];
};
devShells.default = rust.devShell;
checks             = rust.checks;
packages           = rust.packages;

Set toolchainHash = pkgs.lib.fakeHash first; the build failure prints the real one.

Toolchain-only, no check suite — deliberate and explicit:

modules = [ { name = "rust"; checks = "none"; } ];

And the thing that should NOT work:

modules = [ "rust" ];   # eval error, by design — see below

What's here

File
nix/modules/rust.nix v1 capability module: toolchain + curated cargo tooling + mold on Linux
nix/mk-rust-project.nix lib.mkRustProject — dev shell, checks and packages from one call
nix/modules/check-entries.nix internal: how the generated module-<name> check instantiates a module whose options are mandatory

Checks produced: the per-crate builds, plus clippy, fmt, nextest, doc (rustdoc warnings denied) and deny (auto-enabled when a deny.toml exists).

Why checks are a lib function and not a contract field

packages / env / shellHook fold monoidally into one derivation — the shell. checks is a namespaced map of independent peer derivations on a different lifecycle (nix flake check, not nix develop), built from the consumer's source tree, which is project shape a module never sees.

The test that settled it: a checks field could be added to the shell-composition contract without touching shell composition at all. If a field can be added to a contract without touching what that contract composes, it isn't part of that contract.

So mkRustProject composes above mkProjectShell and returns all three together. One call — there is no second function to forget.

Why the module refuses to load bare

modules = [ "rust" ] would hand you a toolchain, a green nix flake check that builds nothing, and CI that compiles nothing: the exact silent-green failure the pack exists to prevent, delivered by the pack. So the module's checks option is mandatory with no default, and the bare form throws at eval with a message naming the fix and the opt-out.

Being straight about the limit: flake outputs are consumer-assigned by construction. No option here — including extending the contract — could have made correct wiring structurally impossible. What this shape buys is one call instead of two, checks arriving visibly beside devShell, and a loud eval-time failure on the one remaining path. Silence was the failure mode; silence is what's removed.

Costs, stated plainly

  • crane + fenix become devkit inputs — 3 leaf lock entries that every consumer pays for, Python-only ones included, in lock size and fetch-at-eval. The alternative is each Rust repo pinning its own fenix, which is per-repo drift on exactly the axis devkit exists to hold still. mkRustProject takes crane/fenix overrides, so the inputs can move back out later without a consumer-visible change. Flag it if you disagree — this is the most reversible-but-annoying-later decision in the PR.
  • nix/lib/ turned out to be gitignored (.gitignore:17 has a bare lib/ from the Python layout, which swallows any lib directory at any depth). The file lives at nix/mk-rust-project.nix instead, matching nix/hooks.nix / nix/devtools.nix. Worth fixing that pattern separately — it will bite someone else.

Verified, not assumed

  • checks.<system>.module-rust evaluates ✅
  • Bare modules = [ "rust" ] throws the guidance error ✅
  • Zero-module invariant holds: devShells.<system>.default.drvPath is byte-identical to dev ✅
  • End-to-end on the first consumer (gerchowl/filesender, a cli + mcp + lib workspace): its ~120 lines of hand-rolled crane/fenix wiring were deleted and replaced by one mkRustProject call; all 9 checks evaluate and build.

Two bugs this shape prevents by construction

Both were shipped by the first consumer, and both were invisible to inspection:

  1. deny.toml outside the crane fileset — an openssl ban that banned nothing.
  2. clippy.toml outside the fileset — the sandboxed clippy check ran against defaults, enforcing rules nobody wrote.

mkRustProject folds the well-known root tool configs (rustfmt.toml, clippy.toml, deny.toml, about.*, .cargo/) into the fileset unconditionally via maybeMissing, so there is nothing to remember and nothing to keep in sync.

Found by devkit's own gates, on devkit

Worth recording because it is the same failure class this PR is about. My first branch was feat/rust-language-pack and the first two commits said Refs #1400 without the colon. Both were wrong by devkit's own rules — the taxonomy is feature, not feat, and Refs: is a mandatory trailer — and both went through, because a fresh git clone has no hooks installed until something installs them. They were caught only when the hooks happened to be present for the third commit.

That is exactly the shape of the five bugs in the first consumer's history: configured, believed active, never executed. Branch renamed, trailers normalized, commits signed. But a fresh clone of devkit does not enforce devkit's rules until someone runs the installer, and nothing tells you that. Probably worth its own issue.

Review asks

  1. The crane/fenix as devkit inputs tradeoff above.
  2. check-entries.nix — is a per-name generator override the right answer for mandatory-option modules, or should the generated smoke check learn about them some other way?
  3. Whether the eval-time refusal is too aggressive for a scratch-shell user (the opt-out is one attrset, but it is friction).

`rust` was an ask-gated candidate in ADR-capability-modules;
gerchowl/filesender is the ask. It ships as two pieces, and the split
between them is the whole design.

The module (nix/modules/rust.nix) stays on the v1 contract: packages,
env, shellHook. It puts a toolchain and the curated cargo tooling on the
dev-shell PATH, and that is the easy half of the capability.

The half that earns its keep is the check suite, and a v1 module cannot
contribute `checks.<system>.*`. That is not an oversight in the contract
— `packages`/`env`/`shellHook` fold monoidally into one derivation,
while `checks` is a namespaced map of independent peer derivations on a
different lifecycle, built from the consumer's source tree, which is
project shape a module never sees. The test that settled it (#1427): a
`checks` field could be added to the shell-composition contract WITHOUT
touching shell composition at all. If a field can be added to a contract
without touching what that contract composes, it is not part of it.

So lib.mkRustProject composes above mkProjectShell instead, and returns
the dev shell, the checks and the packages from ONE call. There is no
second function to forget.

Flake outputs are still consumer-assigned by construction, so nothing
here — and no contract change either — could make wiring structurally
impossible. What remains is closed loudly: the module's `checks` option
is mandatory with no default, so a hand-written `modules = [ "rust" ]`
fails at EVAL with a message that names the fix and the deliberate
opt-out (`{ name = "rust"; checks = "none"; }`). Silence was the failure
mode; silence is what is removed.

Notable details:

- mkRustProject folds the well-known root tool configs (rustfmt.toml,
  clippy.toml, deny.toml, about.*, .cargo/) into the crane fileset
  unconditionally via maybeMissing. Their absence from a build sandbox
  is SILENT — rustfmt/clippy/cargo-deny fall back to built-in defaults
  and the check passes while enforcing rules nobody wrote. The first
  consumer shipped that bug twice.
- The generated `checks.<system>.module-<name>` cannot instantiate a
  module whose options are mandatory, since it passes the bare name. The
  new nix/modules/check-entries.nix is the generator's per-name
  override; `rust` maps to the toolchain-only form. Internal plumbing,
  not consumer surface.
- crane and fenix become flake inputs (3 leaf lock entries). Every
  consumer, including Python-only ones, pays for them in lock size and
  fetch-at-eval. The alternative — each Rust repo pinning its own fenix
  — is per-repo drift on exactly the axis devkit exists to hold still.
  mkRustProject takes overrides, so the inputs can move back out later
  without a consumer-visible change.
- Zero-module invariant preserved: devShells.<system>.default.drvPath is
  byte-identical to dev (verified, not assumed).

Refs: #1400, #1427
crane's buildPackage runs `cargo test` as part of the build. With the
nextest check enabled that is the same suite run twice, on two separate
derivations, for one signal. The package builds now set doCheck = false
whenever nextest is enabled, leaving the test run to checks.nextest —
which is also what CI invokes via `just test`.

Gated on nextest rather than unconditional: with nextest off, dropping
doCheck would mean nothing runs the tests at all.

Refs: #1400
Nine tests on the rust module, and the load-bearing one is
`test_rust_module_bare_form_throws_with_mkrustproject_guidance`: the
whole design rests on `modules = [ "rust" ]` refusing to evaluate, so
that refusal gets a fixture asserting it fires AND that the message
names both the fix and the option. The rest cover the registry entry,
the generated module-rust check, the explicit opt-out, and the three
rejection paths (unknown option, invalid `checks` value, unknown tool).

The parity test is the other half: devShells.<system>.default.drvPath
must be byte-identical to a bare mkProjectShell, so the rust module's
existence cannot perturb the zero-module invariant. No inventory test
enumerating capability modules exists, so nothing needed `rust` added.

ADR-capability-modules gains the #1427 decision, the honest limitation
(flake outputs are consumer-assigned by construction, so no contract
change could have made wiring structurally impossible), the bar for
revisiting, the two rejected options, and a subsection documenting
check-entries.nix as internal plumbing. `rust` moves out of the
ask-gated candidate list into shipped.

Also in this commit: RUSTDOCFLAGS moves to a top-level attr on the doc
check so a consumer's `buildEnv` cannot collide with it through two
mechanisms, and the new banners say `inputs.devkit` rather than
`inputs.devcontainer` — the repo is devkit now.

Refs: #1400, #1427
@gerchowl

Copy link
Copy Markdown
Contributor Author

End-to-end result on the first consumer

gerchowl/filesender@chore/adopt-devkit (59c5adc) now consumes this branch: ~120 lines of hand-rolled crane/fenix wiring deleted, replaced by one mkRustProject call, crane and fenix dropped as inputs there.

nix flake check green on all nine checks — cli, mcp, filesender-cli, filesender-mcp, clippy, fmt, nextest, doc, deny — locked against this pushed branch, not a local path override.

The doc check earned its place on the first run

filesender had no rustdoc check. The one the pack brings (cargo doc with RUSTDOCFLAGS=--deny warnings) failed immediately on two ambiguous intra-doc links: sign is both a module and a re-exported function, so [`sign`] and [`crate::sign`] resolved to neither. Nothing else in that repo's suite looks at rustdoc, so the links had been broken for as long as they existed. Fixed with mod@ in the consumer.

One check, one real defect, first execution. That is the argument for the check suite travelling with the toolchain rather than being left to each repo.

Tests

uv run pytest tests/test_flake_modules.py -k "rust or mk_rust" — 9 passed (144s), run independently of the agent that wrote them.

Related

Filed #1430 — a fresh git clone of devkit does not enforce devkit's own branch-name and Refs: rules until scripts/init.sh sets core.hooksPath. Found the hard way while making this PR; two non-conforming commits of mine went through before the hooks happened to become live.

85% of what crane+fenix cost a downstream consumer was one transitive
input devkit never chose. fenix pulls the rust-analyzer SOURCE TREE to
build its *nightly* rust-analyzer derivation — which this pack never
touches, because fromToolchainFile takes its components from the
release-channel manifest instead.

Following it to nixpkgs removes the node outright rather than replacing
it, since every consumer already has nixpkgs. Lock nodes 15 -> 14,
fetched source ~33 MB -> ~5 MB.

Verified rather than reasoned about, because the obvious worry is that
this breaks the rust-analyzer component: built a toolchain from
filesender's rust-toolchain.toml (which lists rust-analyzer) with the
follows in place, and result/bin contains rust-analyzer alongside cargo,
clippy, rustfmt and rustc. filesender's full nix flake check stays green
on all nine checks.

Measured while spiking #1440, which also corrected a claim I had made
about what these inputs cost. Deleting an unreferenced 20.8 MB input from
the store and re-running each operation shows nix eval, flake show, flake
check, flake metadata, develop and build all leave it absent; only flake
archive and re-locking fetch it. So the recurring cost of a shared input
is confined to nix flake update, not to everyday consumer operations.
That measurement is on Nix 2.34.7+1 with fetch-tree and no lazy-trees;
another Nix may differ, and CI images should be re-measured.

This lands the part of #1440 that every reviewer agreed on regardless of
how the larger question goes. Whether crane and fenix belong in devkit at
all is still open there.

Refs: #1440
@gerchowl

Copy link
Copy Markdown
Contributor Author

Second consumer: gerchowl/squelch — a single-crate library

Adopted this branch on a repo deliberately unlike filesender: one library crate, no binaries, no workspace, heavily feature-gated (browser/logs default; gh-cli, endpoint, serde optional). Wired from scratch — no prior crane/fenix to delete — so this is the cold-start path rather than the migration path.

End state: nix flake check green on all five checks (fmt, clippy, nextest, doc, workspace) plus packages.default, locked against the pushed branch.

Getting there took two blockers, and both were things the pack could say out loud.


1. rust.devShell does not evaluate without devkit.overlays.default — but the checks do

The README snippet in this PR says inherit pkgs, unqualified. A consumer's natural reading is their own nixpkgs:

pkgs = import nixpkgs { inherit system; };

which yields:

error: undefined variable 'vig-utils'
       at .../nix/devtools.nix:36:21
          36|   (pkgs.lib.lowPrio vig-utils)

An error inside devkit, naming a variable the consumer has never heard of, from a file they did not open. The fix is overlays = [ devkit.overlays.default ], which is documented in docs/NIX.md for mkProjectShell but is not in this PR's usage snippet — and mkRustProject is the entry point that is supposed to mean you don't have to know about mkProjectShell.

The part worth fixing rather than documenting: checks and packages evaluate fine without the overlay, because they never touch mkProjectShell. So the failure mode is a repo whose nix flake check is green and whose nix develop is broken. That is the same split-brain the pack exists to close, one layer up.

Suggestion: mkRustProject knows whether the pkgs it was handed carries the overlay (pkgs ? vig-utils). A throw in mkRustProject's own voice — the toolchainHash error is the model, it is genuinely the best error in the codebase — costs one if and removes the whole class.

2. A library that gitignores Cargo.lock is dead on arrival, and cargoVendorDir is unreachable

squelch's .gitignore had Cargo.lock — the long-standing library convention, and what cargo new --lib produced for years. A flake's src = ./. is the git tree, so the lock was simply absent from cleanSrc, and five of six derivations failed at eval:

error: unable to find Cargo.lock at /nix/store/…-source

crane's message is good and names git add -N Cargo.lock. Two things the pack adds on top:

  • The other two remedies crane suggests are unreachable. mkRustProject has no cargoVendorDir argument, and crateOverrides only reaches buildPackage — not buildDepsOnly, cargoClippy, cargoNextest or cargoDoc. A consumer who genuinely cannot commit a lock has to abandon the function and rebuild it from the exposed craneLib/commonArgs.
  • fmt passes anyway — it is the one check that takes only src. Check one thing first and you see green.

Same suggestion: builtins.pathExists (src + "/Cargo.lock") and a throw that says why a library repo in particular hits this. It is a one-line guard for a failure that reads as "the pack doesn't work" rather than "your lockfile isn't staged".


3. Nothing runs doctests — #1400 promised they would

The stage table in #1400 says pre-push carries nextest + cargo test --doc. This PR ships cargoDoc (rustdoc lints, -D warnings) but nothing executes doctests, and nextest cannot by design.

squelch has three executing doctests, including the provenance! macro example, which is the crate's main API surface. Adopting the pack removes them from CI, silently, on a repo where cargo test ran them.

crane already ships lib/cargoDocTest.nix. This looks like one more lib.optionalAttrs block beside doc.

4. Default features only, and no supported way to widen

tests run
cargo test --all-features (squelch's actual suite) 59
cargo test (default features) 55
the pack's nextest 55

Plus 0 of 3 doctests, per §3 — so 55 of 62 signals.

The four missing tests cover gh-cli, endpoint and serde, and more importantly clippy never compiles that code at all. For a crate whose README sells default-features = false, the pack's green is narrower than the repo's own cargo test — and nothing says so.

clippyExtraArgs exists, but there is no features / cargoExtraArgs knob reaching buildDepsOnly, nextest, doc or the package builds.

What works today, found by reading the source rather than the docs:

buildEnv = { cargoExtraArgs = "--all-features"; };   # → 59 tests run

buildEnv is documented as "For CMAKE_*, PKG_CONFIG_PATH, etc." but is merged verbatim into commonArgs, so it is a general crane override wearing an env-var name. It works, it is the only seam, and it is the kind of thing that gets removed in a refactor because the docstring says it holds env vars. Worth either promoting to a real cargoExtraArgs/features argument, or renaming what it is.

(Note it would also collide with buildCrate's own cargoExtraArgs = "-p ${name}" on a workspace — squelch is single-crate so it did not bite here.)


Claims I checked, which held

  • "3 leaf lock entries." Exact. origin/dev 11 nodes → this branch 14: crane, fenix, rust-analyzer-src. flake-utils/systems were already there.
  • The bare-module refusal fires, and the message is the right length and says the right things. It cost me nothing in practice — I only hit it by deliberately testing it.
  • toolchainHash = fakeHash → build prints the real hash → paste → works, first try. The error text explaining why there is no sensible default is why it took thirty seconds instead of a search.
  • The doc check found real defects on first execution, exactly as it did on filesender. Two broken intra-doc links in squelch's main, both pointing at endpoint-gated items from ungated docs (crate::Auth::Dynamic, Transport::Endpoint) — so they were broken for every default-features reader. Nothing else in the repo's suite looks at rustdoc. Fixed in the consumer.

Answers to the three review asks

  1. crane + fenix as devkit inputs — from a consumer's seat, keep them. Three entries is cheap, and the alternative is every Rust repo pinning its own fenix, which is per-repo drift on the exact axis devkit exists to hold still. The reversibility note in the PR (overrides exist) is the right safety valve.
  2. check-entries.nix — reads fine. A name-keyed override, small, with a comment stating the bar for adding one. The rust entry using checks = "none" is honest: the smoke check owns no source tree, which is precisely the sanctioned opt-out case.
  3. Is the eval refusal too aggressive? No — and I would say the opposite is the finding. The refusal never fired in normal use. The thing that actually cost me time was §1, which is silent and produces a half-working repo. Spend the aggression there.

Incidental confirmation of #1400's ask 3

The nix-detection false-negative is real and I hit it without looking for it: squelch is a single-flake.nix repo, so it is never nix-detected, never gets the nix .gitignore fragment, and the first nix build left an untracked result symlink in git status. Had to add /result + /result-* by hand. Every direnv-mode Rust consumer will do this, because a Rust pack repo is a single-flake repo by construction.

Two smaller notes

  • Darwin noise: building the fenix toolchain prints dozens of install_name_tool: command not found lines. The toolchain works, but on a first adoption it reads as a broken build for about a minute.
  • Shell weight: a pure-Rust library's nix develop carries the full devkit toolchain SSoT — podman, nodejs, uv, python3, ruff, pymarkdownlnt, bats, neovim, tmux, claude-code — ~45 packages, of which the Rust pack contributes 7. That is devkit policy rather than a pack bug, and it is the first thing a Rust-only consumer notices.

…c ratchet

Two pieces: the kit, and a gate that can hold a line without becoming
noise.

TOOL GROUPS. `tools` entries may now start with `@` and expand to a
curated set: @Perf (samply first — sampling profiler, no root, no
perf_events, works on both platforms, which makes it the 2026 default;
then flamegraph, hyperfine, criterion, bloat, llvm-lines, show-asm, and
heaptrack/valgrind/poop where they exist), @perf-async (samply,
tokio-console, hyperfine — for tiers whose stalls are awaits, not CPU)
and @api (semver-checks, expand).

A group SKIPS members this platform lacks; an explicitly named tool does
not. That asymmetry is the reason groups exist: asking for @Perf is
asking for this platform's kit, but naming heaptrack is a request that
can only be met or refused, and silently dropping it would hand someone
a shell missing the one tool they asked for. Without groups every
consumer writes the same `optionals isLinux` by hand and some get it
wrong.

THE RATCHET. checks.perf-ratchet, auto-enabled when
.repo/perf-baseline.toml exists — the same adopt-by-existing rule as
deny.

It times nothing, on purpose. Wall-clock benchmarks on shared CI runners
move more with neighbours and thermal state than with most real
regressions, and a gate that fires on noise is one people learn to
re-run until it passes. The pack ADR already says coverage is reported
and never gated; this is the same reasoning, harder, because a flaky
perf gate teaches --no-verify.

What it measures is deterministic given a locked toolchain and a locked
graph, so a change means a change: shipped binary size per binary, and
dependency-graph size read from Cargo.lock at eval. Neither needs anyone
to have authored a benchmark — which is the point, because a ratchet
nobody has to write is a ratchet that is actually in place. Repos doing
real performance work add criterion/divan benches and run them off the
CI critical path; @Perf is what puts that kit on PATH.

It is a ratchet, not a limit: growth past the tolerance fails, a
measured shrink is REPORTED so it can be banked, and the baseline is
committed so the diff shows who spent the budget. packages.perf-seal
emits the baseline file itself, so sealing is never hand-transcribed.

Verified by firing it, not by reading it. On filesender: sealed a
baseline (filesender 2672624 B, filesender-mcp 3629360 B, 220 crates),
confirmed the check goes green, then tightened the baseline and
confirmed REGRESS on both the binary (+33%) and the graph (+10%) while
the untouched binary stayed ok, with the build failing and the guidance
(cargo bloat / llvm-lines / tree --duplicates, then perf-seal) printed.
Three new tests cover group expansion contributing a non-identical
derivation, the explicit-unavailable throw, and the unknown-group throw;
the rust set is 12 passing.

Refs: #1400, #1440
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

Copy link
Copy Markdown
Contributor Author

Follow-up: the four findings above are now a PR against this branch — #1452 (feature/1450-rust-pack-consumer-hardening → feature/1400-rust-language-pack), tracked as #1450.

Two guards (overlay-less pkgs, missing Cargo.lock) and two additions (checks.doctest, cargoExtraArgs). Tests committed failing first; 16 pass on the rebased branch, including your new @perf group tests and the zero-module parity invariant.

Validated end-to-end on the consumer with --override-input: nix flake check green on 6 checks, with doctest executing the three doctests that no check ran before.

Take it or leave it — it is your branch, and the cargoExtraArgs-vs-buildEnv question in particular might be one you'd rather answer differently.

@gerchowl

Copy link
Copy Markdown
Contributor Author

Added: performance tooling + a ratchet, and the #1440 partial landing

1. rust-analyzer-src followed away (from #1440)

The one thing all four #1440 reviewers agreed on, landed independently of the open question there. Lock nodes 15 → 14, fetched source ~33 MB → ~5 MB.

It fed only fenix's nightly rust-analyzer derivation, which this pack never builds — fromToolchainFile takes components from the release-channel manifest. Verified by building filesender's toolchain (whose rust-toolchain.toml lists rust-analyzer) with the follows in place: rust-analyzer is still in result/bin.

Whether crane and fenix belong in devkit at all is still open in #1440 — this PR does not settle it. That question now has four reviews and a consolidated recommendation to move them out; I have held it because it is a convention call for the ADR owner, not mine.

2. Tool groups

tools entries may start with @:

group contents
@perf samply, cargo-flamegraph, hyperfine, cargo-criterion, cargo-bloat, cargo-llvm-lines, cargo-show-asm + heaptrack/valgrind/poop on Linux
@perf-async samply, tokio-console, hyperfine
@api cargo-semver-checks, cargo-expand

samply leads @perf because it is the 2026 default: sampling, no root, no perf_events, works on Linux and macOS.

A group skips members this platform lacks; an explicitly named tool does not. That asymmetry is the reason groups exist — asking for @perf is asking for this platform's kit, but naming heaptrack is a request that can only be met or refused, and silently dropping it hands someone a shell missing the tool they asked for. Otherwise every consumer hand-writes the same optionals isLinux and some get it wrong.

3. The ratchet — checks.perf-ratchet

Auto-enabled when .repo/perf-baseline.toml exists (same adopt-by-existing rule as deny). packages.perf-seal emits the baseline file itself, so sealing is never hand-transcribed.

It times nothing, on purpose. Wall-clock benchmarks on shared CI runners move more with neighbours and thermal state than with most real regressions, and a gate that fires on noise is one people learn to re-run until it passes. The pack ADR already says coverage is reported and never gated; this is the same reasoning, harder, because a flaky perf gate teaches --no-verify.

What it measures is deterministic given a locked toolchain and lockfile:

  • shipped binary size, per binary
  • dependency-graph size, read from Cargo.lock at eval

Neither requires anyone to author a benchmark — which is the point. A ratchet nobody has to write is a ratchet that is actually in place. Repos doing real performance work add criterion/divan benches and run them off the CI critical path; @perf puts that kit on PATH.

Growth past the tolerance (default 5%) fails; a measured shrink is reported so the win can be banked. The baseline is committed, so the diff records who spent the budget.

Verified by firing it, not by reading it

On filesender — sealed a baseline, confirmed green, then tightened it:

  REGRESS  binary/filesender = 2672624 bytes (baseline 2000000, +33%)
  ok       binary/filesender-mcp = 3629360 bytes (baseline 3629360, 0%)
  REGRESS  graph/crates = 220 crates (baseline 200, +10%)

Build fails, guidance prints (cargo bloat / llvm-lines / tree --duplicates, then re-seal). Both directions covered — fires on bad, quiet on good.

Three new tests (group expansion produces a non-identical derivation; explicit-unavailable throws; unknown group throws). Rust set: 12 passing. filesender: 10 checks green against this pushed branch.

One more find in the consumer

Restating tools surfaced that llvm-cov was never in filesender's dev shell, while just test-cov has always named it — it would have died on "command not found" the first time anyone ran coverage. Sixth instance in that branch's history of configured-referenced-absent. Every binary its justfile names now resolves inside nix develop, checked by running the resolution rather than reading the list.

…1452)

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
gerchowl added a commit to gerchowl/squelch that referenced this pull request Aug 12, 2026
Both targets exist only under the `endpoint` feature, so `cargo doc` on a
default build reported them as unresolved — meaning the links were broken
for every reader who was not building with all features.

Found by the rustdoc check in devkit's Rust language pack (vig-os/devkit#1429)
on its first execution against this repo; nothing in the existing suite
looks at rustdoc.
gerchowl added a commit to gerchowl/squelch that referenced this pull request Aug 12, 2026
Wires vig-os/devkit#1429's `lib.mkRustProject`: one call yields the dev
shell, the checks and the package. `nix flake check` covers fmt, clippy,
nextest, rustdoc and the crate build.

Three repo changes the pack requires, each load-bearing:

- Cargo.lock is now tracked. A flake's source is the git tree, so an
  ignored lock is absent inside the build sandbox and every crane
  derivation fails to vendor. Committing it is also current Cargo
  guidance for libraries.
- rust-toolchain.toml pins the compiler; fenix resolves it so nix and a
  local rustup agree. toolchainHash is its content hash and moves with it.
- /result is ignored — devkit does not detect a single-flake repo as a
  nix consumer, so its gitignore fragment never arrives (devkit#1400).

`buildEnv.cargoExtraArgs = "--all-features"` is a workaround, not the
intended seam: mkRustProject has no feature knob, and without it the
checks build default features only — 55 of 59 tests, with the gh-cli,
endpoint and serde code never compiled and so never linted.
…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
@gerchowl

Copy link
Copy Markdown
Contributor Author

Reviewed #1452 — merged, plus two follow-ups

Reviewed by running it rather than reading it. All four findings are legitimate; §3 (doctests) is a regression I shipped, and the catch is a good one — I knew nextest can't run doctests (it's written in filesender's justfile, in a comment explaining why just test needs two commands) and then built a pack that dropped them anyway. That is exactly the shape of thing a second consumer finds and the author cannot.

Verified independently:

  • the pinned crane does expose cargoDocTest
  • filesender's check set is now 11, with doctest present and executing — zero doctests there, so vacuous on this consumer, live on squelch's three
  • rust suite 16 green on the merged branch; nix flake check green on filesender

Follow-up 1 — the overlay guard needed its other half

The guard is right and the error is the best kind. But hasOverlay = pkgs ? vig-utils is a proxy: it infers "the overlay was applied" from one package name. 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 this branch's own rule turned on the branch: a gate is unverified until it has fired on known-bad input and stayed quiet on known-good. test_mk_rust_project_dev_shell_evaluates_with_the_overlay is the second half, and it fails the day the sentinel stops tracking what it stands for.

Follow-up 2 — buildEnv → craneArgs

You were right to leave this to me, and right about what it was. It is now craneArgs, documented as what it actually is: raw attrs merged last into every crane derivation, beating everything above them. buildEnv stays accepted as a deprecated alias so squelch's flake keeps evaluating — merged after craneArgs, on the reasoning that anyone still passing the old name means it. Both covered by a test.

Rust suite now 19 green. Pushed as bf32716.

On your answer to review ask 1

Noted on #1440 — you are the fifth opinion and you land opposite my consolidation there, which recommended moving crane/fenix out on ecosystem-convention grounds (git-hooks.nix, treefmt-nix, crane itself and dream2nix all carry zero language-toolchain inputs). Yours is the only one of the five from an actual consumer seat, which is the seat that pays, so it counts for more than the count suggests. Left open for the ADR owner either way. The 28 MB rust-analyzer-src is already gone regardless — 33 MB → ~5 MB, lock nodes 15 → 14.

Three of yours I have not actioned

  • nix-detection false-negative — confirms Rust language pack — and reconciling devkit with gerchowl/guardrails #1400 ask 3 from a second angle, and your framing is the useful part: every Rust pack repo is a single-flake.nix repo by construction, so this is systematic rather than incidental. Belongs in devkit's detection, not the pack.
  • Darwin install_name_tool noise — upstream fenix/nixpkgs, worth an issue but not one I can fix here.
  • Shell weight (~45 packages for a pure-Rust library, 7 from the pack) — devkit policy. The most interesting thing on your list for whoever owns the toolchain SSoT, and it deserves its own issue rather than a line in this thread.

Both sides appended to CHANGELOG's Unreleased/Added block, so the
conflict is textual only and both sets of entries are kept. The
.devcontainer mirror is regenerated from the resolved file rather than
resolved by hand, since sync-manifest owns it.

Refs: #1400
@gerchowl
gerchowl marked this pull request as ready for review August 12, 2026 16:32
@gerchowl
gerchowl enabled auto-merge August 12, 2026 16:33
CI's Project Checks gate failed on checks.statix: three dotted `fenix.*`
keys in `inputs` trip "avoid repeated keys in attribute sets". The
existing inputs use the dotted form with only two keys each, which is
under whatever statix tolerates; adding the rust-analyzer-src follows
made it three. Rewritten as a single attrset, comments intact.

Found by CI rather than locally because I had verified with
`nix flake check --no-build`, and statix is a check that must BUILD to
say anything. That is this branch's own lesson landing on me: a gate
that is configured and not executed reports nothing, and `--no-build` is
a way to not execute one while believing you ran the suite. Verified
here with a full `nix flake check` — all checks passed, lock unchanged
at 14 nodes.

Refs: #1400
@gerchowl
gerchowl merged commit c7bd3ac into dev Aug 12, 2026
14 checks passed
@gerchowl
gerchowl deleted the feature/1400-rust-language-pack branch August 12, 2026 17:06
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