Skip to content

build(nix): expose libstdc++ in dev-shell so pymarkdown runs on NixOS - #700

Merged
c-vigo merged 3 commits into
feature/625-nix-claude-migrationfrom
bugfix/698-pymarkdown-nixos
Jun 24, 2026
Merged

c-vigo merged 3 commits into
feature/625-nix-claude-migrationfrom
bugfix/698-pymarkdown-nixos

Conversation

@c-vigo

@c-vigo c-vigo commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

The pymarkdown pre-commit hook failed on a NixOS host with
ImportError: libstdc++.so.6: cannot open shared object file, forcing
--no-verify on every local commit. pymarkdown runs from pre-commit's own
manylinux-wheel Python env (not the project venv); its dependency pyjson5 is a
C extension linked against libstdc++.so.6, which a NixOS host does not put on
the loader path outside an FHS environment. Unlike the standalone binaries in
sibling issue #697, pymarkdown is not packaged in nixpkgs, so the "add to
devTools + language: system" recipe does not apply.

This PR makes the existing manylinux wheel resolve its C library by exposing the
Nix C++ runtime on the dev-shell loader path.

Type of Change

  • build -- Build system or dependency changes

Modifiers

  • Breaking change (!)

Changes Made

  • flake.nix (mkProjectShell): append ${pkgs.stdenv.cc.cc.lib}/lib to
    LD_LIBRARY_PATH via the shell hook, preserving the value mkShell already
    injects (it auto-populates LD_LIBRARY_PATH from some packages' propagated
    libs, e.g. alsa-lib) and any host-set value. This is the same libstdc++
    the Nix toolchain itself links, so there is no version clash with the other
    dev-shell binaries, and it generalises to any future C-extension Python hook.
  • tests/test_flake_devshell.py: two dev-shell parity tests (mirroring the
    existing dev_shell_env / BATS_LIB_PATH tests) asserting LD_LIBRARY_PATH
    carries libstdc++.so.6 and that the C library loads under the dev-shell
    loader.
  • docs/NIX.md: documents the mechanism (and notes nix-ld as a non-enforceable
    fallback) under the pre-commit decisions section.
  • CHANGELOG.md (+ scaffolded mirror via sync_manifest): ### Fixed entry.

Approach chosen and alternatives rejected

  • Chosen — Option 1 (dev-shell LD_LIBRARY_PATH). Smallest, robust change;
    keeps the upstream rev: pin; verified that pymarkdown runs and that the other
    Nix binaries (just, nixfmt, jq, rg, git, nvim, lazygit, delta,
    bat, eza, taplo, shellcheck, claude) still run with it set. Used
    LD_LIBRARY_PATH rather than NIX_LD/NIX_LD_LIBRARY_PATH: the latter only
    helps binaries launched through the NixOS stub-ld, whereas the wheel's C
    extension is dlopen'd by an already-running Nix-store CPython that honours
    LD_LIBRARY_PATH directly — the more general and host-independent lever.
  • Rejected — Option 2 (package pymarkdown in the flake). Most hermetic, but
    pymarkdown is absent from nixpkgs, so it means a buildPythonApplication from
    the PyPI sdist plus a version to maintain — more work than warranted to unblock
    the hook, and the env fix is clean and robust. Left as a possible later
    hermetic end-state.
  • Rejected as the fix — Option 3 (nix-ld host config). Per-contributor
    system config the repo cannot enforce; documented as a fallback only.

Changelog Entry

Fixed

  • pymarkdown pre-commit hook no longer fails on NixOS (pyjson5 C extension missing libstdc++) (#698)
    • The pymarkdown hook runs from pre-commit's own manylinux-wheel Python env, whose dependency pyjson5 is a C extension linked against libstdc++.so.6; on a NixOS host that library is not on the loader path outside an FHS environment, so the hook aborted with ImportError: libstdc++.so.6: cannot open shared object file and forced --no-verify. Unlike the standalone binaries in #697, pymarkdown is not in nixpkgs, so the "add to devTools + language: system" recipe does not apply
    • mkProjectShell now appends ${pkgs.stdenv.cc.cc.lib}/lib to LD_LIBRARY_PATH in the dev-shell, so the wheel's C extension resolves the Nix C++ runtime. It is the same libstdc++ the Nix toolchain itself links, so the other dev-shell binaries keep working (no version clash); the existing mkShell-injected LD_LIBRARY_PATH is appended to, not clobbered. Generalises to any future C-extension Python hook. Documented in docs/NIX.md
    • Added dev-shell parity tests asserting LD_LIBRARY_PATH carries libstdc++.so.6 and that the C library loads under the dev-shell loader

Testing

  • Tests pass locally
  • Manual testing performed (describe below)

Manual Testing Details

All run on the NixOS host inside nix develop:

  • Reproduced the bug (before the fix):
    nix develop -c bash -c 'uv run pre-commit run pymarkdown --all-files'
    → ImportError: libstdc++.so.6: cannot open shared object file.
  • TDD RED: the two new tests failed before the flake change
    (AssertionError: libstdc++.so.6 not found under LD_LIBRARY_PATH: /nix/store/...-alsa-lib.../lib), confirming mkShell already set a value the
    fix had to preserve.
  • Fix verified — hook passes:
    nix develop -c bash -c 'uv run pre-commit run pymarkdown --all-files' →
    pymarkdown ... Passed (no manual env export, no --no-verify).
  • Parity tests GREEN: uv run pytest tests/test_flake_devshell.py →
    8 passed.
  • No regression to other Nix tools: just, nixfmt, jq, rg, git,
    nvim, lazygit, delta, bat, eza, taplo, shellcheck, claude all
    run with LD_LIBRARY_PATH set (ruff is absent on this branch only because it
    joins devTools in [BUG] pre-commit: source binary hooks (ruff, ruff-format, typos) from the flake for NixOS compatibility #697 — not a regression here).
  • Flake clean: nixfmt --check flake.nix clean; nix eval of
    devShells/checks evaluate; nix build .#checks.x86_64-linux.format
    succeeds.

--no-verify rationale: the pymarkdown/ruff/typos pre-commit hooks
cannot run on this NixOS host pre-fix (the very bug being fixed, plus #697), so
the TDD commits used git commit --no-verify. CI re-runs the full hook suite
under provision-via-flake. The new markdown was validated manually:
pre-commit run pymarkdown --files CHANGELOG.md docs/NIX.md → Passed.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (docs/NIX.md)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Heads-up for the reviewer — likely merge conflicts with #697. Sibling issue
#697 (bugfix/697-precommit-flake-hooks) also edits flake.nix,
.pre-commit-config.yaml, and CHANGELOG.md:

Both branches are based on feature/625-nix-claude-migration.

Refs: #698

c-vigo added 2 commits June 24, 2026 18:40
The pymarkdown pre-commit hook runs from pre-commit's own manylinux-wheel
Python env, whose dependency pyjson5 is a C extension linked against
libstdc++.so.6. On a NixOS host that library is not on the loader path
outside an FHS environment, so the hook failed with an ImportError and
forced --no-verify. pymarkdown is not in nixpkgs, so the #697
"devTools + language:system" recipe does not apply.

mkProjectShell now appends ${pkgs.stdenv.cc.cc.lib}/lib to
LD_LIBRARY_PATH in the dev-shell (the same libstdc++ the Nix toolchain
links, so no version clash), preserving any mkShell-injected value.
Documented in docs/NIX.md.

Refs: #698
@c-vigo c-vigo self-assigned this Jun 24, 2026
…' into bugfix/698-pymarkdown-nixos

# Conflicts:
#	CHANGELOG.md
#	assets/workspace/.devcontainer/CHANGELOG.md
@c-vigo
c-vigo merged commit 77a8f4a into feature/625-nix-claude-migration Jun 24, 2026
2 checks passed
@c-vigo
c-vigo deleted the bugfix/698-pymarkdown-nixos branch June 24, 2026 17:00
c-vigo added a commit that referenced this pull request Jun 29, 2026
Exposing the Nix store python3 on the dev-shell PATH (#729) made pre-commit build the pymarkdown hook env with the Nix interpreter, whose manylinux pyjson5 wheel cannot resolve libstdc++ on FHS hosts — the #700 LD_LIBRARY_PATH rescue is NixOS-gated (per #703), so it regressed #698 on the ubuntu CI runner. Revert to restore CI green; a host-safe re-implementation follows.

Refs: #729
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