Skip to content

ci: pre-commit hook sets the opensecret dev-shell knobs on nix develop - #969

Merged
AnthonyRonning merged 1 commit into
masterfrom
ci/precommit-dev-shell-env
Sep 18, 2026
Merged

AnthonyRonning merged 1 commit into
masterfrom
ci/precommit-dev-shell-env

Conversation

@AnthonyRonning

@AnthonyRonning AnthonyRonning commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

.githooks/pre-commit ran the opensecret component as

nix develop --no-update-lock-file '.?submodules=1' -c env MAPLE_HOOK_IN_NIX=1 OPENSECRET_DEV_POSTGRES=0 OPENSECRET_DEV_ENV=0 OPENSECRET_DEV_CONTAINERS=0 sh .githooks/pre-commit

so the knobs reached only the check script. nix develop runs the flake's shellHook before the -c command, and the opensecret shell hook defaults every knob to 1. On every commit that staged backend files it therefore ran initdb, started PostgreSQL on port 5432 from services/opensecret/.pgdata in the committing checkout (or silently reused whatever was already listening on that port), created the opensecret_user role and opensecret database, and copied .env.sample to .env when the checkout had none. The server outlived the commit and had to be found and stopped by hand. The hook's own comment, services/opensecret/AGENTS.md, and the develop-opensecret skill all said this does not happen.

Fix: run_component sets the component ENV=VALUE pairs on nix develop itself (env -u GIT_DIR ... OPENSECRET_DEV_POSTGRES=0 ... nix develop ... -c env MAPLE_HOOK_IN_NIX=1 sh <script>). nix develop passes its environment through, so the script sees the same values. The no-Nix path already did this and is unchanged.

The other component shells (.#ci, sdk, proxy, apps/maple-agent) only export variables or pick a cargo build directory behind their own knob, so opensecret remains the only component that passes environment through the hook.

Verification

  • Reproduction against the real opensecret flake (macOS, scratch PGDATA and a spare port so nothing shared was touched). Old form: the initdb transcript, server started, CREATE ROLE, CREATE DATABASE, pg_isready accepting connections, and a fresh .env in the checkout, while the -c command itself printed OPENSECRET_DEV_POSTGRES=0. New form: no initdb, no cluster directory, pg_isready "no response", no .env, and cargo still resolves inside the shell.
  • A commit was made through the fixed hook with MAPLE_HOOK_ONLY=repo,opensecret: repo (the scripts/ci unit tests) in 20 s, then the real opensecret component (cargo fmt --check, Clippy with -D warnings, cargo test: 647 passed, 0 failed, 23 ignored) in 128 s. The hook output has no initdb/server started lines, no .pgdata/ or .env appeared in the checkout, and nothing was listening on 5432 afterwards.
  • shellcheck -s sh on .githooks/pre-commit, .githooks/lib/common.sh, .githooks/repo-checks, and the opensecret script: clean.
  • A throwaway fixture-repository test (real hook files plus a stub nix that records the environment nix develop receives) failed against the old hook and passed with the fix. It is not part of this PR.

Note

If the opensecret devShells.default shellHook grows new stateful steps, they need their own knob and an entry in the hook's run_component call for opensecret.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

Maple development preview: https://9a711643.maple-ca8.pages.dev

Commit: ad387794cb26703f17496775b91006dd4ca4a7c0

Uses development API, billing, flags and PCR configuration. Cloudflare Access applies.

…it hook

The hook ran `nix develop ... -c env OPENSECRET_DEV_POSTGRES=0 ... sh
<script>`, so the knobs reached only the check script. A flake's shellHook
runs before the `-c` command, and by then the opensecret shell had already
run initdb, started a PostgreSQL server on the default port from `.pgdata`
in the committing checkout, and copied `.env.sample` to `.env` when absent.
The server outlived the commit. Set the component environment on `nix
develop` itself; it passes its environment through, so the script still
sees the same values.
@AnthonyRonning
AnthonyRonning force-pushed the ci/precommit-dev-shell-env branch from ad38779 to c16c454 Compare September 18, 2026 17:08
@AnthonyRonning
AnthonyRonning merged commit 0a49b7f into master Sep 18, 2026
20 checks passed
@AnthonyRonning
AnthonyRonning deleted the ci/precommit-dev-shell-env branch September 18, 2026 17:27
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