Skip to content

Add git hooks to the org devenv shell - #45

Merged
andrewthomaslee merged 1 commit into
mainfrom
devenv-git-hooks
Nov 26, 2026
Merged

andrewthomaslee merged 1 commit into
mainfrom
devenv-git-hooks

Conversation

@andrewthomaslee

Copy link
Copy Markdown
Member

What

  • devenv/devenv.nix: the org shell installs a pre-commit hook, fmt, that runs nix fmt -- --ci. It's on only when the repo's devenv.yaml has a git-hooks input. Without the input, entering the shell prints a one-line note to stderr instead.
  • flake.nix / flake.lock: new git-hooks input (cachix/git-hooks.nix; nixpkgs follows, flake-compat dropped). It's lazy: no flake evaluation fetches it.
  • devenv.yaml / devenv.lock (pkgs' own shell): git-hooks is pinned to the flake.lock rev, the same way nixpkgs is.
  • flakeModules/dev.nix:
    • checks.lock-sync also fails when devenv.lock's git-hooks differs from what flake.lock resolves (through org-pkgs in consumers, directly in pkgs).
    • sync-locks re-pins pkgs' own devenv.yaml.
    • resolve now returns null for a missing input instead of throwing.
  • devenv/worktree.sh: worktree new enters the devenv shell once, so the new worktree has its hook config before the first commit.
  • templates/default/devenv.yaml, .gitignores: new repos follow org-pkgs/git-hooks and ignore .pre-commit-config.yaml.
  • Docs: flake-standard.md has a new "Git hooks" section (opting in, repo hooks, worktrees). The README mentions it too.

Why

Unformatted code is caught at commit instead of in CI. A repo can also add its own fast hooks, e.g. home's clan vars check on pre-push.

What I tested

I used a throwaway local clone of skills with org-pkgs set to this branch's worktree.

Test Result
Input declared only in the imported org-pkgs/devenv/devenv.yaml Not picked up. devenv reads inputs from the repo's own devenv.yaml only. That's why each repo needs the follows line
Hook enabled, consumer without the input (first version) devenv fails to enter the shell ("To use 'git-hooks'… devenv inputs add"). That's why the hook is guarded
Guarded, consumer without the input Shell enters, prints the note, no hooks installed
Consumer with git-hooks.follows: org-pkgs/git-hooks Hook installed. devenv.lock git-hooks = pkgs' flake.lock rev (5c6bf7c)
Commit with a badly formatted .nix Blocked (--fail-on-change). treefmt fixes the file; git add and commit again passes. About 2s
git commit --no-verify Skips the hook. Agents will be guarded separately (skills + modules PRs)
Consumer whose .gitignore lacks .pre-commit-config.yaml git add -A commits the nix-store symlink. That's why the .gitignore line is part of opting in
New worktree that never entered the shell Commit blocked: config file not found (the hooks are shared, the config is per worktree). After devenv shell -- true, it commits. worktree new now does this
Clone and worktree side by side Both commit; one shared hook, each with its own config
Old branch from before the repo opted in Blocked; entering the shell doesn't help. PREK_ALLOW_NO_CONFIG=1 works once; rebasing onto main fixes it
git-hooks drift (pkgs devenv.yaml set to an older rev) lock-sync fails and names it; sync-locks restores it, then lock-sync passes

Checks

  • fmt: clean. check: all checks passed.
  • This commit went through the new hook (fmt … Passed).

Reviewer notes

  • No consumer changes until it opts in. Each repo's opt-in PR: nix flake update org-pkgs + sync-locks, the follows line, and the .gitignore line.
  • Merge order: this first, then skills, then modules, then home.

🤖 Generated with Claude Code

The org shell now installs a pre-commit hook (cachix/git-hooks.nix via
devenv, run by prek) that runs `nix fmt -- --ci`, so unformatted code is
caught at commit instead of in CI.

devenv reads inputs only from a repo's own devenv.yaml, not from the
imported org-pkgs/devenv, so pkgs pins git-hooks in flake.lock and each
repo opts in with `git-hooks.follows: org-pkgs/git-hooks`. Until it does,
the hooks stay off and the shell prints a note (an enabled hook with no
input would fail devenv). lock-sync now also checks git-hooks, and
sync-locks re-pins pkgs' own devenv.yaml.

Worktrees share the clone's hooks but each reads its own generated
.pre-commit-config.yaml, so `worktree new` enters the shell once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@andrewthomaslee
andrewthomaslee enabled auto-merge (squash) November 26, 2026 11:15
@andrewthomaslee
andrewthomaslee merged commit 36cc52f into main Nov 26, 2026
3 checks passed
andrewthomaslee added a commit to external-systems/skills that referenced this pull request Nov 26, 2026
Ground rules: agents never skip git hooks (--no-verify, -n,
core.hooksPath, PREK_ALLOW_NO_CONFIG) unless the owner says so, and enter
the devenv shell in a new worktree before its first commit (the hook
config is per worktree).

The flake standard reference documents the org shell's git hooks
(external-systems/pkgs#45): the opt-in (follows org-pkgs/git-hooks, the
.gitignore line, the bump order), repo hooks and worktrees.

This repo opts in: org-pkgs bumped with sync-locks, devenv.yaml follows
org-pkgs/git-hooks, .pre-commit-config.yaml ignored.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
andrewthomaslee added a commit to external-systems/modules that referenced this pull request Nov 26, 2026
homeSpec.agents.gitHookGuard (on by default) adds a claude-code
PreToolUse hook on Bash that blocks git commands skipping the git hooks:
--no-verify, git commit -n, core.hooksPath, PREK_ALLOW_NO_CONFIG or SKIP.
The org shell's hooks (external-systems/pkgs#45) are part of the gate and
the ground rules (external-systems/skills#25) say never to skip them;
this enforces it for the agent. The command is parsed with shlex, so a
commit message that mentions a flag is not a false hit.

Bumps skills (the new ground rule) and org-pkgs (git hooks, sync-locks),
and opts this repo in to the org git hooks.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
andrewthomaslee added a commit to external-systems/home that referenced this pull request Nov 26, 2026
## What
- `devenv.yaml`: follows `org-pkgs/git-hooks`, which opts home in to the
org shell's git hooks (external-systems/pkgs#45).
- `.gitignore`: `.pre-commit-config.yaml` (the shell writes it as a link
into the nix store).
- `devenv.nix`: a `pre-push` hook, `clan vars check`, on top of the org
`fmt` pre-commit hook. It uses the real clan binary (no key, no
1Password prompt) through an absolute path, so it also works from a
plain shell outside devenv.
- `flake.lock` / `devenv.lock`: bumps `org-pkgs` (with `sync-locks`) and
`modules`. That brings in the skills ground rule
(external-systems/skills#25) and the claude git hook guard
(external-systems/modules#55).
- `AGENTS.md`, `documentation/docs/machines/index.md`: say where `clan
vars check` runs now (`check`, pre-push) and the worktree note.

## Why
CI's `checks.clan-vars-present` only checks that the vars files exist.
`clan vars check` also validates hashes and recipients, but until now it
only ran if someone ran `check` by hand. Now every push runs it.

## Checks
- `fmt`: clean. `check`: all checks passed; `clan vars check` passed for
all 6 machines.
- This commit went through `fmt` on pre-commit (Passed), and the push
went through `clan vars check` on pre-push (Passed, about 2.7s for the
whole push).
- I re-ran the pre-push hook with an empty environment (no `DEVENV_*`
variables, only HOME and the system PATH): Passed. So an agent pushing
from a plain shell gets the check, and the private `secrets` input
resolves.

## Reviewer notes
- **No machine change on merge.** The modules bump changes the netsa and
matt home-manager profiles (claude settings get the PreToolUse guard;
CLAUDE.md gets the new ground rule). Those only reach machines with a
deploy, which is the owner's call: `clan machines update <machine>` from
`main`.
- After merging, enter the shell once in the home clone, and in any
existing worktree, so each has its hook config.

## Merge order
pkgs#45, skills#25 and modules#55 (all merged), then **this** (last).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@andrewthomaslee
andrewthomaslee deleted the devenv-git-hooks branch November 29, 2026 16:19
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.

1 participant