flake: format the tree with one treefmt

The pre-commit hooks kept their own list of formatters, so nixpkgs-fmt in
a hook and nixfmt in the check disagreed the moment flake-checks moved.
`nix fmt` is now built from the same treefmt module the formatting check
is, and the hook and the Makefile both call it.
This commit is contained in:
Kristoffer Dalby
2026-09-10 05:33:45 +00:00
parent f1186d8e00
commit d59c1ed209
5 changed files with 28 additions and 19 deletions
+7 -13
View File
@@ -32,21 +32,15 @@ repos:
# Local hooks for project-specific tooling
- repo: local
hooks:
# nixfmt for Nix files; the same formatter the flake's treefmt check
# runs, so the hook and the check cannot disagree.
- id: nixfmt
name: nixfmt
entry: nixfmt
language: system
files: \.nix$
# Prettier for formatting
- id: prettier
name: prettier
entry: prettier --write --list-different
# One formatter for Nix and markup, built from the same treefmt module as
# the flake's formatting check, so the hook and the check cannot disagree.
# Go is absent on purpose: golangci-lint owns it, below.
- id: treefmt
name: treefmt
entry: nix fmt --
language: system
exclude: ^docs/
types_or: [javascript, jsx, ts, tsx, yaml, json, html, css, scss, sass, markdown]
types_or: [javascript, jsx, ts, tsx, yaml, json, html, css, scss, sass, markdown, nix]
# mdformat for docs
- id: mdformat
+3
View File
@@ -1,2 +1,5 @@
.github/workflows/test-integration-v2*
docs/
# Golden fixtures are byte-compared; a formatter must not rewrite them.
hscontrol/testdata/
+2 -1
View File
@@ -109,7 +109,8 @@ prek run --all-files # run hooks on the full tree
Hooks cover: file hygiene (trailing whitespace, line endings, BOM),
syntax validation (JSON/YAML/TOML/XML), merge-conflict markers, private
key detection, nixpkgs-fmt, prettier, and `golangci-lint` via
key detection, `treefmt` (the same formatter `nix fmt` and the flake's
formatting check run), `mdformat` for `docs/`, and `golangci-lint` via
`--new-from-rev=HEAD~1` (see the golangci-lint hook in .pre-commit-config.yaml). A manual
invocation with an `upstream/main` remote is equivalent:
+5 -5
View File
@@ -50,7 +50,7 @@ test: check-deps $(GO_SOURCES) go.mod go.sum
# Formatting targets
.PHONY: fmt
fmt: fmt-go fmt-mdformat fmt-prettier
fmt: fmt-go fmt-mdformat fmt-tree
.PHONY: fmt-go
fmt-go: check-deps $(GO_SOURCES)
@@ -63,10 +63,10 @@ fmt-mdformat: check-deps
@echo "Formatting documentation..."
mdformat docs/
.PHONY: fmt-prettier
fmt-prettier: check-deps $(PRETTIER_SOURCES)
@echo "Formatting markup and config files..."
prettier --write '**/*.{ts,js,md,yaml,yml,sass,css,scss,html}'
.PHONY: fmt-tree
fmt-tree: check-deps $(PRETTIER_SOURCES)
@echo "Formatting Nix, markup and config files..."
nix fmt
# Linting targets
.PHONY: lint
+11
View File
@@ -278,6 +278,17 @@
drv = pkgs.headscale;
};
# `nix fmt` is built from the same treefmt module as the formatting
# check, so the two cannot disagree. Every formatter the tree is judged
# by lives here, not in a hand-kept list of pre-commit hooks.
formatter = fc.formatter (
common
// {
goFmt = "off";
prettier = true;
}
);
checks = {
headscale = pkgs.testers.nixosTest (import ./nix/tests/headscale.nix);
}