Files
ethernet be82958af5 fix(nix): the dev shell's HERMES_PYTHON carries its own dependencies
The shell pointed HERMES_PYTHON at the bare pm-pinned interpreter and reached
the uv2nix site-packages only through PYTHONPATH. Every consumer that replaces
PYTHONPATH (Ink's gateway bootstrap, image attachments, run_tests.sh's env -i)
got an interpreter with no dependencies, so 'hermes --tui' in the shell failed
with 'No module named ruamel'.

devVenv re-homes uv2nix's editable venv onto the pinned interpreter: a real
pyvenv.cfg whose home is the lock's python, devPython's site-packages, and
console scripts re-shebanged onto it. HERMES_PYTHON, VIRTUAL_ENV, python,
pytest and pm are now one interpreter and the shell sets no PYTHONPATH.

The shipped package and the shell share one tool list: runtimeDeps takes
ripgrep and ffmpeg from pm/lock.json too. Reverts the run_tests.sh PYTHONPATH
passthrough, which leaked a caller's PYTHONPATH into every HERMES_PYTHON run.
The dev-venv-self-contained check runs the venv under env -i.
2026-10-23 17:20:39 -04:00

41 lines
1.2 KiB
Nix

# Nix uses the Python family pinned by PM, not a second version constant.
{
lib,
pkgs,
}:
let
pythonFamily =
lockfile:
let
version = (builtins.fromJSON (builtins.readFile lockfile)).packages.python.version;
parts = builtins.match "([0-9]+)\\.([0-9]+)(\\..*)?" version;
in
if parts == null then
throw "packages.python.version '${version}' is not a Python <major>.<minor> version — cannot derive the Nix interpreter from it"
else
builtins.elemAt parts 0 + "." + builtins.elemAt parts 1;
# Select pkgs.python3NN by family ("3.14" -> pkgs.python314). A missing
# lookup throws; there is no default interpreter to fall back to.
selectPython =
family: packageSet:
let
name = "python" + lib.replaceStrings [ "." ] [ "" ] family;
interp = packageSet.${name} or null;
in
if interp == null then
throw "package set does not provide ${name}, but pm/lock.json pins Python ${family} — update the nixpkgs input; Nix will not silently substitute another Python"
else
interp;
lockfile = ../pm/lock.json;
family = pythonFamily lockfile;
in
{
inherit pythonFamily selectPython;
inherit family;
interpreter = selectPython family pkgs;
}