Skip to content

build: adopt git-hooks.nix + prek runner, expose checks.pre-commit, and gate flake checks as CI Tier 0 - #791

Merged
c-vigo merged 14 commits into
devfrom
feature/778-git-hooks-prek
Jul 3, 2026
Merged

c-vigo merged 14 commits into
devfrom
feature/778-git-hooks-prek

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

What

Two related build-system changes land together on this branch:

  1. [CHORE] Adopt git-hooks.nix with package = pkgs.prek (supersedes #40) #778 (Closes [DISCUSSION] Migration to prek #40) — pre-commit → prek. Adopt cachix/git-hooks.nix with
    package = pkgs.prek and migrate the git-hook runner from the Python
    pre-commit to the Rust prek. The flake now exposes
    checks.pre-commit (the sandbox-pure hook subset, run under the flake
    check tier), prek joins the devTools SSoT (dev-shell + image), and the
    standalone pre-commit is dropped from both — one fewer manylinux/FHS
    consumer in the image closure.
  2. [CHORE] Flake-checks as CI Tier 0 (garnix / nix-fast-build) #779 — CI Tier 0 via nix-fast-build. Build every checks.<system>
    derivation (treefmt formatting, deadnix/statix, dev-shell, devShellTools,
    and the new checks.pre-commit gate) in parallel with an eval cache via
    nix-fast-build, replacing the serial nix flake check step in
    project-checks. Recorded in docs/rfcs/ADR-flake-checks-tier0.md.

Scope note: #779 depends on #778's checks.pre-commit existing, so the two
are landed together rather than split. Both issues are addressed here; the
commit trail keeps them on separate Refs: (#778 / #779).

Design: two hook artifacts, kept in agreement

checks.pre-commit builds in the Nix sandbox (no network, no venv), so it can
only run pure hooks. Rather than generate a store-path-bound config (which
would not be portable to the downstream scaffold and would churn on nixpkgs
bumps), the committed .pre-commit-config.yaml stays the hand-maintained,
PATH-based runner config, and checks.pre-commit is the Nix-verified
guarantee that its pure hooks are correct. Documented in docs/NIX.md.

Hook → mechanism mapping

In checks.pre-commit (pure, git-hooks.nix + prek):

  • formatting → one treefmt hook reusing treefmtEval (nixfmt + ruff-format + taplo), replacing the individual nixfmt/ruff-format/taplo-format hooks
  • pure linters → ruff, shellcheck, yamllint (--format parsable --strict), typos, a custom taplo-lint, and just --fmt --check --unstable
  • pre-commit-hooks meta hooks (built-ins) → check-added-large-files, check-case-conflicts, check-json, check-merge-conflicts, check-symlinks, check-toml, check-yaml, python-debug-statements, detect-private-keys, end-of-file-fixer, mixed-line-endings, trim-trailing-whitespace
  • vig-utils/bandit → wired to hermetic Nix binaries (${vigUtils}/bin/…, ${pkgs.bandit}/bin/bandit): check-action-pins, check-skill-names, check-expirations, bandit

Runner-only (excluded from checks.pre-commit): generate-docs, sync-manifest, pip-licenses, pymarkdown (not in nixpkgs), no-commit-to-branch, destroyed-symlinks (no git-hooks.nix built-in + git-state-dependent), check-agent-identity (inspects git identity), and the commit-msg/prepare-commit-msg-stage hooks.

Fidelity notes

Runner/image/scaffold changes

  • .githooks/* (root + scaffold) call prek run; scripts/init.sh runs prek prepare-hooks; just precommit → prek run --all-files; worktree setup → prek install -t pre-commit -t commit-msg -t prepare-commit-msg; scaffold init-precommit.sh/justfile.project follow.
  • Image: prek via devTools (no pre-commit), baked cache renamed PREK_HOME=/opt/prek-cache, precommit alias → prek run.
  • CI lint gate (.github/actions/test-project) runs prek run --all-files (was uv run pre-commit run --all-files); pre-commit==4.6.0 dropped from pyproject.toml + uv.lock and the vestigial pre-commit- dev-shell PATH exclusion removed.

Review follow-ups (addressed on this branch)

  • check-yaml parity — the Nix gate hardcodes --multi; the runner now passes --allow-multiple-documents too so both agree (was: gate strictly more lenient).
  • worktree hook stages — prek install now installs all three stages; bare prek install only wired the pre-commit shim, silently dropping commit-msg / prepare-commit-msg in worktrees.
  • scaffold completeness — repointed the lint job's dead PRE_COMMIT_HOME=/opt/pre-commit-cache → PREK_HOME=/opt/prek-cache, updated container-ci-quirks.md, and dropped the stale .pre-commit-cache idempotency guard in init-precommit.sh.
  • test fidelity — init.bats now asserts the real prek prepare-hooks command instead of a string that only matched a leftover comment.

Verification

  • Tier-0 flake checks via nix run .#nix-fast-build → all checks passed (formatting, deadnix, statix, devShell, devShellTools, pre-commit).
  • prek run --all-files → green on the root repo and the nested scaffold (all hooks incl. the impure uv run ones).
  • prek validate-config → passes on the root and assets/workspace configs.
  • nix build .#devcontainerImage builds; the image closure has prek (0.3.11) and no pre-commit.
  • Image + flake parity tests updated (TDD, test: committed first); tests/bats/init.bats green (29/29).

Closes #40, #778, #779

c-vigo added 6 commits July 1, 2026 09:19
Add the cachix/git-hooks.nix input and build a sandbox-pure
checks.pre-commit driven by the prek runner (package = pkgs.prek):
one treefmt formatting hook (reusing treefmtEval), the pure linters
(ruff, shellcheck, yamllint, typos, taplo lint), the pre-commit-hooks
meta hooks, and the vig-utils/bandit hooks wired to hermetic Nix
binaries. Impure/stage-gated hooks stay runner-only.

Drop the Python pre-commit from the dev-shell and image and add prek
to the devTools SSoT (dev-shell + image). Rename the baked hook cache
to PREK_HOME=/opt/prek-cache and the precommit alias to prek run.

Refs: #778
Swap every git-hook invocation from the Python pre-commit to prek: the
tracked .githooks shims (root + scaffold) call prek run, scripts/init.sh
runs prek prepare-hooks, just precommit and the worktree setup use prek,
and the downstream scaffold (init-precommit.sh, justfile.project) follows.

Source shellcheck from the flake toolchain as a language:system hook: the
shellcheck-py wheel bundles a manylinux binary the Nix userland cannot exec
and prek/uv cannot build under Python 3.14, so it joins ruff/typos/nixfmt
(#697, #701) as a flake-provided hook.

Refs: #778
c-vigo and others added 2 commits July 1, 2026 10:26
#778 drops the Python pre-commit from the image in favour of prek, so the
integration tests that exec `pre-commit run` inside the container (TestDevContainerCLI::
test_pre_commit_hook and the branch-name convention tests) hit a command-not-found
(exit 127) and failed. Point them at the `prek` runner the image now ships.

Refs: #778
c-vigo added a commit that referenced this pull request Jul 1, 2026
## What

Adds `docs/rfcs/ADR-nix-devenv-strategy.md` — a decision record for the
org's Nix
dev-environment strategy, prompted by
[exo-pet/exo-fleet#76](exo-pet/exo-fleet#76)
(devenv→mkShell port) and its "compare devenv / devshell / mkshell /
direnv" thread.

The ADR's core move: that four-way question is a **category error**. It
conflates
**three separable axes**:

1. **Activation** — `nix-direnv` (auto on `cd`, GC-rooted) vs manual
`nix develop`. Complementary.
2. **Shell definition** — `pkgs.mkShell` vs `numtide/devshell` vs
`cachix/devenv`. Exclusive per repo.
3. **Local services** — `devenv up`-style MinIO/Postgres orchestration,
which devenv *bundles* into axis 2.

## Decisions recorded

- **Axes 1–2 (ratify existing practice):** `pkgs.mkShell` (via
`mkProjectShell`) + `nix-direnv`.
Reject `devenv`/`numtide-devshell` as the shared builder — both
interpose their own
package-declaration surface between the `devTools` SSoT and `PATH`,
complicating the
dev-shell↔image **parity test**; devenv additionally pays the measured
~165s IFD cold-eval
(#76) and drags its own substituter. Consistent with #27 (already
Superseded) and the
  #778/#791 move to `git-hooks.nix` + `prek`.
- **Axis 3 (the one open decision):** adopt `process-compose` +
`juspay/services-flake` as the
nix-native `devenv up` replacement (daemon-free, versions from the same
nixpkgs lock, GC-rooted,
no IFD). Shared `mkProjectServices` helper + a MinIO+Postgres PoC
tracked in #795.

Includes two decision matrices (shell-definition; local-services), an
Impact/blast-radius section
(**authoritative for `vig-os`**, a **recommendation** to
`exo-pet`/`exoma` siblings), and a
`Reconsider if` section.

## Also

- Cross-link from `docs/NIX.md` (`## See also`).
- `CHANGELOG.md` Unreleased entry (`### Added`), mirrored to the
scaffold copy by `sync-manifest`.

## Verification

- `pre-commit run --files …` green on all changed docs (pymarkdown,
typos, whitespace,
  generate-docs, sync-manifest, validate-commit-msg).
- ADR matches the house style of `docs/rfcs/ADR-uv2nix-pyproject-nix.md`
(frontmatter, TL;DR,
  Options, matrices, Reconsider-if, References).

Refs #794
c-vigo and others added 2 commits July 1, 2026 10:50
Build every checks.<system> derivation (treefmt formatting, deadnix/statix,
dev-shell build, devShellTools, the git-hooks.nix pre-commit gate) in parallel
with an eval cache via nix-fast-build, replacing the serial `nix flake check`
step in project-checks. Expose nix-fast-build as packages.<system>.nix-fast-build
(pinned-nixpkgs passthrough) so CI runs it via `nix run .#nix-fast-build` without
baking a CI-only tool into the dev-shell or image. Validate the flake output
schema (formatter/checks/apps/modules) with test_flake_checks.py, preserving what
the removed `nix flake check` covered. Document the pure/effectful tiering in
docs/rfcs/ADR-flake-checks-tier0.md.

Refs: #779
@c-vigo

c-vigo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Folded in #779 (flake-checks as CI Tier 0 via nix-fast-build) — PR #797 auto-closed as merged. This branch now lands roadmap threads B (git-hooks.nix + prek, closes #40) and C (#779), and is up to date with dev. Refs #779.

@gerchowl

gerchowl commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review finding — migration gap: CI lint gate still on pre-commit

.github/actions/test-project/action.yml:85 is untouched by this PR and still runs:

uv run pre-commit run --all-files --show-diff-on-failure --color=always

This PR removes pre-commit from the dev-shell and image and advertises a full runner migration to prek, but the CI job that exercises the whole committed hook suite still invokes the Python pre-commit (pre-commit==4.6.0 is still in pyproject.toml + uv.lock; prek is in neither).

Consequences:

  • prek is never validated against the full committed config in CI — only the pure subset via checks.pre-commit plus the single-file container smoke test — so a prek-vs-pre-commit behavioral divergence on the impure hooks (generate-docs, sync-manifest, pip-licenses, pymarkdown, check-agent-identity, commit-msg stages) would ship undetected.
  • pre-commit remains a project dependency, contradicting the "dropped from both" narrative.

Suggest either switching this step to prek run --all-files or explicitly documenting that the CI gate intentionally stays on pre-commit.

@gerchowl

gerchowl commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review finding — just-fmt silently dropped from checks.pre-commit and undocumented as runner-only

The just-fmt hook (.pre-commit-config.yaml:102, entry: just --fmt --unstable, language: system) is sandbox-pure and just is already in devTools, yet it appears in neither the preCommitCheck hooks attrset (flake.nix) nor the treefmt wrapper (which covers only nix/python/toml).

It is also absent from the runner-only exclusion list enumerated in docs/NIX.md and the ADR — unlike nixfmt (folded into treefmt) and pymarkdown/no-commit-to-branch/etc. (explicitly excluded). It is the only pure hook in the committed config that is neither mirrored nor documented as excluded, so justfile-formatting drift is not caught by the Nix-verified gate this PR positions as "the guarantee that the pure hooks stay correct."

Suggest adding a just-fmt custom hook (mirroring the taplo-lint pattern) or documenting it as a deliberate exclusion.

Address the review findings on #791: the PR advertised a full runner
migration and "dropped from both", but the CI lint gate and one pure
hook were still left behind.

- CI: switch the lint gate (.github/actions/test-project) to
  `prek run --all-files` (was `uv run pre-commit run --all-files`) and
  drop `pre-commit==4.6.0` from pyproject.toml + uv.lock, so prek — not
  the Python pre-commit — is what CI validates against the impure hooks
  too. Also drop the now-vestigial `pre-commit-` dev-shell PATH
  exclusion in setup-env and repoint the hook cache to PREK_HOME.
- flake: mirror the pure `just-fmt` hook into `checks.pre-commit`
  (`just --fmt --check --unstable`) so justfile-format drift is caught
  by the Nix-verified gate; document it in docs/NIX.md and the ADR.
- worktree setup (.claude/worktrees.json) and the skill docs now point
  at `prek install` instead of `pre-commit install`.

Refs: #778
@c-vigo

c-vigo commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @gerchowl — both findings are valid and now fixed in 9e876b08, along with an adjacent gap of the same class.

Finding 1 — CI lint gate still on pre-commit. Confirmed. .github/actions/test-project now runs prek run --all-files (was uv run pre-commit run --all-files), so prek — not the Python pre-commit — is what CI validates against the whole committed config, impure hooks included. pre-commit==4.6.0 is dropped from pyproject.toml + uv.lock (–8 transitive deps), the hook cache step is repointed to PREK_HOME, and the now-vestigial pre-commit- dev-shell PATH exclusion in setup-env is removed (its comment claimed "CI uses uv run pre-commit" — that contradiction is gone). This also makes docs/NIX.md's "covered by CI's prek run --all-files" true rather than aspirational.

Finding 2 — just-fmt uncovered. Confirmed, and mirrored (not documented-as-excluded) since just is already in devTools. Added a just-fmt custom hook to preCommitCheck following the taplo-lint pattern, using just --fmt --check --unstable (check-mode, since the sandbox is read-only). Documented in docs/NIX.md and the ADR. Verified it's wired in: nix build .#checks.<system>.pre-commit passes clean, and an injected justfile-format drift correctly fails the check.

Adjacent gap (self-found). The PR moved justfile.worktree to prek install but left .claude/worktrees.json (root + scaffold) and the skill docs on pre-commit install — fixed to prek install (--prepare-hooks for the worktrees.json env pre-build). Note docs/SKILL_PIPELINE.md is generated, so the change is in the .j2 template.

Verification: prek run --all-files green (31 hooks), checks.pre-commit builds with just-fmt, uv lock --check consistent, tests/test_flake_checks.py passes.

Address weak points found reviewing #791:

- check-yaml: pass --allow-multiple-documents in both the committed runner
  config and (via git-hooks.nix' hardcoded --multi) checks.pre-commit, so the
  Nix gate is no longer more lenient than the runner on multi-document YAML.
- worktree setup: `prek install` now wires all three hook stages
  (-t pre-commit -t commit-msg -t prepare-commit-msg); bare `prek install`
  only installs the pre-commit shim, silently dropping the commit-msg /
  prepare-commit-msg hooks in worktrees.
- scaffold: repoint the remaining pre-commit references at prek — the lint
  job's dead PRE_COMMIT_HOME=/opt/pre-commit-cache env (now PREK_HOME=
  /opt/prek-cache), container-ci-quirks.md, and init-precommit.sh (drop the
  stale .pre-commit-cache idempotency guard; prek prepare-hooks is idempotent).
- tests: init.bats now asserts the real `prek prepare-hooks` command instead
  of a string that only matched a leftover comment.

Refs: #778
@c-vigo c-vigo changed the title build: adopt git-hooks.nix + prek runner and expose checks.pre-commit build: adopt git-hooks.nix + prek runner, expose checks.pre-commit, and gate flake checks as CI Tier 0 Jul 2, 2026
c-vigo added a commit that referenced this pull request Jul 3, 2026
## Summary

Closes the version-drift #720 was filed for — but by **deletion rather
than by automating a sync**.

Investigation showed CI already provisioned the toolchain from the flake
for the image/test jobs (`setup-env`'s `provision-via-flake` mode). The
drift lived only in the *other* mode: the ad-hoc path hardcoded a second
`uv` version (`0.11.23`) that had to be kept in lockstep with the
flake's overlaid `pkgs.uv.version`. (Concretely, they had already
drifted — the flake currently resolves `uv 0.11.19`.)

This makes `setup-env` **flake-only**: every job installs Nix + Cachix
and enters the dev-shell, so CI and local `nix develop` run the
identical toolchain from a single source (`flake.lock`). The literal pin
is gone; the `uv` version now flows solely from the flake.

## Changes

- **`setup-env` action** — remove the `provision-via-flake` toggle and
the ad-hoc install steps (`astral-sh/setup-uv` ×2 with the `0.11.23`
pin, `actions/setup-python`, `taiki-e/install-action` for just, the
taplo curl, `bats-action`); drop the now-dead
`install-python`/`python-version`/`install-just`/`install-taplo`/`install-bats`
inputs and the unused `uv-version` output. Keep the host-integration
steps (podman setuid, Node.js, devcontainer CLI) and the
`UV_PYTHON_DOWNLOADS_JSON_URL` forwarding that pre-commit's manylinux
hooks depend on.
- **Callers** — the 4 composite actions drop `provision-via-flake`/tool
flags now provided by the flake; the lightweight ad-hoc callers
(`ci.yml` security jobs, `prepare-`/`promote-`/`release.yml`
orchestration) are wired to the warm `vig-os` Cachix cache.
- **`security-scan.yml` `scan-nix-image`** — drops its duplicate
*direct* Nix/Cachix setup and routes provisioning through `setup-env`
(no double install; DRY).
- Docs (`NIX.md`) + CHANGELOG updated.

Net `+71 / −227`.

## Trade-off (accepted)

The lightweight security/release jobs now pull the warm Cachix closure
instead of a ~5 s `uv` download, and the release-orchestration pipeline
gains a dependency on Nix + the Cachix cache (mitigated: the closure is
already warmed by `nix-cachix.yml`/build jobs, and `cache.nixos.org` is
a fallback substituter).

## Verification

- `grep` for `0.11.23` / `provision-via-flake` / removed inputs → clean
across `.github`.
- `pre-commit` green on changed files (`yamllint`, `check-action-pins`,
`pymarkdown`, agent-identity).
- **CI on this PR exercises the converted `ci.yml` jobs**
(`python-security`, `security-scan`, `dependency-review`) — confirm they
hit the warm cache.
- ⚠️ The `prepare-`/`promote-`/`release.yml` legs are **event-gated**
(tags/release/dispatch) and cannot run on a feature-branch PR; they are
verified structurally (identical shared action + YAML) and should be
watched on the next release. `release.yml` `vulnix-gate` uses the same
flake path already proven in `build-and-test`.

## Notes

Non-testable CI config (no unit test; noted per the TDD standard).
Downstream follow-up: #779 (flake-checks as CI Tier 0) is the natural
next step once #791 lands.

Refs: #720

@gerchowl gerchowl 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.

Approving — re-reviewed only the changes pushed after my 07-02 findings (9e876b08 + 4908b9b9c). Both are cleanly resolved:

Finding 1 (CI lint gate still on pre-commit) — .github/actions/test-project now runs prek run --all-files (cache step + --version probe repointed to prek/PREK_HOME), pre-commit==4.6.0 and its 8 transitive deps are gone from pyproject.toml + uv.lock, and the vestigial pre-commit- PATH exclusion in setup-env (whose comment contradicted the migration) is removed. prek is now what CI validates against the whole committed config, and NIX.md's "covered by CI's prek run --all-files" is now true rather than aspirational.

Finding 2 (just-fmt uncovered) — mirrored into preCommitCheck following the taplo-lint pattern, in --check mode for the read-only sandbox, and documented in both NIX.md and the ADR. The right call over documenting-as-excluded, since just was already in devTools.

Self-found adjacent gap — good catch on .claude/worktrees.json (root + scaffold) and the skill docs still on pre-commit install; repointed to prek install --prepare-hooks. Verified --prepare-hooks is the valid current spelling of prek's old --install-hooks, so the env pre-build works. (justfile.worktree staying on bare prek install is fine — it matches the prior no-pre-build behavior there.)

No new concerns. LGTM.

@c-vigo
c-vigo disabled auto-merge July 3, 2026 11:04
…prek

# Conflicts:
#	CHANGELOG.md
#	assets/workspace/.devcontainer/CHANGELOG.md
#	flake.nix
@c-vigo
c-vigo enabled auto-merge July 3, 2026 11:17
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.

2 participants