Repository navigation
Description
Edit: Discovering what happens took a few turns, which is why the initial report is about a failing rust build, which is where I discovered the problem.
This regression was likely introduced in #442540 where the python executable in buildEnv changed and no longer gets NIX_PYTHONPREFIX and NIX_PYTHONPATH, more detail at the bottom in #461884 (comment)
original first issue text
Nixpkgs version
- Unstable (25.11)
Describe the bug
❯ git describe HEAD
25.11-pre-94963-ga40339417f4b
❯ nix-build --attr korrect --eval-system x86_64-linux
trace: evaluation warning: buildRustPackage: `useFetchCargoVendor` is non‐optional and enabled by default as of 25.05, remove it
these 2 derivations will be built:
/nix/store/j4x6ym8xky0ms0vqksk7abch3pl3m5ns-korrect-0.3.3-vendor.drv
/nix/store/jnm94cchf35rxrrpydsmfw437dnzvkdr-korrect-0.3.3.drv
building '/nix/store/j4x6ym8xky0ms0vqksk7abch3pl3m5ns-korrect-0.3.3-vendor.drv' on 'ssh-ng://rosetta-builder'...
copying 0 paths...
building '/nix/store/j4x6ym8xky0ms0vqksk7abch3pl3m5ns-korrect-0.3.3-vendor.drv'...
Traceback (most recent call last):
File "/nix/store/f2aiivbcplcfk3c30dmjgl0iw96yvwaz-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 16, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
error: build of '/nix/store/j4x6ym8xky0ms0vqksk7abch3pl3m5ns-korrect-0.3.3-vendor.drv' on 'ssh-ng://rosetta-builder' failed: Cannot build '/nix/store/j4x6ym8xky0ms0vqksk7abch3pl3m5ns-korrect-0.3.3-vendor.drv'.
Reason: builder failed with exit code 1.
Output paths:
/nix/store/n6gidz7rcxb7drwvhg4k2igfjhwd56d0-korrect-0.3.3-vendor
Last 4 log lines:
> Traceback (most recent call last):
> File "/nix/store/f2aiivbcplcfk3c30dmjgl0iw96yvwaz-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 16, in <module>
> import requests
> ModuleNotFoundError: No module named 'requests'
For full logs, run:
nix log /nix/store/j4x6ym8xky0ms0vqksk7abch3pl3m5ns-korrect-0.3.3-vendor.drv
error: builder for '/nix/store/j4x6ym8xky0ms0vqksk7abch3pl3m5ns-korrect-0.3.3-vendor.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/jnm94cchf35rxrrpydsmfw437dnzvkdr-korrect-0.3.3.drv' failed to buildSteps to reproduce
Either checkout the commit mentioned above, or use nixpkgs-review like this: nix-review pr 460269 --systems x86_64-linux
Expected behaviour
Should work?
Screenshots
No response
Relevant log output
See aboveAdditional context
No response
System metadata
❯ nix-shell -p nix-info --run "nix-info -m"
fetching path input 'path:/nix/store/ipyw6f3ah05zxy1imaydg5bmr8qmsiyc-source'
- system:
"aarch64-darwin" - host os:
Darwin 25.1.0, macOS 26.1 - multi-user?:
yes - sandbox:
no - version:
nix-env (Lix, like Nix) 2.93.3 System type: aarch64-darwin Additional system types: aarch64-darwin, x86_64-darwin Features: gc, signed-caches System configuration file: /etc/nix/nix.conf User configuration files: /Users/dwt/.config/nix/nix.conf:/Users/dwt/.nix-profile/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf Store directory: /nix/store State directory: /nix/var/nix Data directory: /nix/store/wags9ajivrc1r24z9qx5glny5n8q5i4g-lix-2.93.3/share - nixpkgs:
/nix/store/ipyw6f3ah05zxy1imaydg5bmr8qmsiyc-source
Notify maintainers
not sure how to find the maintainers, as this is on the rust build toolchain. Other bugs mentioned these people:
- @TomaSajt @JohnRTitor @mmlb as recent editors of relevant files
- @zowoq @winterqt @figsoda as code owners
Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)
I assert that this issue is relevant for Nixpkgs
- I assert that this is a bug and not a support request.
- I assert that this is not a duplicate of an existing issue.
- I assert that I have read the NixOS Code of Conduct and agree to abide by it.
Is this issue important to you?
Add a 👍 reaction to issues you find important.
Activity
dwt commentedon Nov 15, 2025
Some maybe relevant information: For x86_64-linux builds, I use a vm (I'm on an aarch64 Mac) that I have built via
github:cpick/nix-rosetta-builder. That should not be a reason for this issue, but I did have problems with rosetta, especially under linux before, so perhaps this is part of the reason for this problem. It does however look different than the issues I had with rosetta in the past, as those have always been crashes in binary code, or code hangs, never something like an import package missing.eclairevoyant commentedon Nov 15, 2025
The PR builds fine on my machine.
dwt commentedon Nov 15, 2025
@eclairevoyant thanks!
Looking at the source, this looks correct too:
nixpkgs/pkgs/build-support/rust/fetch-cargo-vendor.nix
Lines 24 to 34 in 042d0c7
seems to correctly pull in requests.
dwt commentedon Nov 15, 2025
Digging into this, it seems that on my builder-vm, the python interpreter that is used by fetch-cargo-vendor-util is somehow configured wrong. Here are some observations:
This implies that the built python virtual env (on the builder) is missing the correct python path and is not including the site-packages directory of itself that contains the requests package.
Not quite sure yet what this means, but it starts to look less likely that this is darwin rosetta problem.
dwt commentedon Nov 15, 2025
This is a somewhat minimal reproduction:
As far as I can see, with
--eval-system x86_64-linuxthe python environment gets built wrong.Now this looks more like a problem with writers.writePython3Bin?
dwt commentedon Nov 15, 2025
Manually adding in the correct environment variables makes it work, so it's probably 'just' a problem with the wrapper generator:
[-]fetch-cargo-vendor-util: Build fails on x86_64-linux because requests not available[/-][+]writers.writePython3Bin: python wrapper doesn't load generated env on x86_64-linux (emulated on darwin with rosetta)[/+]dwt commentedon Nov 15, 2025
Looking at the source in nixpkgs, this line
nixpkgs/pkgs/build-support/writers/scripts.nix
Line 1202 in dc55488
looks suspicious to me. Wouldn't that always be true? To me this reads like if something is not this or not that. Likely not the reason for this bug, but strange none the less.
Introduced here: f6e0ee5 - sadly the commit comment doesn't make clear to my why this change was done.
dwt commentedon Nov 15, 2025
This fails already in
python3.withPackages:dwt commentedon Nov 15, 2025
This commit likely introduced the problem, as it splits how venv creation works, the python executable does not get
NIX_PYTHONPREFIXandNIX_PYTHONPATHany more. However the commit message is cryptic, and I cannot find the pull request that discusses this behavior. That commit was rather recent (oktober 3rd 2025) so it is possible I am the first person to find this regression from that change.edit: found pull request #442540
[-]writers.writePython3Bin: python wrapper doesn't load generated env on x86_64-linux (emulated on darwin with rosetta)[/-][+]python.buildEnv: python wrapper doesn't load generated env on x86_64-linux (emulated on darwin with rosetta)[/+]dwt commentedon Nov 15, 2025
@qbisi could you please take a look at this? I think I have debugged this down to your change being the likely direct reason for this problem, but am not sure how to proceed from here.
dwt commentedon Nov 15, 2025
python.withPackages primary interpreter fails to see env site-packages on cross builds after PR #442540 (python: fix venv creation)
Summary:
After PR #442540 introduced special-casing of the primary Python wrapper (removing NIX_PYTHONPATH/NIX_PYTHONPREFIX/NIX_PYTHONEXECUTABLE from the main interpreter wrapper), python3.withPackages environments built with --eval-system x86_64-linux (on a different host arch via Rosetta) can no longer import packages added to the environment (e.g. requests). Native builds still work.
Reproduction:
Runtime differences (cross vs native):
Cause:
Primary interpreter wrapper now omits NIX_PYTHONPATH (and related vars) relying solely on CPython prefix inference. Under cross builds that inference chooses the base interpreter prefix, not the env root, so env site-packages symlinks are never added to sys.path.
Historical behavior:
Before PR #442540 all executables (including python itself) exported NIX_PYTHONPATH/NIX_PYTHONPREFIX/NIX_PYTHONEXECUTABLE, making path augmentation independent of prefix inference.
Impact:
Breaks python.withPackages usage for cross (eval-system) builds; environment no longer usable for imports unless secondary wrappers are used or NIX_PYTHONPATH is set manually.
[-]python.buildEnv: python wrapper doesn't load generated env on x86_64-linux (emulated on darwin with rosetta)[/-][+]python3.withPackages: python wrapper doesn't load generated env on x86_64-linux (emulated on darwin with rosetta)[/+]20 remaining items
dwt commentedon Nov 18, 2025
@spinda Indeed, setting this rosetta setting fixes the problem for me
That is I set this for my linux vm:
After applying this, I can no longer reproduce
Interesting enough, this is without the patch from @qbisi (at least the way it is merged, it should not be part of unstable yet, which m linux vm is based on)
@spinda Now how do we get this fix into nixpkgs? I have not delved into these kinds of settings before. Especially I am not sure about the support policy for nixpkgs on darwin, do we actually still support older versions than MacOS 14?
pyrox0 commentedon Nov 18, 2025
As of 25.11, the minimum supported MacOS version is 14.0(ref:
nixpkgs/doc/release-notes/rl-2511.section.md
Lines 15 to 18 in 40d5fe7
dwt commentedon Nov 18, 2025
Thanks @pyrox0 that significantly simplifies things.
I have a pull request that just changes that setting. Since GitHub (git ops) is currently down, I cannot push my pull request right now, so that will have to wait till tomorrow.
bengsparks commentedon Nov 18, 2025
Tacking on to this for an easy reproduce package / posterity: https://hydra.nixos.org/build/313316407
I can observe an import failure when running on darwin systems, but on aarch64-linux the derivation continues to build.
See #463023
dwt commentedon Nov 19, 2025
@bengsparks That sounds very similar to #461406 - there the problem was that the generated wrapper also discarded argv 0, which bombed when the executable wasn't called with the full or relative path.
Necoro commentedon Nov 25, 2025
As a passer-by, just the short info that this line is indeed correct: It excludes PyPy thus executing the code only for CPython. Probably because PyPy is broken as mentioned in a referenced issue further down. This commit also removes all the PyPy-based tests.
eclairevoyant commentedon Nov 25, 2025
@Necoro you misunderstood. If
a != b, thenx != a || x != bis always trivially true. That||should be a&&most likely.Though that's an unrelated bug since we're not using pypy here.
fix: mkPythonScript environment inheritance
nixos-discourse commentedon Nov 28, 2025
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/does-anyone-have-python-env-patch-binary-cached-for-aarch64-darwin/72631/1
dwt commentedon Nov 29, 2025
Now that these pull requests have been merged:
At what point should we close this issue? I can no longer reproduce with these fixes applied, though part of the fix is not in master yet..
Update nixpkgs