Skip to content

lintspec: fetch-cargo-vendor-util fails during build #385366

Open

Description

@beeb

Edit: related: NixOS/nix#12698

Nixpkgs version

  • Unstable (25.05)

Describe the bug

When trying to build my package lintspec on macOS x86, the build fails because of the tooling. The culprit seems to be fetch-cargo-vendor-util which tries to use python's requests package and fails to build with PermissionError: [Errno 1] Operation not permitted

Steps to reproduce

  • checkout nixpkgs on macOS intel (x86_64) machine
  • nix build .#lintspec
  • error

Expected behaviour

The package should build or at least get past the cargo vendor stuff

Screenshots

No response

Relevant log output

Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/0wfj7a0bkgjbzsw7c3zidpc4rmx1kfci-source
source root is source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
Traceback (most recent call last):
  File "/nix/store/xgbpy30i497qw8q8mdsknzpp7ngns76v-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 15, in <module>
    import requests
  File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/__init__.py", line 164, in <module>
    from .api import delete, get, head, options, patch, post, put, request
  File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/api.py", line 11, in <module>
    from . import sessions
  File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/sessions.py", line 15, in <module>
    from .adapters import HTTPAdapter
  File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/adapters.py", line 81, in <module>
    _preloaded_ssl_context.load_verify_locations(
PermissionError: [Errno 1] Operation not permitted

Additional context

macOS Sonoma 14.6.1 on MacBook Pro 15-inch 2019

System metadata

  • system: "x86_64-darwin"
  • host os: Darwin 23.6.0, macOS 10.16
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.15.1
  • channels(root): ""
  • channels(valentin): "home-manager, nixpkgs"
  • nixpkgs: /Users/valentin/.nix-defexpr/channels/nixpkgs

Are you using nix-darwin?

No, I am not using nix-darwin.

Notify maintainers


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

Is this issue important to you?

Add a 👍 reaction to issues you find important.

Activity

  1. added
    0.kind: bug
    6.topic: darwin
    on Feb 26, 2025
  2. beeb commented on Feb 26, 2025

    @beeb
    ContributorAuthor

    @TomaSajt I think you wrote that util?

  3. TomaSajt commented on Feb 26, 2025

    @TomaSajt
    Contributor

    Does this happen with any other package that uses fetchCargoVendor?
    (So most packages that use buildRustPackage)

    E.g. you can run this to check if the cargo-auditable package can fetch its deps:
    nix-build -A cargo-auditable.cargoDeps.vendorStaging --check

  4. beeb commented on Feb 26, 2025

    @beeb
    ContributorAuthor

    Thanks for the quick reply. Same error with cargo-auditable and the command you provided.

  5. TomaSajt commented on Feb 26, 2025

    @TomaSajt
    Contributor

    The issue is probably related to how cacert is loaded.
    No idea why this hasn't happen for others.

    The relevant lines of the requests library:

        _preloaded_ssl_context.load_verify_locations(
            extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)
        )

    DEFAULT_CA_BUNDLE_PATH = requests.certs.where()
    requests.certs.where is an alias to certifi.where

    in any case, try running this (inside the repo root):
    nix-shell -p -I nixpkgs=./. 'cacert' 'python3.withPackages (ps: [ps.requests])' --run 'python3 -m requests.certs'

    It should print something similar:

    <frozen runpy>:128: RuntimeWarning: 'requests.certs' found in sys.modules after import of package 'requests', but prior to execution of 'requests.certs'; this may result in unpredictable behaviour
    /nix/store/2vjhfxc2vpval8v76v0hn1d2rpincpgd-nss-cacert-3.108/etc/ssl/certs/ca-bundle.crt
    

    Could you send the output?

    Also, try reading the .crt file, since it looks like there is some issue with the permissions.

  6. beeb commented on Feb 26, 2025

    @beeb
    ContributorAuthor

    Cool, thanks for helping out!

    Here's the command output:

    <frozen runpy>:128: RuntimeWarning: 'requests.certs' found in sys.modules after import of package 'requests', but prior to execution of 'requests.certs'; this may result in unpredictable behaviour
    /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
    

    I can read the file at /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt just fine apparently.
    Permissions: .rwxr-xr-x, owner is root

  7. TomaSajt commented on Feb 26, 2025

    @TomaSajt
    Contributor

    Looks like it's not using the value from the cacert package.

    Here are the relevant lines:

    export NIX_SSL_CERT_FILE="${NIX_SSL_CERT_FILE:-@out@/etc/ssl/certs/ca-bundle.crt}"
    # compatibility
    # - openssl
    export SSL_CERT_FILE=$NIX_SSL_CERT_FILE
    # - Haskell x509-system
    export SYSTEM_CERTIFICATE_PATH=$NIX_SSL_CERT_FILE

    It will set the NIX_SSL_CERT_FILE to the one from cacert, unless you already have set the NIX_SSL_CERT_FILE variable.
    That variable is allowed to be inherited from the user by fetchers, such as fetchCargoVendor.

    Maybe you have the NIX_SSL_CERT_FILE env-var set in your environment.
    Are you perhaps behind a proxy?

  8. beeb commented on Feb 26, 2025

    @beeb
    ContributorAuthor

    Oh you're right, this environment variable is somehow set to that path when I run env! I have no idea where it comes from. Not behind a proxy either.

    Where would I start looking to find what sets it?

  9. beeb commented on Feb 26, 2025

    @beeb
    ContributorAuthor

    I unset the variable and ran the command again, and now I get:

    <frozen runpy>:128: RuntimeWarning: 'requests.certs' found in sys.modules after import of package 'requests', but prior to execution of 'requests.certs'; this may result in unpredictable behaviour
    /nix/store/fq2xj115kp74svil14pisfcsfb34rjxy-nss-cacert-3.108/etc/ssl/certs/ca-bundle.crt
    

    The permissions are .r-xr-xr-x with owner root. Still have the same error while building.

  10. TomaSajt commented on Feb 26, 2025

    @TomaSajt
    Contributor

    Please make the following changes to your nixpkgs repo:

    diff --git a/pkgs/build-support/rust/fetch-cargo-vendor.nix b/pkgs/build-support/rust/fetch-cargo-vendor.nix
    index ce015b099382..f10158d31805 100644
    --- a/pkgs/build-support/rust/fetch-cargo-vendor.nix
    +++ b/pkgs/build-support/rust/fetch-cargo-vendor.nix
    @@ -62,6 +62,7 @@ let
             [
               fetchCargoVendorUtil
               cacert
    +          (python3Packages.python.withPackages (ps: [ ps.requests ]))
             ]
             ++ lib.optionals allowGitDependencies [
               nix-prefetch-git
    @@ -75,6 +76,12 @@ let
               cd "$cargoRoot"
             fi
    
    +        cert=$(python3 -m requests.certs)
    +        echo "The cert is: $cert"
    +        cat "$cert"
    +        echo "The cert is: $cert"
    +        exit 1
    +
             fetch-cargo-vendor-util create-vendor-staging ./Cargo.lock "$out"
    
             runHook postBuild

    and run nix-build -A cargo-auditable.cargoDeps.vendorStaging --check

    The question is: does it successfully do the cat step or does it just fail.

  11. beeb commented on Feb 26, 2025

    @beeb
    ContributorAuthor

    Ok did the change, ran the command, and it fails before the cat:

    checking outputs of '/nix/store/flpq9vcms10p074w7k6zv5fyx1vjjhrv-cargo-auditable-0.6.5-vendor-staging.drv'...
    Running phase: unpackPhase
    unpacking source archive /nix/store/vsss2l1h7sq6ppdvlr7zzp9kxz9nwqcr-source
    source root is source
    Running phase: patchPhase
    Running phase: buildPhase
    Traceback (most recent call last):
      File "<frozen runpy>", line 189, in _run_module_as_main
      File "<frozen runpy>", line 112, in _get_module_details
      File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/__init__.py", line 164, in <module>
        from .api import delete, get, head, options, patch, post, put, request
      File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/api.py", line 11, in <module>
        from . import sessions
      File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/sessions.py", line 15, in <module>
        from .adapters import HTTPAdapter
      File "/nix/store/fryx95sbwrjrbah4a7xg5lqkl3l12dyf-python3-3.12.9-env/lib/python3.12/site-packages/requests/adapters.py", line 81, in <module>
        _preloaded_ssl_context.load_verify_locations(
    PermissionError: [Errno 1] Operation not permitted
    

    The error seems to happen on the line cert=$(python3 -m requests.certs).

  12. TomaSajt commented on Feb 26, 2025

    @TomaSajt
    Contributor

    Let's try this one:

    diff --git a/pkgs/build-support/rust/fetch-cargo-vendor.nix b/pkgs/build-support/rust/fetch-cargo-vendor.nix
    index ce015b099382..f1c692c32612 100644
    --- a/pkgs/build-support/rust/fetch-cargo-vendor.nix
    +++ b/pkgs/build-support/rust/fetch-cargo-vendor.nix
    @@ -62,6 +62,7 @@ let
             [
               fetchCargoVendorUtil
               cacert
    +          (python3Packages.python.withPackages (ps: [ ps.requests ]))
             ]
             ++ lib.optionals allowGitDependencies [
               nix-prefetch-git
    @@ -75,6 +76,13 @@ let
               cd "$cargoRoot"
             fi
    
    +        echo "#1 The cert is: $NIX_SSL_CERT_FILE"
    +        cert=$(python3 -c "from certifi import where; print(where())")
    +        echo "#2 The cert is: $cert"
    +        cat "$cert"
    +        echo "#3 The cert is: $cert"
    +        exit 1
    +
             fetch-cargo-vendor-util create-vendor-staging ./Cargo.lock "$out"
    
             runHook postBuild
  13. beeb commented on Feb 26, 2025

    @beeb
    ContributorAuthor

    Interesting:

    #1 The cert is: /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
    #2 The cert is: /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt
    cat: /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt: Operation not permitted
    

    Although I unset my environment variable just before running the command, it somehow still goes looking for it in the nix profile. It's getting late here but I'll answer tomorrow if you have any other ideas!

  14. TomaSajt commented on Feb 26, 2025

    @TomaSajt
    Contributor

    Hmm, something is re-setting this env-var.
    Next step would be to look at /nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt and check what kind of file it is?
    Is it a plain file?
    Is it a symlink?
    If yes does it just point to /nix/store/...-nss-cacert-3.108/etc/ssl/certs/ca-bundle.crt?

    What might possibly be setting this variable?
    I'll ask others on Matrix.

  15. 10 remaining items

  16. TomaSajt commented on Mar 6, 2025

    @TomaSajt
    Contributor

    Another solution according to the matrix chat is to relax the sandbox. (I don't know how that's done).

  17. wattmto commented on Mar 6, 2025

    @wattmto
    Contributor

    Thanks, sandbox = "relaxed" seems works!

  18. beeb commented on Mar 13, 2025

    @beeb
    ContributorAuthor

    Sandbox relaxed does not seem to help here. I'll try with the re-install but it will take me some time on the very slow intel mac and I don't have a lot of time these days.

  19. n8henrie commented on Mar 19, 2025

    @n8henrie
    Contributor

    Sandbox relaxed works here (for nushell as well as espanso) but will be nice to go back to the full sandbox.

    Recognizing that darwin isn't tier 1, it's still kind of a bummer to break so many builds for sandboxed darwin users -- was this recognized as an issue before merging? I should probably know this, but are hydra darwin builds done with sandbox enabled?

    (I am grateful for the work done and recognize that many folks don't have access to darwin machines for testing.)

  20. TomaSajt commented on Mar 19, 2025

    @TomaSajt
    Contributor

    This mass migration to fetchCargoVendor was something we were pretty much forced into. I myself wasn't expecting the migration to happen so soon. I had tested it in my darwin VM, but I never configured it to have sandboxed builds. Noone else complained, so I thought it was fine.

    Also, this issue is very likely a nix bug. It hasn't been reported yet. If you have a step by step way to reproduce the issue maybe consider opening an nix issue.

    But before that: I wanted to confirm this: does fetchgit also fail for people who have this issue? I would assume yes, but I'd like some confirmation.
    (fetchgit is not fetchFromGitHub) (don't forget that you mustn't use an already cached source)

  21. n8henrie commented on Mar 19, 2025

    @n8henrie
    Contributor

    No worries, I appreciate the explanation and really am grateful for your efforts here. The fact that you went so far as to test in a darwin vm is awesome.

    fetchgit seems fine in the repl at least.

    EDIT: Sorry, I tested in the wrong shell session / machine. fetchgit is not working:

    nix-repl> :b fetchgit { url = "https://github.com/n8henrie/flake-templates"; hash = "sha256-nkwrC+gtQ1AgD0LOmnweBs25aIErWWiv8qckplrofvk=";}
    error: builder for '/nix/store/i80ansib9qpy96ydqvxx1h8vvcmfv4h0-flake-templates.drv' failed with exit code 1;
           last 7 log lines:
           > exporting https://github.com/n8henrie/flake-templates (rev HEAD) into /nix/store/ycbh64cs7finbl4z8ig7wqm1k0iydbrr-flake-templates
           > Initialized empty Git repository in /nix/store/ycbh64cs7finbl4z8ig7wqm1k0iydbrr-flake-templates/.git/
           > fatal: unable to access 'https://github.com/n8henrie/flake-templates/': SSL certificate problem: unable to get local issuer certificate
           > fatal: unable to access 'https://github.com/n8henrie/flake-templates/': SSL certificate problem: unable to get local issuer certificate
           > fatal: unable to access 'https://github.com/n8henrie/flake-templates/': SSL certificate problem: unable to get local issuer certificate
           > fatal: unable to access 'https://github.com/n8henrie/flake-templates/': SSL certificate problem: unable to get local issuer certificate
           > Unable to checkout HEAD from https://github.com/n8henrie/flake-templates.
           For full logs, run 'nix log /nix/store/i80ansib9qpy96ydqvxx1h8vvcmfv4h0-flake-templates.drv'.
    error: build of '/nix/store/i9qaqh66iydxzr0sqqpkz6wvqfs63xdw-flake-templates.drv' failed
    [0 built (4 failed), 0.0 MiB DL]
    
  22. TomaSajt commented on Mar 19, 2025

    @TomaSajt
    Contributor

    Okay, thanks for testing, that is reassurring to hear.
    At least it's consistently broken.

    Also fetchgit is arguably more important to be working properly than a cargo fetcher, so more reason to figure it out.

  23. TomaSajt commented on Mar 19, 2025

    @TomaSajt
    Contributor

    I have opened NixOS/nix#12698

    If you're having this issue, it would be very appreciated if you headed over to the opened issue and provided some details as I myself have not reproduced the problem yet.

  24. beeb commented on Mar 21, 2025

    @beeb
    ContributorAuthor

    Re-installing nix from scratch with the determinate-systems installer helped! I had to manually delete some users and groups before re-installing but managed in the end. I can now build packages even with sandbox enabled. So I'm afraid I can't help to reproduce the issue.

  25. sybereal commented on Apr 25, 2025

    @sybereal
    Contributor

    I experienced what may be the same issue on a Linux host, although the error message is slightly different:

     > Running phase: unpackPhase
     > unpacking source archive /nix/store/bl5h6hy8p6v8m2yqinvnk020r11pnybb-source
     > source root is source
     > Running phase: patchPhase
     > Running phase: updateAutotoolsGnuConfigScriptsPhase
     > Running phase: buildPhase
     > Traceback (most recent call last):
     >   File "/nix/store/20lygcsj1cc7bbqwgnzqwrccsw5azlih-fetch-cargo-vendor-util/bin/fetch-cargo-vendor-util", line 16, in <module>
     >     import requests
     >   File "/nix/store/g9pci3lzsm5mk5xsb02qh5fxq94r1y53-python3-3.12.9-env/lib/python3.12/site-packages/requests/__init__.py", line 164, in <module>
     >     from .api import delete, get, head, options, patch, post, put, request
     >   File "/nix/store/g9pci3lzsm5mk5xsb02qh5fxq94r1y53-python3-3.12.9-env/lib/python3.12/site-packages/requests/api.py", line 11, in <module>
     >     from . import sessions
     >   File "/nix/store/g9pci3lzsm5mk5xsb02qh5fxq94r1y53-python3-3.12.9-env/lib/python3.12/site-packages/requests/sessions.py", line 15, in <module>
     >     from .adapters import HTTPAdapter
     >   File "/nix/store/g9pci3lzsm5mk5xsb02qh5fxq94r1y53-python3-3.12.9-env/lib/python3.12/site-packages/requests/adapters.py", line 81, in <module>
     >     _preloaded_ssl_context.load_verify_locations(
     > FileNotFoundError: [Errno 2] No such file or directory
    

    For me, setting the sandbox to relaxed as suggested by others in this thread resolved the issue.

  26. TomaSajt commented on Apr 25, 2025

    @TomaSajt
    Contributor

    Hmm, interesting...
    @sybereal if it's OK, I would like to learn more about your setup.

    • Which Nix variant are you using?
      • Nix, Determinate Nix, Lix?
    • What is your ssl-cert-path if you run nix config show
      • is it configured explicitly in /etc/nix/nix.conf?
    • Is $NIX_SSL_CERT_FILE set in your normal shell environment
      • If yes, what is it set to?
    • What is the $NIX_SSL_CERT_FILE set in FOD-based fetchers?
      • You can check it by applying this patch to your local checkout of nixpkgs,
        and then running nix-build -A mdbook.cargoDeps.vendorStaging --check
    diff --git a/pkgs/build-support/rust/fetch-cargo-vendor.nix b/pkgs/build-support/rust/fetch-cargo-vendor.nix
    index 5f5a16440778..c35ed125a3ea 100644
    --- a/pkgs/build-support/rust/fetch-cargo-vendor.nix
    +++ b/pkgs/build-support/rust/fetch-cargo-vendor.nix
    @@ -70,6 +70,9 @@ let
               cd "$cargoRoot"
             fi
    
    +        echo "cert file: $NIX_SSL_CERT_FILE"
    +        exit 1
    +
             fetch-cargo-vendor-util create-vendor-staging ./Cargo.lock "$out"
    
             runHook postBuild
  27. sybereal commented on May 10, 2025

    @sybereal
    Contributor

    This occurred on my work laptop, which I don't have access to right now, but it worked without changing the sandbox settings on another machine. The key difference between the two is that the machine that errored is a single-user Nix install in WSL2, from before systemd was available. On the machine that works, it's also WSL2, but a regular multi-user install, since it was configured after systemd support was released.

    On the machine where it works:

    • Which Nix variant are you using? Vanilla Nix, via sh <(curl -L https://nixos.org/nix/install) --daemon
    • What is your ssl-cert-path if you run nix config show? There is no ssl-cert-path, only ssl-cert-file, which is set to /etc/ssl/ca-bundle.pem.
    • Is $NIX_SSL_CERT_FILE set in your normal shell environment? Yes, to /etc/ssl/ca-bundle.pem.
    • What is the $NIX_SSL_CERT_FILE set in FOD-based fetchers? /nix/store/2wmmwdbxp6myhdbrqsan7nbpsfazszvl-nss-cacert-3.108/etc/ssl/certs/ca-bundle.crt

    I will edit this comment once I am on my work machine again and check there.

    Update for the machine where it doesn't work:

    • Which Nix variant are you using? Vanilla Nix in single-user configuration, via sh <(curl -L https://nixos.org/nix/install) --no-daemon
    • What is your ssl-cert-path if you run nix config show? There is no ssl-cert-path, only ssl-cert-file, which is set to /etc/ssl/ca-bundle.pem.
    • Is $NIX_SSL_CERT_FILE set in your normal shell environment? Yes, to /etc/ssl/ca-bundle.pem.
    • What is the $NIX_SSL_CERT_FILE set in FOD-based fetchers? /etc/ssl/ca-bundle.pem
  28. sybereal commented on May 13, 2025

    @sybereal
    Contributor

    @TomaSajt Updated my previous comment with new information.

  29. TomaSajt commented on May 13, 2025

    @TomaSajt
    Contributor

    Thank you, now I see why it's not working for your second machine: the build environment inherits env vars from the daemon if possible (its unset by default), but in single user mode it inherits from the user running the command...

    We'll merge one of the half-fix PRs soon, so it should work afterwards, but we will try to figure out a more permanent solution with cooperation with people on the nix development side.

  30. added
    2.status: stale
    on Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug2.status: stale6.topic: darwin

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions