diff --git a/packages/codex-api-proxy/daemon-pythonpath.patch b/packages/codex-api-proxy/daemon-pythonpath.patch new file mode 100644 index 0000000..c596715 --- /dev/null +++ b/packages/codex-api-proxy/daemon-pythonpath.patch @@ -0,0 +1,19 @@ +--- a/src/codex_api_proxy/cli.py ++++ b/src/codex_api_proxy/cli.py +@@ -405,11 +405,15 @@ + if args.proxy: + command.extend(["--proxy", args.proxy]) + ++ env = dict(os.environ) ++ env["PYTHONPATH"] = os.pathsep.join(path for path in sys.path if path) ++ + with args.log_file.open("ab") as log: + process = subprocess.Popen( + command, + stdin=subprocess.DEVNULL, + stdout=log, + stderr=subprocess.STDOUT, ++ env=env, + start_new_session=True, + ) + args.pid_file.write_text(f"{process.pid}\n", encoding="utf-8") diff --git a/packages/codex-api-proxy/package.nix b/packages/codex-api-proxy/package.nix index d0b5831..3b46669 100644 --- a/packages/codex-api-proxy/package.nix +++ b/packages/codex-api-proxy/package.nix @@ -23,6 +23,12 @@ python3Packages.buildPythonApplication rec { setuptools ]; + # `start` re-runs sys.executable with `-m codex_api_proxy.cli`. The Nix + # console wrapper injects site paths with site.addsitedir, not PYTHONPATH, + # so the daemon child cannot import the package. Pass the parent's sys.path + # through the environment. + patches = [ ./daemon-pythonpath.patch ]; + # [project.dependencies] plus the uvicorn[standard] extra. dependencies = with python3Packages; [ fastapi