Design hermetic, cacheable nix flake checks for comprehensive repository validation. Covers 8-category check taxonomy, flake-parts modules, pure derivations, nix-unit invariants, NixOS VM tests, evaluation cost, and check gating.
Ships in preferences-nix-and-secrets. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill covers the design of hermetic, cacheable nix flake checks that validate a repository across its full surface area. The approach treats every check as a pure nix derivation, composable through flake-parts modules and distributable across CI workers.
Eight canonical categories classify the validation surface of a nix-based repository. Each category targets a distinct failure mode and has characteristic cacheability properties. The categories are ordered roughly by cost: earlier categories are cheaper to run and should fail fast, while later categories are more expensive and validate deeper properties.
Format covers treefmt-equivalent enforcement of code formatting. Formatters run as a single derivation that fails if any file would be reformatted. This catches whitespace, import ordering, and style drift before any semantic analysis. Formatting checks are typically the fastest to run and should be the first to fail in a pipeline, since formatting violations are trivial to fix and indicate the contributor has not run the formatter locally.
Secrets-scan covers gitleaks-equivalent detection of leaked credentials, API keys, and tokens in source files. The derivation wraps a scanner tool over the full source tree, so it invalidates on any source change. Unlike most other categories, secrets scanning has no language-specific variant; a single gitleaks derivation covers the entire repository. The cost of a false negative (leaked credential) is severe enough that running this check on every change, despite its full-tree cache invalidation, is warranted.
Lint covers language-specific static analysis beyond formatting: clippy for Rust, ruff for Python, eslint or biome for JavaScript/TypeScript. Linters catch correctness issues, unused imports, suspicious patterns, and style violations that formatters do not address. The distinction between formatting and linting matters for cacheability: a formatting check depends on source text layout, while a lint check depends on semantic content. Changing a comment may invalidate the formatter but leave the linter cached.
Type-check covers static type system validation: cargo check for Rust, basedpyright for Python, tsc --noEmit for TypeScript.
Python type checking uses basedpyright rather than mypy.
Wrapping basedpyright as a nix derivation requires running it inside a uv2nix-built virtual environment so that all type stubs and dependencies are available.
Type checking is typically more expensive than linting but cheaper than running tests, and it catches a different class of errors: interface mismatches, missing fields, incorrect return types, and violations of type-level invariants.
Unit-test covers workspace-level and per-package test suites: cargo nextest, pytest, vitest.
For Python, wrapping pytest as a nix check similarly requires the uv2nix virtual environment.
Per-crate or per-package isolation via lib.genAttrs allows targeted debugging without running the full workspace suite.
Unit tests provide the highest ratio of confidence-per-second for behavioral correctness: they exercise code paths with controlled inputs and assert on outputs.
When designing check derivations for unit tests, the granularity decision (one derivation per workspace vs one per package) trades debugging convenience against build system overhead.
Integration/e2e covers end-to-end validation: Playwright browser automation, NixOS VM tests, multi-service integration tests.
These checks tend to be the most resource-intensive and have the longest runtimes.
NixOS VM tests require kvm and nixos-test sandbox features.
Integration tests validate properties that unit tests cannot: cross-service communication, database migrations, browser rendering, and system-level behavior.
The cost of running these checks means they are often fan-out candidates for CI distribution rather than local nix flake check targets.
See references/nixos-vm-tests.md for the full framework.
Nix-infrastructure covers nix-unit tests on flake structure and declarative invariants.
These validate properties like "every package has a corresponding check" or "all machines in the fleet have consistent naming conventions."
Infrastructure invariants are unique among the categories because they test the build system itself rather than the software it produces.
They are cheap to evaluate (pure nix expression evaluation, no building) and catch structural drift that would otherwise go unnoticed until a deployment fails.
See references/nix-unit-invariants.md for the test case template and design pattern.
Build/eval covers the actual package derivations.
A successful nix build is itself a check that the derivation graph is well-formed and all build phases complete.
nix flake check evaluates all checks and packages for the current system.
Build checks are implicit: every derivation in the packages output is a build check.
Evaluation checks (via nix flake check or nix eval) validate that the nix expression graph is well-formed without building, catching infinite recursion, missing attributes, and type errors in module options.
When a category does not apply to a repository, N/A is a valid and authorized state. Do not manufacture speculative future coverage for categories that have no current relevance. A Rust-only project has no Python type-check category. A library with no network services has no NixOS VM test category. Recording N/A explicitly communicates that the absence is intentional rather than an oversight.
Three target-state values classify how a check derivation integrates with the build pipeline. These values are not mutually exclusive in all combinations, and understanding their composition is necessary for designing checks that work correctly in both local and CI contexts.
flake-check-native means the derivation runs under nix flake check.
This is the default for checks that are pure, hermetic, and reasonably fast.
The derivation appears in checks.<system>.<name> and evaluates alongside all other flake checks.
Local development uses nix flake check as the primary validation command, so flake-check-native checks form the core feedback loop.
The tradeoff is that nix flake check evaluates all checks sequentially on a single machine, so expensive checks slow the entire pipeline.
fan-out means the derivation is exposed as a separate attribute for parallel execution.
Tools like nix-fast-build and buildbot-nix can distribute fan-out checks across workers, evaluating and building each independently.
Fan-out checks still appear under checks.<system> but are designed for granular scheduling rather than monolithic evaluation.
nix-fast-build evaluates derivations in parallel and distributes builds across remote builders, making it the natural choice for CI pipelines with multiple workers.
buildbot-nix goes further by evaluating the flake once, then scheduling individual derivation builds as independent buildbot steps with their own status reporting and retry logic.
effect means the operation has side effects: deploying, publishing, pushing artifacts, or mutating external state.
Effect operations never belong in nix flake check because they are not hermetic and their success depends on external state.
Deployment scripts, cache uploads, container registry pushes, and notification triggers are all effects.
They run in CI pipelines as post-check steps gated by the success of pure checks, but they are not themselves checks, and each must first earn its place as preferences-nix-ci-cd-integration §Effect execution strategies requires.
flake-check-native and fan-out compose naturally.
A check can be both: it runs under nix flake check locally and fans out in CI.
effect is mutually exclusive with both because side effects break the purity contract.
The composition table is straightforward: a derivation that is both flake-check-native and fan-out runs locally via nix flake check and in CI via nix-fast-build or buildbot-nix.
A derivation that is fan-out only (not flake-check-native) is too expensive for local runs but still distributes in CI.
This is appropriate for NixOS VM tests and Playwright e2e tests that require specialized hardware or take minutes to complete.
Every check must be a pure nix derivation: cacheable, reproducible, and content-addressed.
No impure wrappers around shell scripts.
Even security scanners like gitleaks run as pkgs.runCommand derivations that take the source tree as input and fail the build if violations are detected.
The pre-commit check anti-pattern illustrates why purity at the individual check level matters.
A monolithic pre-commit.check derivation bundles formatting, linting, and scanning into a single derivation.
When any source file changes, the entire pre-commit derivation invalidates and reruns all bundled checks from scratch.
The bundled derivation cannot cache intermediate results because it is a single build step.
Setting pre-commit.check.enable = false and running treefmt, gitleaks, and linters as independent check derivations yields finer cache granularity.
If only a Rust file changed, the treefmt check for Rust invalidates while the Python lint check (which depends only on Python source files via source filtering) remains cached.
The gitleaks check invalidates because it depends on the full tree, but it runs independently and does not force the linter to rerun.
Independent derivations also produce independent build logs, making failures easier to diagnose: a CI log that says "gitleaks-check failed" is immediately actionable, whereas "pre-commit-check failed" requires reading the log to determine which bundled tool failed.
Beyond cacheability, independent derivations enable fan-out scheduling. CI systems can distribute independent check derivations across multiple workers, running them in parallel. A monolithic pre-commit derivation forces serial execution of all bundled tools on a single machine.
See references/derivation-patterns.md for per-category derivation recipes.
The derivation purity principle and the source filtering that follows it optimize what gets rebuilt. This section optimizes what gets evaluated, which is a separate resource with a separate failure mode. A cached derivation costs nothing to build, but its expression is still evaluated on every PR, for every attribute, on every system, whether or not anything changed. In a fleet repository evaluation is therefore the binding constraint: the build side is mostly cache hits, and the evaluator pays in full every time.
The cost in this repository was measured rather than assumed.
CI evaluated 311 check attributes at about 92 GiB of evaluator allocation and about 400 s on a 16-vCPU, 30.6 GiB host.
Two corrective PRs brought it to 235 attributes, about 45 GiB, and about 218 s, and removed no coverage anyone wanted.
Nothing in the check suite had treated evaluation as costed, so each addition looked free and the total degraded silently.
The rules below are the constraints whose absence allowed that.
See references/evaluation-cost.md for the measurement protocol, the benchmark discipline, and the drvPath-identity oracle that any evaluation refactor must pass.
Nix attribute sets are lazy in their values and strict in their keys.
Computing the attribute names of checks.<system> forces every expression those names depend on, for every check module, before any single check can be selected.
An evaluator that wants one check therefore pays for the key set of all of them, and nix-eval-jobs pays it in every worker.
The rule follows directly: a check module's key set must depend only on static data.
Static data means literals, the system string, clan inventory metadata, and flake-level lib values such as self.lib.machineSystems.
It never means evaluated NixOS, nix-darwin, or home-manager configurations, an instantiated pkgs, or package passthru, because each of those forces a module-system fixpoint or a nixpkgs instantiation just to learn a name.
A predicate that needs a configuration belongs in the check's lazy value, as an assert inside the derivation expression or as a build-time comparison, never in its key set and never in the condition that gates whether the attribute exists.
modules/checks/zerotierone-controller.nix is the measured instance.
Its key set was derived from six evaluated machine configurations, filtering for those whose zerotier package diverged from pkgs.zerotierone:
# before (shape): names depend on evaluated configurations
checks = lib.mapAttrs' (name: m: lib.nameValuePair "zerotierone-controller-${name}" m.config.services.zerotierone.package) (
lib.filterAttrs (_: m: m.config.services.zerotierone.package.drvPath != m.pkgs.zerotierone.drvPath)
self.nixosConfigurations
);
The fix keys the attributes on the inventory role and moves the divergence predicate into the value, where it is evaluated only when that one check is:
# after: names depend on inventory metadata; the predicate is an assert in the value
controllers = lib.filter (name: self.lib.machineSystems.${name} == system) (
builtins.attrNames self.clan.inventory.instances.zerotier.roles.controller.machines
);
checks = lib.listToAttrs (map (name: lib.nameValuePair "zerotierone-controller-${name}" (
let machine = self.nixosConfigurations.${name}; in
assert lib.assertMsg (machine.config.services.zerotierone.package.drvPath != machine.pkgs.zerotierone.drvPath)
"controller ${name} no longer diverges from pkgs.zerotierone";
machine.config.services.zerotierone.package
)) controllers);
Before the fix, evaluating the drvPath of a trivial unrelated check cost about 934 MiB and 3 s, all of it spent computing names. After it, the same attribute costs 89 MiB and 0.27 s. The assertion still fails loudly if clan stops overriding the controller's package, so the change lost no failure mode; it only moved the work from every evaluation to the one that needs it.
config; it reads committed data or registry data, such as the host registry or clan inventory metadata, because each such read evaluates the other configuration inside this one.share = true) or committed data, never through reading another host's configuration or the members of another role.fleetObligations, modules/lib/fleet-obligations.nix), which the existing machine checks judge, rather than adding check attributes, so the key set stays static.Stock nix-eval-jobs forks a pool of evaluator workers and recycles any worker whose heap exceeds --max-memory-size.
Each fresh worker re-loads the flake and recomputes every strict prefix, including the key set, before it evaluates its first attribute.
Any cost incurred before the first attribute is therefore paid once per worker per restart, not once per run.
The zerotier key set above was paid about 26 times per CI run for this reason, which accounts for roughly 25 GiB of the original 92 GiB.
A fixed cost that looks negligible in a single nix eval multiplies by the restart count in CI, and restarts are themselves driven by allocation, so the two compound.
An evaluator that ignores the limit, as iets does on macOS, never restarts its workers: it pays the prefix once per worker, and its workers grow with everything they evaluate instead.
Instantiating nixpkgs is not free: each instantiation costs about 40 MiB and 0.1 to 0.2 s of evaluation before anything is built.
This repository had about 29 instantiations, one per machine, home, and probe, where four (one per system) suffice.
The package set must be instantiated once per system and consumed by machines and homes through nixpkgs.pkgs, not re-imported per configuration.
preferences-nix-development documents the mechanism and the hard constraint that applies when an upstream input instantiates its own nixpkgs.
A check whose derivation would be identical on every system belongs to exactly one system, gated with lib.optionalAttrs (system == "x86_64-linux").
Structural checks over inventory, configuration values, or repository files are of this kind, and the modules under modules/checks/structure/ and most of modules/checks/ are gated this way.
A check whose derivation genuinely differs per platform must stay per system: packages, dev shells, built executables, and NixOS or home-manager module branches gated on platform all produce different derivations and can fail independently.
Both error directions are real. Needless duplication evaluates the same expression once per system and buys no evidence for any of the repeats, which in a four-system flake is a fourfold tax on that check's evaluation. Wrongly dropping a platform is worse in kind: a real platform goes unverified, and the gap is invisible because the remaining systems pass. The decision is made by asking whether the derivation's inputs differ by system, not by asking where it is convenient to run.
Standalone home-manager configurations are checked once per platform archetype, plus any user not already evaluated inside a host of that system. A user whose home is already built as part of a NixOS or nix-darwin toplevel on that system is already covered by the machine check, and a standalone evaluation of the same user on the same system repeats the module fixpoint without new evidence. Aliases of the same user, such as a second username pointing at the same module set, are not separate evidence and are not checked separately.
Derivation hashes should change only when semantically relevant source content changes. Source filtering is the primary mechanism for achieving this.
builtins.path with a fixed name parameter produces content-addressed store paths.
Without a fixed name, the store path includes the filesystem path, causing unnecessary rebuilds when the checkout location changes.
A developer checking out the same repository to /home/alice/project and /home/bob/project would get different store paths for identical source content.
The filter parameter excludes files irrelevant to the derivation (documentation, tests, CI config) so that changes to those files do not invalidate the build cache.
A well-designed filter is the single most impactful optimization for check cacheability because it determines which changes trigger rebuilds.
crane.filterCargoSources applies Rust-specific filtering: it includes *.rs files, Cargo.toml, Cargo.lock, and build scripts while excluding tests, benches, and examples.
This is the standard filter for crane-based Rust builds.
Combining crane.filterCargoSources with builtins.path (for the fixed name) is the idiomatic pattern: builtins.path { path = craneLib.filterCargoSources ./.; name = "rust-source"; }.
lib.fileset.toSource combined with lib.fileset.unions provides fine-grained file set composition for JavaScript packages and other ecosystems.
You declare exactly which files and directories constitute the source, and the resulting store path reflects only those contents.
This is more explicit than builtins.path with a filter function because the inclusion list is declarative rather than imperative.
Adding a new file type to the project requires adding it to the union, which is a visible code change rather than a silent filter rule.
Lockfile-based dependency fetchers like bun2nix.fetchBunDeps and uv2nix workspace loading derive their store paths from lockfile contents.
When the lockfile does not change, the dependency fetch is a cache hit regardless of source changes.
This separation of dependency resolution from source compilation is the foundation of the two-phase build pattern used across all language ecosystems.
Several patterns allow expensive intermediate artifacts to be computed once and shared across multiple checks.
Crane's buildDepsOnly produces a single compiled-dependencies artifact that cargoClippy, cargoNextest, and buildPackage all share.
Compiling dependencies is the most expensive phase of a Rust build, and sharing this artifact across clippy, tests, and the final build avoids tripling the compile time.
The artifact is keyed on Cargo.toml and Cargo.lock contents, so adding a source file or changing implementation code does not trigger dependency recompilation.
Only adding, removing, or updating a dependency invalidates this artifact.
The passthru.tests pattern attaches test derivations to a package.
A package's passthru.tests.unit and passthru.tests.e2e attributes are derivations that can be referenced from the flake's checks output.
This keeps the test definition co-located with the package while exposing it for CI.
The pattern supports the relational invariant from nix-unit: TC-006 can verify that every package's passthru.tests attributes are wired into the checks output.
Per-crate isolation via lib.genAttrs generates one check derivation per crate in a workspace.
This allows debugging a single failing crate without rebuilding or retesting the entire workspace.
The per-crate derivations share the same buildDepsOnly artifact.
In CI, per-crate derivations enable finer-grained fan-out: if only one crate's source changed, only that crate's tests need to rebuild.
See references/derivation-patterns.md for concrete nix expression skeletons.
Beyond testing that individual derivations build successfully, nix-unit can enforce structural relationships between flake outputs. Structural invariants operate at the meta-level: they test the shape of the build system rather than the behavior of the software it produces.
The canonical example is the TC-006 pattern: every package in packages.<system> has a corresponding entry in checks.<system>, enforced by a nix expression that enumerates both attribute sets and asserts coverage.
An explicit exclusion list documents packages that intentionally lack a check (the default alias, release meta-packages, per-crate test derivations that are themselves checks).
The exclusion list is itself a reviewable artifact: adding a package to it requires a justification comment, which means the decision to skip test coverage is deliberate and visible in code review.
Structural validation extends to other flake output relationships. Does every system have a devShell? Is a formatter configured? Do infrastructure-specific outputs (machine configurations, deployment specs) satisfy naming conventions? For declarative infrastructure repositories like vanixiets, invariants validate clan inventory consistency, secrets tier separation, and machine registry completeness, properties that are not exercised by building any single package.
The value of invariants is highest for cross-cutting relationships between independently-defined outputs. If a property is guaranteed by the nix module system's type checking, an invariant test is redundant. If it depends on conventions that the type system cannot enforce, an invariant catches drift. A practical heuristic: if two developers can independently add outputs that should be related (a package and its test, a machine config and its inventory entry), an invariant ensures the relationship holds.
A recurring instance of this drift-catching role guards schema-driven codegen of any kind — LinkML, sqlc, protobuf, or openapi — through two general checks: a codegen drift check that regenerates the bindings from their source schema and diffs against the committed output, and a schema-conformance property test asserting that the generated schema round-trips the producer's own serializations.
Both guard the schema-factored leg of the lowering-path bifurcation defined in preferences-data-modeling, whose spec-anchored instantiation is nucleus-platform; the schema-language-specific machinery lives there and does not enter the eight-category taxonomy.
See references/nix-unit-invariants.md for the full test case template and guidance on when invariants add value.
NixOS VM tests run full virtual machines with real systemd services, network stacks, and multi-machine topologies. They are appropriate for validating NixOS module interaction, service lifecycle, network configuration, and multi-machine coordination. The decision to use a VM test rather than a pure derivation check should be deliberate: VM tests are the right tool when the property under test requires a running init system, real network connectivity between services, or multi-machine coordination.
VM tests require kvm and nixos-test sandbox features and are significantly more resource-intensive than pure derivation checks.
A single VM test boots one or more QEMU virtual machines, each running a full NixOS system with systemd, networking, and the configured services.
Multi-machine tests use VLANs implemented via vde_switch for network isolation, enabling tests of client-server architectures, mesh networks, and distributed systems.
The test framework provides a Python driver API for interacting with VMs. The driver communicates with each VM through a virtio-console backdoor rather than the network, so test commands work even when the VM's networking is misconfigured. Common operations include waiting for systemd units, asserting on command output, transferring files, and taking screenshots for debugging.
Properties that benefit from VM testing include NixOS module correctness (does enabling a service produce the expected systemd units and firewall rules?), multi-service integration (does the reverse proxy correctly route to backend services?), secrets decryption (do sops-encrypted secrets decrypt correctly during system activation?), and network topology (do VPN mesh nodes discover each other?).
Properties that do not benefit from VM testing include pure function behavior, data transformation logic, and CLI tool output, all of which are better served by unit-test or build/eval checks.
clan-core extends the framework with shared test runners, container-based alternatives to QEMU for lighter weight testing, helpers for secrets and evaluation-only checks, and VM image minification for faster boot times.
See references/nixos-vm-tests.md for the complete framework architecture, driver API, debugging workflow, and clan-core extensions.
Before writing or reviewing a VM or container test, follow the practice checklist in references/nixos-vm-tests.md §Practice checklist: container first, conditions instead of sleeps, systems built on the host rather than evaluated in the guest, signed caches with validity judged by the guest's Nix database, and a reference test to copy for each common scenario.
Within the integration/e2e category, three regulator kinds cover overlapping but distinct envelopes, and a fourth narrower kind (pure derivation checks) sits below them on the cost ladder but is not strictly an integration regulator.
Selecting among them is a question of operating envelope rather than convenience or familiarity.
The CCV framing in preferences-compositional-continuous-verification treats each regulator as a pair of an operating envelope and a verification rule; the right regulator for an artifact is the one whose envelope matches the artifact's deployment shape.
Process-compose is the regulator kind for the application-composition envelope. Services start in dependency order on the developer's host, bind ports, and answer readiness probes, but there is no systemd, no NixOS module evaluation, and no kernel namespace isolation beyond what the host already provides. The regulator runs on Darwin and Linux developer machines, requires no special sandbox features, and produces results in seconds.
Nspawn container tests (clan-core's clan.test.useContainers = true, which is the default for clan tests) are the regulator kind for the service-on-NixOS envelope.
The artifacts under test are real systemd units evaluated through the NixOS module system; the test runs them under systemd-nspawn against the host kernel.
The regulator is Linux-only and requires container sandbox access, but it is markedly cheaper than full QEMU and covers most properties that depend on systemd ordering, NixOS module behavior, or secrets activation under clan-vars or sops-nix.
Full QEMU NixOS tests (pkgs.testers.runNixOSTest, or clan's useContainers = false) are the regulator kind for the NixOS-module-plus-kernel envelope.
This is the only regulator that exercises kernel features or kernel modules, TUN/TAP devices, the boot sequence, disks or other QEMU devices, systemd namespacing options, specialisation switching, setuid binaries, and VMs mixed with containers; containers share test VLANs too, so a multi-machine topology alone does not need it.
It requires kvm and nixos-test sandbox features and pays for that capability in build time.
Pure derivation checks are the narrower fourth kind: they sample pure-function correctness, CLI output, transformations, and any property that can be asserted in a single-process sandbox. They are not integration regulators in the same sense — they do not run a composition of services — but they are the cheapest evidence at the bottom of the escalation ladder.
The decision rules are escalation rules.
Start at process-compose if the artifact under test is genuinely host-process-shaped or if its deployment shape is not yet decided; the eval-gate variant of process-compose (checks.X = self'.packages.X) is a legitimate but limited regulator that asserts configuration well-formedness without exercising runtime behavior.
Promote to nspawn when the artifact will be deployed as a systemd service on NixOS, when secrets activation under clan-vars or sops-nix is part of the envelope, or when systemd ordering between services is part of what is being asserted.
Promote to full QEMU only when the test needs kernel features or kernel modules, TUN/TAP devices (tincr, zerotier), the boot sequence, disks or other QEMU devices, systemd namespacing options (ProtectSystem=, MountAPIVFS=), specialisation switching, setuid binaries, or VMs mixed with containers; otherwise a test of a NixOS system, multi-machine ones included, is a container test.
The choice is not exclusive across a project.
A single artifact can appear in process-compose (for the developer loop on every change), in an nspawn container test (for the merge-gate check at PR time), and in a full QEMU test (for the multi-machine integration check that runs less often).
Each regulator samples a different envelope, and the same artifact passing all three is stronger evidence than passing any one of them.
The CCV closure operator composes them automatically when each is exposed in checks.<system>.
Cost and cacheability profile follows envelope size.
Process-compose eval-gate checks build in seconds and cache cheaply; executed process-compose tests are harder to make hermetic and accordingly less cache-friendly.
Nspawn container tests boot in tens of seconds and cache at the granularity of the underlying NixOS module evaluation.
Full QEMU tests run in tens of seconds to minutes per node, scale linearly with the number of nodes, and require the kvm and nixos-test sandbox features that not every CI host provides.
This cost profile is the reason the escalation ladder exists: a project should run the cheapest regulator that faithfully covers the envelope, not the most powerful regulator available.
The severity profile of the regulators follows the same ordering as the envelope size, in the sense of preferences-validation-assurance's severity criterion: would the regulator fail under plausibly incorrect implementations of its target.
Process-compose passes a class of regressions that fail under nspawn because the systemd layer is absent.
Nspawn passes a class of regressions that fail under full QEMU because the kernel and multi-machine layers are absent.
Conversely, the heavier regulators do not subsume the lighter ones in terms of where they live in the development loop: process-compose's developer-host portability is valuable precisely because it runs on Darwin where the heavier regulators cannot.
The right composition is concentric envelopes with different cadences, not a single chosen regulator.
The PR cycle in nix-flake-pr-cycle exercises the closure operator over whichever regulators the project has wired into checks.<system>; buildbot's flake-check matrix runs them as fanout, so adding a heavier regulator costs build minutes but not orchestration effort.
The decision to escalate is therefore principally about whether the additional confidence is worth the build cost, not about whether the CI infrastructure can accommodate it.
See references/process-compose-checks.md for the full treatment of the application-composition regulator, references/nixos-vm-tests.md for the nspawn and full-QEMU regulators, and preferences-compositional-continuous-verification for the operating-envelope-plus-regulator framing.
Every check and test has a size class that says what it may wait on and how long one run may take: small up to 1 minute, medium up to 5 minutes, large up to 15 minutes, and enormous up to 60 minutes, the timeouts Bazel implies for its test sizes; a small test waits on no passage of time, and behaviour whose point is the passage of time, such as an outage window or a crash loop, belongs in a test kept for it.
A check's run is its build; a runtime test's run is its test script, which its timeout holds, and its driver and node builds are build cost outside the class.
Small and medium checks belong on the pull-request gate, a large one only with a recorded reason, and an enormous one never; it runs on a schedule or on demand.
A run expected to exceed 5 minutes is announced before it starts, with its expected duration, what it proves that a cheaper run cannot, and what waits on it.
The escalation ladder above picks the cheapest regulator for an envelope, and the size class holds each case's run time to what its assertion needs; a test larger than its purpose is a defect to report, not a cost to absorb.
See references/test-sizes.md for assigning a class, measuring one run, and what to do when a check outgrows its class.
Checks are organized as flake-parts modules, one per check category or logical group.
A repository might have checks/gitleaks.nix, checks/e2e.nix, checks/nix-unit.nix, and checks/rust.nix (combining clippy, nextest, and build for a Rust workspace).
The grouping decision balances module count against cohesion: a Rust workspace with clippy, nextest, and build checks benefits from colocating them in a single module because they share commonArgs and cargoArtifacts, while gitleaks and treefmt are independent enough to warrant their own modules.
import-tree auto-discovers these modules from the directory structure, so adding a new check module requires no manual wiring in flake.nix.
Each module defines its check derivations under perSystem.checks.<name>.
The convention is to name check attributes with a language or tool prefix: rust-clippy, rust-nextest, python-typecheck, python-test, js-typecheck, gitleaks, treefmt.
Prefixed names sort together in nix flake check output and make it clear which language ecosystem a failure originates from.
The devShell inputsFrom pattern connects checks to the development environment:
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self'.checks;
};
This makes all native build inputs from check derivations available in the dev shell. A developer entering the shell has all formatters, linters, type checkers, and test runners on their PATH without manually listing them. The pattern ensures that the development environment stays synchronized with the check suite: adding a new check that requires a new tool automatically makes that tool available in the dev shell.
When a check requires inputs that are inappropriate for the dev shell (for example, a large VM test dependency), exclude it from inputsFrom and add its tool dependencies to the dev shell explicitly.
The inputsFrom pattern pulls nativeBuildInputs and buildInputs, so be aware of what each check declares.
The preceding sections document the construction side of flake checks: the eight-category taxonomy, the derivation purity principle, source filtering for cacheability, shared artifact patterns, relational invariants under nix-unit, NixOS VM tests, and module organization under flake-parts.
This section names the meta-property layer that elevates the resulting check graph from a bag of derivations that happen to pass into a verification apparatus that closes.
The theoretical anchor for this framing is preferences-compositional-continuous-verification, which establishes operating-envelope-plus-regulator pairs composing into a single closure operator over the system's build and runtime graph.
The operational invocation that exercises this closure operator on the local flake is documented in nix-flake-pr-cycle.
Four meta-properties of the check suite sit alongside the per-artifact regulators, each strictly stronger than the prior.
Existence is the trivial property: at least one regulator of a given kind appears in the suite, observable by enumerating checks.<system>.
Traceability says that for every artifact in the repository that requires regulation, at least one regulator targets it — the relation from checks to artifacts is total over the artifact set.
Adequacy says that within each fiber of the traceability relation, the regulators jointly saturate the declared coverage model for their target.
Integrity says that the regulator would actually fail under mutation of its target — the vacuity-detection property that distinguishes a check with regulatory power from a check that passes regardless of what its target does.
These are properly understood as derivation kinds that belong in checks.<system> alongside the per-artifact regulators rather than as a separate audit subsystem; the meta-check derivations evaluate the structural relationship between the artifact set and the check set and fail loudly when the relationship is incomplete.
The exemption-audit derivation is the fifth wheel preventing silent erosion of coverage: real repositories accumulate legitimate exemptions, and the audit derivation enumerates them, validates that each has an owner and an unexpired timestamp, and fails on stale or unowned entries.
Within each artifact's check set, observability-interaction verification is an expected per-artifact discipline rather than a separate check category.
An artifact whose check set omits verification that emission, sampling, and the receiving side function end-to-end in dev mode — that traces appear in the local collector under synthetic load, that the dashboard renders against real data, that the SLO query returns the expected shape — is an adequacy gap rather than a stylistic choice.
The check categories in the preceding taxonomy describe the surface area of validation by failure mode; the observability-interaction obligation is orthogonal to that surface area and runs through it.
See preferences-observability-engineering for the regulator pattern that lands in a sibling commit.
The agent-side audit habit is the operational complement to the structural commitment.
The canonical enumeration command lives in preferences-compositional-continuous-verification; this skill restates it for cross-reference.
nix eval --json ".#checks.$(nix eval --impure --raw --expr 'builtins.currentSystem')" --apply builtins.attrNames | jaq -r '.[]'
This form enumerates currentSystem only and is sufficient for local probing during development.
Multi-platform coverage across the flake's declared systems list requires a different form that operates over the full .#checks attrset and emits a per-system view.
nix eval --json '.#checks' --apply 'cs: builtins.mapAttrs (system: attrs: builtins.attrNames attrs) cs'
This form maps over every system attribute that flake-parts emitted into checks and returns the attribute-name set per system, which is the correct shape for asking "do all declared systems carry the regulators we expect?" rather than the narrower local-system question.
Buildbot-nix in CI remains the authority for multi-platform coverage of the fleet; this caveat exists so an agent does not conclude "I ran the local enumeration, traceability is closed" when buildbot is the real authority for fleet-wide evaluation.
The meta-check derivations themselves — traceability, adequacy, integrity, and exemption-audit — are not yet present in the vanixiets flake. Their introduction is a deferred epic tracked separately when the per-artifact manifest schema, the coverage-model schema, and the mutation-testing sampling strategy land as flake-side machinery. This section establishes the discipline and the agent-side enumeration habit so that future work has a coherent target rather than a retrofit.
The preceding section defines integrity as the property that a regulator would fail under mutation of its target, and defers the meta-check derivations that would measure it.
The audit of this repository showed why the property cannot wait for that machinery.
Of about 80 checks reviewed, about 60 were vacuous, tautological, duplicated, or used a mechanism out of proportion to what they tested.
One of them, secrets-encryption-integrity in modules/checks/validation.nix, passed any file that was not JSON, so a plaintext YAML secret would have passed a check whose name promised protection against exactly that.
A vacuous check is not neutral: it costs evaluation and build time, and it signals coverage that does not exist, which suppresses the search for the real gap.
The governing principle is a placement ladder ordered by cost, and every check is placed on the lowest rung that can observe its failure mode; modules/checks/README.md states the same ladder for this repository.
assertions entry, or in a fleet obligation judged in the existing machine checks (modules/checks/machines.nix, nixos-<host> and darwin-<host>).
Such a fact is then checked as a side effect of evaluating the configuration that must be evaluated anyway, against the real values rather than a fixture.modules/checks/, with a testSizes.checks entry beside it and a negative control in the same comparison.
Example: sshd-no-keyboard-interactive.nix compares one sshd setting on every NixOS machine of the inventory, with a mutant that must differ.modules/vm-tests/, and only on the platforms where that behaviour actually differs.The one exception to rung 1: fleet obligations run only in the machine checks, and a host whose registry record sets checked = false (flake.fleet.hosts.<name>.checked, modules/lib/hosts.nix) has no machine check, so a fact about one configuration's values that must hold on such a host as well is a standalone check on rung 2.
A fact about our own pure logic belongs in an in-process unit test of that function, such as the nix-unit suite in modules/home/users/lib.test.nix that sits beside the lib.nix it tests, or a language-native test runner for non-Nix code.
The corollary is the rule an agent applies in review: a check that can be replaced by a cheaper rung of the ladder without losing a failure mode must be.
A check that cannot name a plausible incorrect implementation it would catch, and that nothing else catches, has no rung at all and is deleted rather than re-pinned.
The question is the severity criterion from preferences-validation-assurance, applied to the check rather than to the code it targets.
A mutant that demonstrates integrity runs only the case it must fail, not the regulator's full case set. Rerunning every case to judge one multiplies the check's cost by its case count in every build and adds no failure mode, since the other cases are already exercised by the unmutated regulator.
references/check-vacuity.md names the vacuity patterns found in this repository, each with its smell, the concrete instance, and the replacement, so that a reviewer can recognize them without re-deriving the argument.
The following skills provide complementary context:
preferences-nix-development covers flake conventions, module structure, and derivation best practices that underpin check derivation design, the import-from-derivation prohibition that keeps evaluation free of builds, and the mechanism for instantiating one nixpkgs per system that "One package set per system" depends on.preferences-validation-assurance provides the theoretical foundations for test design: the severity criterion (would this test fail under plausible incorrect implementations?) and the confidence promotion chain (how evidence accumulates across check categories). The 8 check categories in this skill map to confidence levels in the validation assurance framework: format and lint provide low confidence (style correctness), type-check and unit-test provide medium confidence (behavioral correctness), integration/e2e and nix-infrastructure provide high confidence (system-level correctness), and build/eval provides baseline confidence (the code compiles). "Operationalizing integrity" and references/check-vacuity.md apply the severity criterion to the checks themselves.preferences-nix-ci-cd-integration covers nix-eval-jobs, nix-fast-build, and buildbot-nix, the pipeline in which the evaluation cost described in "Evaluation cost as a design constraint" is paid per worker; references/evaluation-cost.md gives the protocol for measuring it.preferences-algebraic-laws covers property-based testing approaches for generating high-severity evidence, relevant when designing checks that go beyond example-based assertion. Property-based tests can be wrapped as nix check derivations using the same patterns described in references/derivation-patterns.md.preferences-production-readiness covers CI/CD pipeline integration, progressive delivery, and how checks gate deployment. The composition rules in this skill (flake-check-native, fan-out, effect) align with the production readiness stages: local development uses flake-check-native, CI uses fan-out, and deployment uses effects gated by check success.preferences-compositional-continuous-verification — theoretical anchor for the meta-property hierarchy and the closure-operator framingnix-flake-pr-cycle — operational workflow that exercises the closure operator and the audit habitWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
nix-flake, flake-parts, nix-checks, ci-validation, nixos-testing
4 skills in this plugin
/preferences-nix-ci-cd-integrationIntegrate nix flake checks into CI/CD pipelines via nix-eval-jobs, nix-fast-build, and buildbot-nix. Use when designing CI pipelines for nix-based repositories, migrating from hand-crafted CI matrices to nix-native check fanout, configuring buildbot-nix project registration, or planning binary cache strategy. Also load when sizing nix-eval-jobs evaluation workers and memory budgets (stock or an alternative evaluator such as iets), when reading nix-eval/nix-build statuses or cached attributes before merging, when working with the merge queue, or when the two-phase migration pattern (GHA+nix-fast-build to buildbot-nix delegation) or the effect execution strategy decision (platform-native vs nix-native effects) is relevant.
/preferences-nix-developmentNix development conventions for flakes, derivations, modules, and code style. Use when authoring flake.nix files, writing derivations, builders or overlays, designing NixOS/nix-darwin/home-manager modules, deciding how configurations instantiate and share nixpkgs, editing flake input wiring or `follows`, bumping pinned upstream versions guarded by assertions (kernel modules, patched sources), or following nix formatting and naming conventions. For check architecture and CI integration, see preferences-nix-checks-architecture and preferences-nix-ci-cd-integration.
/preferences-nix-and-secrets:preferences-nix-checks-architecturefrom preferences-nix-and-secrets
npx claudepluginhub cameronraysmith/vanixiets --plugin preferences-nix-and-secretsOther plugins' skills for the same job