Skip to content

fix(scaffold): default direnv to flake-generated pre-commit hooks - #1168

Merged
c-vigo merged 3 commits into
devfrom
bugfix/1167-direnv-flake-hooks
Jul 17, 2026
Merged

c-vigo merged 3 commits into
devfrom
bugfix/1167-direnv-flake-hooks

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1167.

A fresh direnv scaffold now defaults to flake-generated pre-commit hooks instead of the hand-managed .pre-commit-config.yaml.

Why

The direnv (and bare) CI lanes run on the bare host runner — resolve-toolchain emits an empty container image, so the job runs directly on the runner rather than inside the devkit image. The image ships the FHS dynamic loader + C++ runtime that the scaffolded YAML's pymarkdown hook needs (its native pyjson5); the host runner does not, so the hook fails with ImportError: libstdc++.so.6. Both existing direnv consumers (commit-action, sync-issues-action) had already switched to flake-generated hooks by hand. Observed during the 1.3.1 rollout on vig-os/org-config.

What changed

  • assets/init-workspace.sh: on a fresh direnv scaffold, activate an empty hooks = { }; in flake.nix (deterministic single insert after the unique extraPackages line) and drop the seeded .pre-commit-config.yaml. The shared flake hook set then generates the config as a /nix/store symlink, which is gitignored from the first scaffold (render_gitignore gains a FLAKE_HOOKS_DEFAULT path so the ignore is seeded before the symlink exists).
  • Guarded on a fresh scaffold: a consumer's own preserved flake.nix or committed .pre-commit-config.yaml is never rewritten.
  • Out of scope by design: container/both keep the hand-managed YAML (they run inside the image where pymarkdown works); bare ships no flake.nix (it prunes it) and the consumer owns its own toolchain there.
  • Docs: docs/MIGRATION.md pre-commit opt-in section + residual note; CHANGELOG.md.

Testing

  • TDD: 6 new bats cases in tests/bats/init-workspace.bats (drop YAML, activate hooks, gitignore seed; container/both keep YAML + opt-in; consumer files preserved).
  • Full init-workspace.bats suite green (218 tests); test_scaffold_lint.py + test_install_script.py green.
  • End-to-end: generated flake.nix passes nix-instantiate --parse and is nixfmt --check clean.
  • Full pre-commit run --all-files green.

Refs: #1167

c-vigo added 3 commits July 17, 2026 10:45
The direnv CI lane runs on the bare host runner (resolve-toolchain emits an
empty container image), which lacks the devkit image's FHS loader and C++
runtime that the hand-managed .pre-commit-config.yaml's pymarkdown hook (native
pyjson5) needs — so pymarkdown fails with ImportError: libstdc++.so.6 there.
A fresh direnv scaffold now activates an empty `hooks = { }` in flake.nix and
drops the hand-managed YAML, so the shared flake hook set generates the config
(dropping pymarkdown, which is not in nixpkgs) and runs host-side. The generated
store-symlink config is gitignored from the first scaffold.

Gated on a fresh scaffold: a consumer's own preserved flake.nix or committed
.pre-commit-config.yaml is never rewritten. Container/both keep the hand-managed
YAML (they run inside the image where pymarkdown works). bare is out of scope —
it prunes flake.nix and the consumer owns its own toolchain.

Refs: #1167
@c-vigo
c-vigo merged commit 38106d5 into dev Jul 17, 2026
13 checks passed
@c-vigo
c-vigo deleted the bugfix/1167-direnv-flake-hooks branch July 17, 2026 09:14
c-vigo added a commit that referenced this pull request Jul 17, 2026
## Summary

Closes #1170.

Packages `pymarkdownlnt` 0.9.23 in the flake (`nix/pymarkdown.nix`:
pymarkdownlnt + its two PyPI-only pure-Python deps
`application-properties` 0.9.3 and `columnar` 1.4.1; the native
`pyjson5` comes from nixpkgs) and promotes the `pymarkdown` hook from a
runner-only remote-repo hook to a `language: system` hook across **all
three** artifacts (committed runner YAML, sandbox `checks.pre-commit`
gate, consumer flake-generated surface). This retires the documented
"pymarkdown residual" — the reason direnv consumers lost markdown
linting after #1167/#1168 — and unblocks the direnv-only deployment of
exo-pet/vault (a markdown documentation vault).

- Built against `python314` (toolchain default); all three packages are
pure Python and pass `pythonImportsCheck`.
- `remoteRepos.pymarkdown` pin and its `repoOrder` entry removed; both
committed `.pre-commit-config.yaml`s re-rendered to the system-hook
form.
- "Drops pymarkdown / not in nixpkgs" messaging retired in
`assets/init-workspace.sh`, `docs/NIX.md`, `docs/MIGRATION.md`, and the
#1167 bats assertions.
- **Deliberate deviation from the issue text:** the sandbox gate mirrors
the hook in `fix` mode (on the sandboxed copy, fail-on-modify — same
semantics as the ruff/end-of-file-fixer gates and identical to the
runner), not `scan`: scan is strictly stricter and would fail the gate
on pre-existing MD013 line-length debt, an out-of-scope behavior change.
Documented in the hookDef comment.

## Verification

- TDD: RED `d76dbcc7` → GREEN `bf1c866a` → docs `98db437e`.
- `pymarkdown version` → 0.9.23 in the dev shell; `nix build
.#checks.x86_64-linux.pre-commit` → gate builds and passes — re-run by
the reviewing session.
- `pytest tests/test_flake_hooks.py tests/test_flake_devshell.py` → 40
passed, 1 skipped (re-run by the reviewing session); bats #1167
direnv-hooks tests 6/6.
- Full `prek run --all-files` in the dev shell: green (pymarkdown runs
over all markdown), working tree clean (re-run by the reviewing
session).
- Strict `buildEnv` collision probe (pymarkdown + pythonEnv) assembles
cleanly; the full image build is left to CI.

## Notes

- The NixOS-only `LD_LIBRARY_PATH` libstdc++ shim is no longer strictly
needed for pymarkdown but is left in place (general safety net, minimal
diff).
- Expect CHANGELOG (+ mirror) and `nix/hooks.nix`/test-file merge
conflicts with sibling PRs #1174/#1175/#1176 — union-merge as usual.
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