The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(nix): the dev shell's HERMES_PYTHON carries its own dependencies
ethernetbe82958af5ed
diff --git a/nix/checks.nix b/nix/checks.nixindex 446084b4bab..bfd48599c55 100644--- a/nix/checks.nix+++ b/nix/checks.nix@@ -183,6 +183,20 @@ json.dump(sorted(leaf_paths(DEFAULT_CONFIG)), sys.stdout, indent=2)cat $out/*'';+ # The dev shell's HERMES_PYTHON must carry its own dependencies: the+ # TUI and the test runner launch it with PYTHONPATH replaced or cleared.+ dev-venv-self-contained = pkgs.runCommand "hermes-dev-venv-self-contained" { } ''+ venv=${hermes-agent.devVenv}+ env -i "$venv/bin/python3" -c '+ import sys, ruamel.yaml, openai, httpx, pytest+ assert sys.prefix == "'"$venv"'", sys.prefix+ assert sys.base_prefix == "${hermes-agent.pmPython}", sys.base_prefix+ '+ env -i "$venv/bin/pytest" --version+ mkdir -p $out+ echo ok > $out/result+ '';+# Verify the default package builds successfully (cross-platform).# On Linux the runtime checks below already depend on the package,# but this ensures darwin builders also build it during flake check.diff --git a/nix/devShell.nix b/nix/devShell.nixindex dd10d6cecc7..b38fd139a5a 100644--- a/nix/devShell.nix+++ b/nix/devShell.nix@@ -8,7 +8,7 @@{ ... }:{perSystem =- { pkgs, self', ... }:+ { pkgs, lib, self', ... }:letpackages = builtins.attrValues self'.packages;hermesNpmLib = self'.packages.default.passthru.hermesNpmLib;@@ -28,6 +28,10 @@install -Dm755 ${../hermes} $out/bin/hermes'')self'.packages.sandbox+ ]+ # Wayland-only: cage and ghostty pull alsa-lib, which does not+ # evaluate on darwin.+ ++ lib.optionals pkgs.stdenv.isLinux [# Headless Wayland compositor for E2E tests (test:e2e:visual).# cage renders a single client with no window management, so# the Electron window opens at a fixed size without tiling.@@ -42,7 +46,7 @@]++ self'.packages.default.passthru.devDeps;shellHook = ''- # for the devshell to pick up the src (the pm hook reads it)+ # The editable venv's .pth resolves the checkout through this.export HERMES_PYTHON_SRC_ROOT=$(git rev-parse --show-toplevel)${hermesAgentDevShellHook}@@ -51,11 +55,6 @@# Force Node to use Nix's playwright-test binary instead of node_modules/.binexport PATH="${pkgs.playwright-test}/bin:$PATH"- # Let `uv run --active --no-sync` reuse the Nix-built venv instead of- # creating an empty project .venv. Named explicitly: `python` on PATH- # is the lock's interpreter, which is not inside a venv.- export VIRTUAL_ENV="${self'.packages.default.passthru.devPython}"-# The lock's interpreter is python-build-standalone, whose OpenSSL has# no compiled-in NixOS trust store; point it at the CA bundle so# urllib/httpx/requests verify certificates like the nixpkgs one.diff --git a/nix/hermes-agent.nix b/nix/hermes-agent.nixindex 6e6a37ec326..fac6a7be3d7 100644--- a/nix/hermes-agent.nix+++ b/nix/hermes-agent.nix@@ -10,11 +10,10 @@makeWrapper,writeText,callPackage,+ runCommand,electron,- ripgrep,git,openssh,- ffmpeg,# for pmwriteShellApplication,@@ -152,12 +151,15 @@ letfilter = path: _type: !(lib.hasInfix "/__pycache__/" path);};+ # Tools come from pm/lock.json, the same builds `hermes pm install`+ # provisions elsewhere. git and openssh are nixpkgs': the lock pins them for+ # win32 only. hermesNpmLib.nodejs is the pinned node with the pinned npm.runtimeDeps = [hermesNpmLib.nodejs- ripgrep+ pmPackages.ripgrep+ pmPackages.ffmpeggitopenssh- ffmpeg]++ lib.optionals stdenv.isLinux [wl-clipboard@@ -314,19 +316,42 @@ stdenv.mkDerivation (finalAttrs: {passthru =let+ # uv2nix builds the editable venv against the nixpkgs interpreter (it+ # cannot build against a tarball one); devVenv re-homes it onto the+ # interpreter pm/lock.json pins.devPython = (mkHermesVenv (extraDependencyGroups ++ [ "dev" ])).editableVenv;- # The shell's interpreter: the exact build pm/lock.json installs, not- # nixpkgs'. uv2nix structurally needs a nixpkgs interpreter to BUILD the- # venv, so the site-packages stay Nix-owned and only the interpreter the- # shell runs (and `hermes` uses) comes from the lock.- devSitePackages = "${devPython}/${sitePackagesPath}";- pmPython = pythonLock.pinned;+ pmPython = pmPackages.python;++ # A real venv: pyvenv.cfg's `home` is the pinned interpreter and its+ # site-packages are devPython's, so `.pth` files (the editable checkout)+ # load and nothing depends on the caller's PYTHONPATH. Console scripts+ # are re-shebanged onto it so `pytest` and `python -m pytest` agree.+ devVenv = runCommand "hermes-agent-dev-venv" { } ''+ mkdir -p $out/bin $out/lib/python${python.pythonVersion}+ ln -s ${devPython}/${sitePackagesPath} $out/${sitePackagesPath}+ cat > $out/pyvenv.cfg <<EOF+ home = ${pmPython}/bin+ include-system-site-packages = false+ version = ${lib.head (lib.splitString "+" pmPython.version)}+ EOF+ for name in python python3 python${python.pythonVersion}; do+ ln -s ${pmPython}/bin/python3 $out/bin/$name+ done+ for script in ${devPython}/bin/*; do+ name=$(basename "$script")+ [ -e "$out/bin/$name" ] && continue+ if head -n1 "$script" | grep -q '^#!.*python'; then+ { echo "#!$out/bin/python3"; tail -n +2 "$script"; } > "$out/bin/$name"+ chmod +x "$out/bin/$name"+ fi+ done+ '';+pm = writeShellApplication {name = "pm";text = ''- root="$(git rev-parse --show-toplevel)"- cd "$root"- exec python -m pm.cli "$@"+ cd "$(git rev-parse --show-toplevel)"+ exec ${devVenv}/bin/python3 -m pm.cli "$@"'';};in@@ -342,7 +367,7 @@ stdenv.mkDerivation (finalAttrs: {pmRuntimepythondevPython- devSitePackages+ devVenvpmPython;@@ -365,40 +390,20 @@ stdenv.mkDerivation (finalAttrs: {};devShellHook = ''- export HERMES_PYTHON=${pmPython}/bin/python3- # Dependencies come from the Nix-built editable venv; only the- # interpreter is the lock's own build. PYTHONPATH rather than the- # venv's bin/python3, which is the nixpkgs interpreter.- export PYTHONPATH=${devSitePackages}:$HERMES_PYTHON_SRC_ROOT+ export HERMES_PYTHON=${devVenv}/bin/python3+ # `uv run --active --no-sync` reuses this venv instead of creating .venv.+ export VIRTUAL_ENV=${devVenv}'';devDeps =- # The pinned tool set, straight from pm/lock.json: the shell runs the- # same uv, node, npm, ripgrep and ffmpeg `hermes pm install` provisions- # on a non-Nix host. nixpkgs still supplies what pm ships no Linux- # artifact for — git and openssh are win32-only pins — plus the- # platform tools Nix owns. hermesNpmLib.nodejs is the pinned node with- # the pinned npm already in its bin/, the same tree the builds use.- [- hermesNpmLib.nodejs+ runtimeDeps+ ++ [pmPackages.uv- pmPackages.ripgrep- pmPackages.ffmpeg- git- openssh+ devVenv+ pm]++ lib.optionals stdenv.isLinux [- wl-clipboard- xclipcage # for running e2e tests without popping windows- ]- ++ [- # The lock's interpreter first: `python` in the shell is the build a- # real install runs. devPython stays on PATH for its console scripts- # (pytest, debugpy), which are bound to the Nix-built venv.- pmPython- devPython- pm];};diff --git a/nix/pythonLock.nix b/nix/pythonLock.nixindex 6297e48bc01..ac91b641238 100644--- a/nix/pythonLock.nix+++ b/nix/pythonLock.nix@@ -37,11 +37,4 @@ ininherit family;interpreter = selectPython family pkgs;-- # The interpreter the lock itself installs. uv2nix cannot build a venv- # against it (a tarball interpreter has no `pkgs`), so the venv keeps- # `interpreter` while a shell that must match a real runtime takes this.- # Derived here, not passed in: every caller of this file reads `interpreter`- # and nothing else should have to know about the pinned build.- pinned = (pkgs.callPackage ./pm-packages.nix { }).python;}diff --git a/scripts/run_tests.sh b/scripts/run_tests.shindex f60fadc18a1..36d7abffbfb 100755--- a/scripts/run_tests.sh+++ b/scripts/run_tests.sh@@ -55,12 +55,8 @@ _has_pytest() { [ -n "$1" ] && [ -x "$1" ] && "$1" -c 'import pytest' 2>/dev/nul. "$SCRIPT_DIR/_activation.sh"if [ -z "${__HERMES_ACTIVATED:-}" ] && _has_pytest "${HERMES_PYTHON:-}"; thenPYTHON="$HERMES_PYTHON"- # The Nix devShell's HERMES_PYTHON is the lock's interpreter, which finds the- # uv2nix venv only through PYTHONPATH; keep it across `env -i` below.- INHERITED_PYTHONPATH="${PYTHONPATH:-}"echo "▶ not activated — using HERMES_PYTHON: $PYTHON"else- INHERITED_PYTHONPATH=""if ! hermes_activation_current "$REPO_ROOT"; thenif [ -n "${__HERMES_TESTS_REEXEC:-}" ]; thenecho "error: run-in-hermes-env did not produce a current environment for $REPO_ROOT" >&2@@ -79,10 +75,10 @@ fi# ── Live-gateway plugin (computed before we drop env) ───────────────────────-EXTRA_PYTHONPATH="$INHERITED_PYTHONPATH"+EXTRA_PYTHONPATH=""EXTRA_PYTEST_PLUGINS=""if [ -f "$HOME/.hermes/pytest_live_guard.py" ]; then- EXTRA_PYTHONPATH="${EXTRA_PYTHONPATH:+$EXTRA_PYTHONPATH:}$HOME/.hermes"+ EXTRA_PYTHONPATH="$HOME/.hermes"EXTRA_PYTEST_PLUGINS="pytest_live_guard"fidiff --git a/website/docs/getting-started/nix-setup.md b/website/docs/getting-started/nix-setup.mdindex b0ab8f77717..d378b55f79c 100644--- a/website/docs/getting-started/nix-setup.md+++ b/website/docs/getting-started/nix-setup.md@@ -910,8 +910,9 @@ A build-time collision check prevents plugin packages from shadowing core hermes### Dev Shell-The flake provides an editable Python environment with the lock-derived interpreter-and the `dev` dependency group. `HERMES_PYTHON` points to its interpreter. It does not install+The flake provides an editable Python venv with the `dev` dependency group, running+on the interpreter `pm/lock.json` pins. `HERMES_PYTHON` and `VIRTUAL_ENV` point at it,+and it needs no `PYTHONPATH`. It does not installPython dependencies into a repository-local `.venv`. The shell also providesNode.js and runtime tools. Its npm hook refreshes JS workspaces when their inputs change.diff --git a/website/docs/reference/package-management.md b/website/docs/reference/package-management.mdindex db5265f675b..bea6754db2a 100644--- a/website/docs/reference/package-management.md+++ b/website/docs/reference/package-management.md@@ -513,9 +513,10 @@ references. `--offline` and `--cache` control dependency acquisition.For application environment builds, PM must already be able to start in theinvoking Python. These builds are not an interpreter bootstrap. They do not modify a running application'simports or replace its selected environment. Nix's declarative uv2nix builds-remain Nix-owned: `nix develop` still builds its dependencies with uv2nix, but-runs them on the interpreter `pm/lock.json` pins (uv2nix cannot build a venv-against a tarball interpreter, so only the interpreter comes from the lock).+remain Nix-owned: `nix develop` still builds its dependencies with uv2nix, then+re-homes that venv onto the interpreter `pm/lock.json` pins (uv2nix cannot build+against a tarball interpreter). The shell's uv, node, npm, ripgrep and ffmpeg are+the lock's builds too.Package-manager commands for unrelated projects or agentsandboxes do not manage Hermes itself.