python-env: wrap python executable with --resolve-argv0

This commit, together with https://github.com/NixOS/nixpkgs/pull/442540,
changes the way python environments are built:

  * When generating wrappers for python executables, we inherit argv[0]
    from the wrapper. This causes python to initialize its configuration
    in the environment with all the correct paths.
  * We also resolve argv[0] to absolute path when invoking python from
    PATH. This helps set python's prefix correctly on Darwin.

The end result is that python environments no longer appear to be venvs,
and behave more like a vanilla python installation. In addition it's
possible to create a venv using an environment and use packages from
both the environment and the venv.
This commit is contained in:
qbisi
2025-11-16 11:19:14 +08:00
parent 839a7d6dc2
commit abe61db737
@@ -50,6 +50,7 @@ let
if [ "$prg" = "${python.executable}" ]; then
makeWrapper "${python.interpreter}" "$out/bin/$prg" \
--inherit-argv0 \
--resolve-argv0 \
${lib.optionalString (!permitUserSite) ''--set PYTHONNOUSERSITE "true"''} \
${lib.concatStringsSep " " makeWrapperArgs}
elif [ "$(readlink "$prg")" = "${python.executable}" ]; then