Skip to content

chore: add formatting & linting for Nix and shell + CI - #44

Merged
phorcys420 merged 6 commits into
mainfrom
nix-format-lint-ta15
Jun 30, 2026
Merged

phorcys420 merged 6 commits into
mainfrom
nix-format-lint-ta15

Conversation

@phorcys420

Copy link
Copy Markdown
Member

Closes #36.

Adds formatting + linting for the Nix and shell files, with CI to enforce it.

What's in here

  • treefmt.nix — single treefmt config driving every tool:
    • Nix: nixfmt (RFC-style format) + statix (anti-pattern lints) + deadnix (dead-code removal)
    • Shell: shfmt (format, 2-space indent to match existing scripts) + shellcheck (lint)
    • Excludes vendored/generated files (flake.lock, *.terraform.lock.hcl, *.tar.gz, image artifacts)
  • flake.nix — adds the treefmt-nix input plus:
    • formatter.<system> → nix fmt applies everything in-place
    • checks.<system>.formatting → nix flake check verifies the tree is clean
  • .github/workflows/fmt.yml — new CI job running nix fmt -- --ci inside the nixos/nix container, mirroring the docker run pattern in test.yml/release.yml. Triggers on push to main, PRs, and manual dispatch.
  • Reformatted the whole tree (all tracked .nix files + install.sh) so CI is green. The only hand-written, non-mechanical change is in install.sh: the SC2059 shellcheck disable now scopes the whole print_summary function (the previous inline one only covered the first of ~9 printf "$row" rows).
  • agents.md — short contributor note on nix fmt / nix fmt -- --ci.

Verification

  • nix fmt -- --ci → 0 changed (the exact CI command)
  • nix build .#checks.x86_64-linux.formatting → passes
  • nix flake check --no-build --all-systems → all configs/outputs evaluate
  • make installer/drv + make appliance/drv → both ISO derivations fully instantiate (confirms the deadnix/statix edits dropped nothing used)
  • bash -n install.sh → valid

The diff is large because enabling formatters reformats existing files, but it's almost entirely mechanical.

Add treefmt-nix as the single formatter/linter runner (config in
treefmt.nix), driving:

  * Nix:   nixfmt + statix + deadnix
  * Shell: shfmt (2-space) + shellcheck

Expose it via the flake's formatter (`nix fmt`) and
checks.<system>.formatting (`nix flake check`) outputs, and add a CI
workflow (.github/workflows/fmt.yml) that runs `nix fmt -- --ci` in the
nixos/nix container (matching the existing test/release workflows).

Reformat all tracked .nix files and install.sh to satisfy the tools, and
fix a shellcheck SC2059 in install.sh by scoping the disable to the whole
print_summary function. Document the workflow in agents.md.

Closes #36
Add Makefile targets driving treefmt with -f to keep formatting and
linting separate:

  * make fmt        format in place (nixfmt + shfmt)
  * make fmt/check  format check only (--ci, no writes)
  * make lint       lint check only (statix + deadnix + shellcheck, --ci)

Rework .github/workflows/fmt.yml into two independent jobs (format check
+ lint) that only CHECK — they never apply formatting, failing with a
diff when something is off. Update agents.md accordingly.
The format/lint checks are light, so drop the nixos/nix `docker run`
container wrapper (only needed for the heavy image builds' glibc-loader
workaround) and instead install Nix on the runner with
nix-installer-action (flakes enabled), running `make` directly (GNU Make
is preinstalled on the GitHub Ubuntu runners).
# Conflicts:
#	Makefile
#	hosts/_appliance-disk/default.nix
`make lint/fix` runs statix + deadnix in write mode to auto-apply lint
fixes in place (shellcheck has no autofixer; run `make lint` after to
catch what's left).
@phorcys420
phorcys420 merged commit a4f8937 into main Jun 30, 2026
6 checks passed
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.

chore: add CI for code prettification

1 participant