Skip to content

python: fix venv creation; resolve sys.prefix to realpath - #448141

Draft
qbisi wants to merge 3 commits into
NixOS:masterfrom
qbisi:python-env
Draft

qbisi wants to merge 3 commits into
NixOS:masterfrom
qbisi:python-env

Conversation

@qbisi

@qbisi qbisi commented Oct 3, 2025

Copy link
Copy Markdown
Contributor

An attempt tring to fix python's sys.prefix not targetting the realpath in python-env or python-venv . See #442540

Before

> nix-build -I nixpkgs=$HOME/nixpkgs -E '{pkgs ? import <nixpkgs> {}}: pkgs.python3.withPackages (ps: [])' -o result
> result/bin/python3 -c 'import sys; print(sys.base_prefix); print(sys.prefix)'
/home/qbisi/nixpkgs/result
/home/qbisi/nixpkgs/result

> result/bin/python3 -m venv --system-site-packages result-venv 
> result-venv/bin/python3 -c 'import sys; print(sys.base_prefix); print(sys.prefix)'
/home/qbisi/nixpkgs/result
/home/qbisi/nixpkgs/result-venv
> ls -al result-venv/bin/python3
/home/qbisi/nixpkgs/result/bin/python3

After

> nix-build -I nixpkgs=$HOME/nixpkgs -E '{pkgs ? import <nixpkgs> {}}: pkgs.python3.withPackages (ps: [])' -o result
> result/bin/python3 -c 'import sys; print(sys.base_prefix); print(sys.prefix)'
/nix/store/82hqqjwsg9xgm0mxmbj495hk6sfwd0iv-python3-3.13.7-env
/nix/store/82hqqjwsg9xgm0mxmbj495hk6sfwd0iv-python3-3.13.7-env

> result/bin/python3 -m venv --system-site-packages result-venv 
> result-venv/bin/python3 -c 'import sys; print(sys.base_prefix); print(sys.prefix)'
/nix/store/82hqqjwsg9xgm0mxmbj495hk6sfwd0iv-python3-3.13.7-env
/home/qbisi/nixpkgs/result-venv
> ls -al result-venv/bin/python3
/nix/store/82hqqjwsg9xgm0mxmbj495hk6sfwd0iv-python3-3.13.7-env/bin/python3

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

Partially reverts NixOS#297628.
The --resolve-argv0 option in makeWrapper does nothing, and no
packages use it.
The --resolve-argv0 option was originally introduced in
NixOS#297628 for wrapping Python
executables. No other packages currently use it.
This commit adjusts the behavior of --resolve-argv0: it now also
resolves the dirname of argv0 to its realpath. This ensures that
python venvs always resolve sys.base_prefix to the Nix store path
(e.g., /nix/store/xxx-python3-env), regardless of how the Nix
python environment's python is invoked.
@qbisi qbisi mentioned this pull request Oct 3, 2025
3 of 16 tasks
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 6.topic: python Python is a high-level, general-purpose programming language. 8.has: documentation This PR adds or changes documentation labels Oct 3, 2025
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 16, 2025
@nixpkgs-ci nixpkgs-ci Bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 8, 2026
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: python Python is a high-level, general-purpose programming language. 8.has: documentation This PR adds or changes documentation 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant