hyperhive/nix/devshell.nix
atlas 27932ec631 types: let nix own the reserved-name blacklist
One list, in nix/reserved-names.nix, handed to everything that needs it
as HIVE_RESERVED_NAMES. Keeping it current becomes a config change
rather than a rebuild, and hive names and agent names -- one namespace
going forward -- are checked against the same file: swarm-otel.nix's
hand-written reservedOwners is gone.

Whitespace-separated rather than JSON, deliberately, unlike the
structured env vars beside it. Every entry is an Ident ([a-z0-9-]), so
whitespace cannot occur inside a name and the encoding is provably
lossless; JSON would mean either a parser dependency in a crate whose
purpose is to have none, or a copy of the parse in every consumer.

An UNSET variable is not "nothing is reserved". Both creation sites log
an error and return a warning saying the check did not run, so a
misconfigured deployment says so instead of silently accepting every
name. A blank value folds into unset: nix always renders a non-empty
list, so present-but-empty is a rendering fault, not a declaration.

Two guards whose subject moved out of their own file now assert their
own case is still in it, because a guard that can be retired by an edit
elsewhere is not a guard:

- swarm-otel.nix asserts reserved-names.nix still contains its
  swarmTierName.
- hive-sh4re's sentinel drift test PANICS when the variable is missing
  rather than skipping -- a drift test that quietly does nothing still
  reports green. checks.nix and devshell.nix both export it so CI and a
  local cargo test agree. Verified as a pair: with the variable set, 8
  tests pass; with it unset, exactly the 4 drift tests fail and the
  unrelated ones still pass.
2026-08-27 16:36:42 +02:00

45 lines
2 KiB
Nix

# Dev shell: the rust toolchain plus the exact native build inputs
# the crane derivations use (git, sqlite, pkg-config, cmake — see
# ../rust.nix), so a plain `cargo build` / `cargo test` in the shell
# sees the same toolchain shape as CI.
{ pkgs, rust }:
{
default = pkgs.mkShell {
# Same list the daemons are handed and the same one `checks.nix` gives
# the test derivation — `nix/reserved-names.nix`. Without it here, a
# plain `cargo test` in the shell would panic on the drift test, so a
# developer's local run and CI would disagree about a test that exists
# precisely to stop two spellings of one fact from drifting.
HIVE_RESERVED_NAMES = pkgs.lib.concatStringsSep " " (import ./reserved-names.nix);
packages =
rust.nativeBuildInputs
++ (with pkgs; [
cargo
cargo-llvm-cov
clippy
rust-analyzer
rustc
rustfmt
]);
# `cargo llvm-cov` shells out to `llvm-profdata` and `llvm-cov`,
# which it expects to find as rustup's `llvm-tools-preview` beside
# the rustc toolchain. Nixpkgs has no such component, so without
# these it aborts with "failed to find llvm-tools-preview" — a
# message that reads like a missing install rather than a path the
# shell simply has to name.
#
# ⚠️ Both the variable names and the package were wrong on the first
# attempt and only the tool itself said so: it reads `LLVM_COV` /
# `LLVM_PROFDATA` (no `_PATH` suffix), and the binaries live in
# `llvmPackages.llvm` — `llvmPackages.bintools` is the linker
# wrapper and ships neither.
#
# Coverage is deliberately NOT part of `nix flake check`: an
# instrumented build cannot reuse the normal test artifacts, so it
# roughly doubles a test job. It runs on manual dispatch — see
# .forgejo/workflows/coverage.yml for why that rather than nightly.
LLVM_PROFDATA = "${pkgs.llvmPackages.llvm}/bin/llvm-profdata";
LLVM_COV = "${pkgs.llvmPackages.llvm}/bin/llvm-cov";
};
}