Skip to content

feat(hooks): package pymarkdown and promote it to a system hook - #1177

Merged
c-vigo merged 4 commits into
devfrom
feature/1170-pymarkdown-system-hook
Jul 17, 2026
Merged

c-vigo merged 4 commits into
devfrom
feature/1170-pymarkdown-system-hook

Conversation

@c-vigo

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

Copy link
Copy Markdown
Contributor

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.yamls 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 direnv-mode scaffold ships hand-managed pre-commit config whose pymarkdown hook cannot run on host runners #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 direnv-mode scaffold ships hand-managed pre-commit config whose pymarkdown hook cannot run on host runners #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

c-vigo added 4 commits July 17, 2026 12:13
Package pymarkdownlnt (nix/pymarkdown.nix) with its two PyPI-only
pure-Python deps not in nixpkgs (application-properties, columnar);
pyjson5 comes from nixpkgs. Add it to the toolchain SSoT (nix/devtools.nix)
so it reaches the dev-shell, image, and vigos.packages home module.

Convert the pymarkdown hookDef in nix/hooks.nix from a runner-only
remote-repo hook to a language: system hook rendered in all three
artifacts: the committed runner + scaffold YAML, the sandbox
checks.pre-commit gate, and the consumer generation surface. All run
`-c .pymarkdown fix` with the same excludes; the gate operates on the
sandbox source copy so fix never mutates the real tree. Drop the now
unused remoteRepos.pymarkdown pin and its repoOrder entry.

Refs: #1170
pymarkdown is now packaged in the flake and rendered as a language:
system hook in all three artifacts (#1170), so the "not in nixpkgs /
drops pymarkdown" rationale is stale. Update the direnv flake-hooks
default messaging in assets/init-workspace.sh (and its bats comment),
the residual notes in docs/NIX.md and docs/MIGRATION.md, and record the
change under CHANGELOG Unreleased -> Added. The direnv default mechanism
stays; its rationale is now that the flake set resolves every hook from
the Nix store rather than building the committed YAML remote pre-commit
repo hook envs per runner.

Refs: #1170
@c-vigo
c-vigo marked this pull request as ready for review July 17, 2026 11:35
@c-vigo
c-vigo merged commit 374bcc9 into dev Jul 17, 2026
15 checks passed
@c-vigo
c-vigo deleted the feature/1170-pymarkdown-system-hook branch July 17, 2026 11:35
c-vigo added a commit that referenced this pull request Jul 17, 2026
## Summary

Closes #1178.

Adds the `docs` capability module (`nix/modules/docs.nix`):
document-oriented consumers opt in with `mkProjectShell { modules = [
"docs" ]; }` and get `typst` + `typstyle` on the dev-shell PATH. First
consumer: exo-pet/vault (direnv-only deployment in the current wave);
qms and EXOMA presentation/grant repos share the profile — the ADR's
ask-gate is met.

- v1 contract per ADR-capability-modules: packages only, no version knob
— nixpkgs ships a single typst per pin, so the module tracks the
toolchain pin (typst output isn't version-stable; a consumer's
`generated/` artifacts regenerate once at migration).
- Deliberate v1 exclusions documented in `docs/NIX.md` and the module
header: pandoc/LaTeX (ask-gated), headless drawio/excalidraw export
(electron-shaped, repo-owned), Python doc libs (pymupdf4llm/openpyxl →
consumer `pyproject.toml` via uv).
- Registered in `nix/modules/default.nix`; geant4/rust/fortran/root stay
deferred.

## Verification

- TDD: RED `779252c3` (missing `module-docs` check attr) → GREEN
`29ed4844` → docs `455aa3f8`; merge of dev (post-#1177) `5bb9d9dc`
clean, no conflicts.
- `pytest tests/test_flake_modules.py` → 9 passed (re-run by the
reviewing session after the dev merge).
- Through the modules path (`nix develop .#checks…module-docs`): `typst
0.14.2`, `typstyle 0.14.4` — proven from the module's own
purity-isolated shell, not devkit's own devshell (re-run by the
reviewing session).
- Full `prek run --all-files` green (incl. the new pymarkdown system
hook from #1177), working tree clean.
c-vigo added a commit that referenced this pull request Jul 17, 2026
…1184)

## What & why

On a non-Python **direnv-mode** consumer, the CI preamble keeps the Nix
CPython on `PATH` (the manylinux exclusion of #1028 only applies when
`pyproject.toml` exists). A `uvx`-run tool whose manylinux native wheel
links `libstdc++.so.6` then aborts with `libstdc++.so.6: cannot open
shared object file`, because the Nix loader does not search `/usr/lib` —
the same failure class as the dropped `pymarkdown`/`pyjson5` hook.

Fixes #1181.

## Approach

Ship the proven org-config pattern as a **base justfile helper** rather
than a global preamble export or a change to `setup-devkit-toolchain`
(owned by #1180). The root `assets/workspace/justfile` gains a
`with-native-libs +command` recipe:

- Lives in the **root** justfile so it is reachable in **every**
delivery mode (direnv/bare have no `.devcontainer/justfile.devc`) —
direnv-mode CI is exactly the case that needs it.
- Derives a **command-scoped** `LD_LIBRARY_PATH` from
`$VIGOS_STDCPP_LIB` (dev-shell export) or, failing that, from the
on-`PATH` `cc` wrapper via `cc -print-file-name=libstdc++.so.6` (the
wrapper is on the preamble-forwarded PATH; `cc` echoes the bare name
back — not an absolute path — when it cannot resolve the lib, so the
leading-`/` check degrades to a no-op).
- Scoped to the one wrapped command, so the Nix `libstdc++` never leaks
into other tools' processes; degrades to the caller's own
`LD_LIBRARY_PATH` (or empty) when neither source resolves.

A consumer recipe wraps its tool:

```just
validate:
    just with-native-libs uvx --from [email protected] otterdog validate --local
```

## Provenance & evidence

- Mirrors the consumer-side fix proven in **org-config@f01175a**
(vig-os/org-config#40), reproduced under a CI-faithful `env -i
PATH=<store bins>` simulation.
- TDD: failing bats test committed first, then the recipe. New coverage
in `tests/bats/just.bats` exercises all branches:
  - derives `LD_LIBRARY_PATH` from the on-PATH `cc` wrapper,
  - prefers `$VIGOS_STDCPP_LIB` over deriving from `cc`,
  - no-ops cleanly when the lib is not found,
  - prepends to an existing `LD_LIBRARY_PATH`.
- `bats tests/bats/just.bats`: **51/51 pass** (5 new). `prek run
--all-files`: **fully green**.

## Scope

Minimal diff — root justfile helper, its bats coverage, changelog (+
synced `.devcontainer/` mirror), and NIX.md docs. Does **not** touch
`setup-devkit-toolchain` (#1180) and does **not** resurrect the
pymarkdown hook (nix-packaged separately in #1177).

## Review fix: no empty LD_LIBRARY_PATH entries

Review found an edge case: when nothing resolved the libstdc++ dir (no
`$VIGOS_STDCPP_LIB`, `cc` absent or lib not found) the recipe still
composed the prefix, yielding `:/pre/existing` when the caller had an
`LD_LIBRARY_PATH` (a leading empty entry = **cwd** on the dynamic
loader's search path — a tool run from an untrusted directory could load
a planted `libstdc++.so.6`), or setting the variable to `""` when it did
not. Fixed (TDD, RED then GREEN): the recipe now branches on a non-empty
prefix and otherwise runs the command with the environment **untouched**
— never a leading colon, never set-to-empty. New bats coverage asserts
the caller's value passes through byte-identical and that the variable
stays unset in the pure no-op case. After the fix: `bats
tests/bats/just.bats` **52/52 pass**, `prek run --all-files` fully
green.

Refs: #1181, vig-os/org-config#40
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