Skip to content

fix: let extraPackages python env win python3 on PATH - #1246

Merged
c-vigo merged 5 commits into
devfrom
bugfix/1230-extrapackages-python-shadowed
Jul 21, 2026
Merged

c-vigo merged 5 commits into
devfrom
bugfix/1230-extrapackages-python-shadowed

Conversation

@c-vigo

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

Copy link
Copy Markdown
Contributor

Summary

mkProjectShell consumers who add Python libraries the documented way — a
pythonXX.withPackages env passed through extraPackages — silently got the
builder's bare pinned 3.14 interpreter on PATH with none of their
libraries, surfacing only later as ModuleNotFoundError. This blocked the
cad2gdml onboarding (FreeCAD via extraPackages).

Closes #1230

Root cause

The bug is a python3 PATH race, but not the one the issue's minimal repro
suggested. Reordering extraPackages ahead of the bare python in packages
(the issue's suggested fix 1) does not work, and neither does dropping the
bare python — I verified both live. The interpreter that actually shadows the
consumer's env is vig-utils: it is a buildPythonPackage in devTools,
pinned to 3.14, and its Python setup hook propagates that 3.14 interpreter
onto PATH
ahead of anything in packages. This is the exact same shadowing
pythonOverrideHook (flake.nix) already fights for the python = … override
case — and it beats it the only reliable way in this builder: a shellHook
PATH prepend.

Evidence (before fix, extraPackages = [ python313.withPackages … ]):

python3 is /nix/store/…-python3-3.14.4/bin/python3        ← from vig-utils, wins
python3 is /nix/store/…-python3-3.13.13-env/bin/python3   ← consumer env, loses

Fix

Prepend any extraPackages-provided Python env in the shellHook (identified by
its python passthru, which a withPackages env carries and the bare
interpreter / plain library packages do not), using the same PATH-order
mechanism as pythonOverrideHook. Placed before pythonOverrideHook in the
chain so an explicit python override (the primary interpreter knob, #1038)
still wins if a consumer sets both.

  • packages list unchanged, so the zero-extraPackages default dev-shell stays
    byte-identical (the #1038 parity test still passes).
  • The python override path and #729 bare-python3 presence are unaffected.

Test evidence

New tests/test_flake_devshell.py::test_devshell_extrapackages_python_env_wins_on_path
builds a real mkProjectShell with a python313.withPackages([setuptools]) env
in extraPackages, enters it under nix develop --ignore-environment, and
asserts python3 resolves to the env (3.13) and imports its setuptools.

  • RED (before fix): ModuleNotFoundError: No module named 'setuptools' /
    python3 reports 3.14 — the exact issue reproduction.
  • GREEN (after fix): 1 passed.

Regression set (all pass): python_default_is_byte_identical,
python_override_switches_interpreter, exposes_python3_and_precommit, plus the
new test — 4 passed.

prek run --all-files: fully green.

c-vigo added 5 commits July 21, 2026 13:21
A pythonXX.withPackages env passed via extraPackages was silently shadowed
by vig-utils' propagated pinned 3.14 interpreter, so the consumer got the
bare interpreter with none of their libraries. Prepend such envs in the
shellHook (the same PATH-order mechanism pythonOverrideHook uses) so the
consumer's env owns python3/python.

Refs: #1230
@c-vigo
c-vigo merged commit ba0c770 into dev Jul 21, 2026
15 checks passed
@c-vigo
c-vigo deleted the bugfix/1230-extrapackages-python-shadowed branch July 21, 2026 11:57
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