Skip to content

Lint Nix code with deadnix and statix - #370

Merged
seberm merged 4 commits into
bitcoinix:masterfrom
sebsgent:nix-linters
Dec 1, 2026
Merged

seberm merged 4 commits into
bitcoinix:masterfrom
sebsgent:nix-linters

Conversation

@sebsgent

@sebsgent sebsgent commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #369, whose unused-binding cleanup was done by hand. deadnix would have found almost all of it.

Changes

  • New nix-lint flake check: deadnix --fail (unused bindings and arguments) and statix check. The existing check_flake job runs it through nix flake check, so there is no new CI job and ci_gate is unchanged.
  • statix.toml disables repeated_keys. Splitting options across several services.x = …; assignments is normal in NixOS modules, and this lint accounted for 67 of the 123 statix warnings on master.
  • deadnix and statix are in nix develop for local use. test/README.md and AGENTS.md describe the check.
  • Fixes for the current findings, mostly statix autofixes (inherit, useless parentheses), with a few rewritten by hand for readability.
  • fetchNodeModules: the runScripts and npmFlags defaults never reached the build, because only the caller's arguments were passed. They are now passed explicitly. The build does the same as before.
  • Intentionally unused bindings are marked # deadnix: skip: shellVersion in helper/makeShell.nix (existing shell.nix files still pass it) and exampleScenarios in test/tests.nix (kept as documentation).

Not included: nixfmt

nixfmt would reformat 114 of 177 .nix files (+12.7k/−8k lines) and conflict with most open PRs. That belongs in a separate formatting-only PR, together with a formatter flake output, a format check and .git-blame-ignore-revs, landed when few PRs are open.

Testing

  • nix build .#checks.x86_64-linux.nix-lint passes, and fails after adding an unused binding (negative control).
  • nix eval .#checks.x86_64-linux.module-config.testCount evaluates (247 tests).
  • All 48 standalone test scenarios evaluate to the same system toplevel outPaths, test scripts and drivers as master, including scenarios not in CI (full, hardened, clightning-replication, trustedcoin). The fetchNodeModules change alters only the fixed-output derivation, not its output path.
  • Full nix flake check, VM scenarios and deployment examples are left to CI.

Assisted-by: Claude Code (claude-opus-5-5)

@github-actions github-actions Bot added area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix area: packages pkgs/ and flake pins size: L 100–499 changed lines (additions + deletions) labels Dec 1, 2026
@seberm
seberm marked this pull request as ready for review December 1, 2026 14:33
@seberm seberm added this to the v0.2.2 milestone Dec 1, 2026

@prusnak prusnak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing! utACK

@seberm

seberm commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

@prusnak Thanks! I'll merge this one (still running a review) and then open a follow-up that:

  • splits the linters into separate flake checks, run as a CI matrix so each one shows up as its own check
  • adds an optional pre-commit hook built from the same Nix definitions
  • enables more linters (actionlint and zizmor for the workflows)

nixfmt will come later in its own formatting-only PR.

ostermayer and others added 2 commits December 1, 2026 15:53
clightning announced the port of the first mapping of its onion
service. When another mapping came first, peers dialed a port that
doesn't reach clightning. Pick the mapping to the peer port, as lnd
does. Without one, fall back to the first mapping, as before.

Assisted-by: Claude Code (Claude Opus 5.5)
…itcoinix#358)

With a public clightning onion service, clightning announced the port of
the first mapping of the onion service. When another mapping came first,
for example one added with `mkBefore`, peers dialed a port that doesn't
reach clightning. Now it picks the mapping to clightning's peer port, as
lnd does. Without one, it falls back to the first mapping, so those
configs announce the same port as before.

Item 10 of bitcoinix#316. The new `testClightningAnnouncesPeerOnionPort` check
fails on master and when no mapping matches, and `module-config` passes.
A mapping to another address on the same port still counts, as in lnd's
lookup.

Claude Fable 5.2 triaged bitcoinix#316 and Claude Opus 5.5 wrote this. DeepSeek
V4.1 Flash 1017 (max), Gemini 4 Carbon (high), Gemini 4 Neon (high),
Claude Opus 5.5 (high) and GPT-6 Astra (max) reviewed it over two
rounds. They found that the first test couldn't tell a match from the
fallback, and that the fallback had to stay the first mapping.

@sebsgent sebsgent left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, no must/should items.

Optional:

  • Commit message of fb7b5af and the PR body: "201 of the 257 statix warnings" counts statix check -o errfmt output lines, not warnings. On master it is 67 repeated_keys warnings out of 123.

Tested: compared every standalone test scenario (48) between master and the PR head: identical system toplevel outPaths, test scripts and drivers, including scenarios not in CI (full, hardened, clightning-replication, trustedcoin); the fetchNodeModules env change only alters the fixed-output derivation, not any output path. Negative controls: deadnix fails on an unused binding, statix fails on a lint, repeated_keys stays disabled. CI built and passed nix-lint.

Assisted-by: Claude Code (Claude Opus 5.5)

Apply statix's suggestions: inherit instead of manual assignments,
drop useless parentheses, an empty pattern and a redundant pattern
bind. Rewrite a few autofixes by hand where the result was hard to read.

fetchNodeModules declared defaults for runScripts and npmFlags but
passed only the caller's args to the derivation, so the defaults never
reached the build script. Pass them explicitly; the build does the same
as before, because unset and false both leave the variable empty.

Mark the remaining intentionally unused bindings with
`# deadnix: skip`: makeShell's shellVersion argument, which existing
shell.nix files still pass, and exampleScenarios in test/tests.nix,
which dev/dev-env/template-scenarios.nix points to as documentation.

Assisted-by: Claude Code (claude-opus-5-5)
Add the nix-lint flake check, which fails on unused bindings and
arguments (deadnix) and on statix lints. The check_flake CI job runs it
via `nix flake check`, so no new job is needed. Both tools are in the
dev shell for local use.

statix.toml disables repeated_keys: splitting options across several
`services.x = …;` assignments is idiomatic in NixOS modules, and the
lint accounted for 67 of the 123 statix warnings on master.

Assisted-by: Claude Code (claude-opus-5-5)
@seberm
seberm merged commit bedfbf7 into bitcoinix:master Dec 1, 2026
15 checks passed
seberm added a commit that referenced this pull request Dec 1, 2026
Each linter is defined once in test/lint.nix (actionlint, deadnix,
shellcheck, statix and zizmor) and runs as its own flake check and as
a job of a new `lint` CI matrix, so a failing linter is visible without
opening the logs. The matrix replaces the shellcheck job and is required
by ci_gate; the ci-workflows check keeps the matrix in sync with
lint.nix. `./test/run-tests.sh lint` runs all linters locally, and an
optional pre-commit hook (.#pre-commit-hook) runs them on the staged
tree.

The workflows are hardened for zizmor's findings: checkouts no longer
persist the GitHub token, the labeler's pull-requests write permission
is granted per job, the docs site path no longer goes through
GITHUB_ENV, and the pull_request_target and workflow_run triggers are
documented as safe and marked as accepted findings.

Follow-up to #370
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ci .github/, test/, dev/ area: docs docs/, README, examples/, SECURITY.md, book.toml, assets area: modules modules/ and pkgs/lib.nix area: packages pkgs/ and flake pins size: L 100–499 changed lines (additions + deletions)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants