Repository navigation
rustPlatform.fetchCargoVendor: set a custom User-Agent - #512735
Conversation
|
This is a mass rebuild but right now I can't build any rust package, so not sure whether this should still go through staging. Maybe this is also targeted by geo IP and other people aren't getting 403? |
|
Can confirm this is an issue for me too (thank you so much for submitting this PR, I just spent a while desperately trying to figure out what's going on lol) For some reason it doesn't block all requests, maybe it's still being rolled out or something somewhere is doing caching? Oh just so people can find here when searching for the error message: |
|
I also experienced this today. Changing the user-agent fixed the issue for me. While testing, I added the The https://crates.io/data-access#api page states:
Setting the user-agent would conform to 2., which sounds like the correct solution. It seems 1. is not actually enforced while downloading crates or the existing retry logic handles rate limits. |
|
Why would this create a mass rebuild? These are all FODs? |
|
@NickCao The tarball downloads themselves are FOD-cached, but runCommand "${name}-vendor" {
inherit vendorStaging;
nativeBuildInputs = [ fetchCargoVendorUtil cargo replaceWorkspaceValues ];
} ''
fetch-cargo-vendor-util create-vendor "$vendorStaging" "$out"
''That |
That's unfortunate, I hope crates.io can grant us an exception for now. |
|
The staging part is a FOD, but there is a non-staging part, which is not a FOD. (e.g. separating files or ditching the non-staging part completely and moving it into the setup hook) |
|
For now we can copy the Python file, fix the user agent in only one of them, and use that one in the FOD. That should avoid rebuilds and can be cleaned up on |
| ) | ||
| session = requests.Session() | ||
| # crates.io blocks the default python-requests/<version> User-Agent | ||
| session.headers["User-Agent"] = "nixpkgs fetchCargoVendor (https://github.com/NixOS/nixpkgs)" |
There was a problem hiding this comment.
Nixpkgs issues can easily go unnoticed if they don't ping anyone. I'm wondering if we should include a suggestion to ping here or perhaps an email address (Nixpkgs core would be fine for this although it would likely be pure indirection since I expect we'd just end up opening an issue ourselves).
There was a problem hiding this comment.
Also I think it would be a good idea to include some kind of version information here. That could be a manual integer specific to fetchCargoVendor for now as including the Nixpkgs version info would require the split Toma mentioned (so that release manager tasks don't go to staging).
|
From the upstream issue:
Since it sounds like the rate limit isn't an immediate problem for us, I suggest we do the file-copying hack now on unstable and 25.11 to get a UA set so the crates.io admins can reinstate the block, and if it would be feasible when cleaning up on ( |
|
@emilazy Will push in a bit, thanks for the suggestions 🙏 |
ff2edda to
5a4b429
Compare
| @@ -0,0 +1,416 @@ | |||
| import functools | |||
There was a problem hiding this comment.
diff pkgs/build-support/rust/fetch-cargo-vendor-util.py pkgs/build-support/rust/fetch-cargo-vendor-util-v2.py
42a43
> session.headers["User-Agent"] = "nixpkgs fetchCargoVendor/2 (https://github.com/NixOS/nixpkgs)"
71c72,74
< return f"https://crates.io/api/v1/crates/{pkg["name"]}/{pkg["version"]}/download"
---
> # Use static.crates.io (CDN) instead of crates.io/api to avoid the 1 req/sec
> # rate limit on the API servers.
> return f"https://static.crates.io/crates/{pkg["name"]}/{pkg["version"]}/download"
There was a problem hiding this comment.
I think we shouldn’t hardcode this:
for completeness, the technically correct path for downloading crates is: load https://index.crates.io/config.json, look at the
dlkey in the JSON file, build the download URL via{dl}/{name}/{version}/download.
Let’s perhaps stick to the minimal change for now to reduce risk on unstable and 25.11 and unblock crates.io amins ASAP, and follow up with further improvements on staging? (Also, please split the copy into a separate commit to the other changes so that the diff is readable directly.)
There was a problem hiding this comment.
My thinking was that the current approach is already wrong and it already hardcodes an URL, so we might as well hardcode the URL that doesn't have rate limiting.
There was a problem hiding this comment.
I separated the changes into separate commits as requested.
| status_forcelist=[500, 502, 503, 504] | ||
| ) | ||
| session = requests.Session() | ||
| session.headers["User-Agent"] = "nixpkgs fetchCargoVendor/2 (https://github.com/NixOS/nixpkgs)" |
There was a problem hiding this comment.
Maybe we can create an issue on nixpkgs for reports and just link to it here? WDYT @emilazy?
There was a problem hiding this comment.
We also don't want to make the UA a giant string, so maybe just an email might be the way to go?
There was a problem hiding this comment.
The UA is technically valid but parses oddly against RFC 9110 section 10.1.5.
The current format is parsed as two separate products: nixpkgs with no version, and fetchCargoVendor/2, rather than one. Replacing the space with a dash would combine them into a single product token, something like this: nixpkgs-fetchCargoVendor/2 (...).
We should revisit this when we do the cleanup on staging with proper separation between the FOD stage and the input-addressed stage.
This is just a suggestion though, and not meant to block if this needs to land fast (since rust builds are currently broken).
There was a problem hiding this comment.
Updated with your suggestion.
There was a problem hiding this comment.
Replacing the repository URL with an issue URL for reports that the relevant parties can subscribe to and reporters can link their new issues in seems like a good idea to me.
|
Feel free to push directly to this branch to fix any remaining issues (I may be offline for the next hours). |
The crates.io API server's 1 req/sec rate limit currently surfaces as intermittent HTTP 403 errors when vendoring lockfiles. Switch to the CDN endpoint as recommended by upstream (rust-lang/crates.io#13482), mirroring the fix already applied to fetchCargoVendor in NixOS#512735. fetchurl is content-addressed by sha256, so the URL change does not affect any downstream store paths. Fixes NixOS#524979
Fixed #514 FYI: NixOS/nixpkgs#512735 Track a stable channel rather than an unstable one: fewer "HEAD is broken" regressions. 25.11 has the fetchCargoVendor User-Agent fix (needed so crates.io doesn't 403 libtokenizers' crate downloads) --------- Signed-off-by: ChengHao Yang <[email protected]>
- Bump nixpkgs (2026-04-14 → 2026-05-23) for the fetchCargoVendor User-Agent fix (NixOS/nixpkgs#512735) so kanidm-cli and other Cargo builds stop hitting crates.io 403s. - Bump home-manager (2026-03-20 → 2026-05-30) past the neovim `extraConfig` null-list regression that was failing admin/developer per-user closure builds. - Pin Kanidm 1.9 → 1.10.1 (1.9 EOL 2026-05-31): flake.nix overlay, nix/kanidm-cli.nix (version + hashes), docker-compose image tag, CLAUDE.md key conventions. - Switch kanidm-unixd `home_attr` from `spn` to `name` and align `lib.buildUserEnv` so `/home/testuser` is the on-disk path. Keeps `@` out of paths where Nextcloud Desktop and similar clients fail; SPN login still works via `home_alias = spn`. - Wire `hearth-office-oxt` into the home-manager LibreOffice module when `enableExtensions` is true, and pass `libreofficeExtensions = true` in `dev/fleet-vm.nix` so the Rust UNO bundle ships with the dev VM closure. - Add sqlx PgPool keepalive (`test_before_acquire`, `idle_timeout`, `max_lifetime`) on both hearth-api and hearth-build-worker — the worker was silently losing its DB connection on idle and stalling the job queue. - Pre-fetch Stalwart's `webadmin.zip` in `just setup`, bind-mount it into the container, and point `[webadmin] resource` at the local file. The container's GitHub download silently fails. - Qualify all attic CLI calls with the `dev:` server prefix so pushes don't leak to a developer's personal default-server. - Pin pnpm's `verifyDepsBeforeRun: false` in pnpm-workspace.yaml so `pnpm build` under `nix develop -c` doesn't abort on a missing TTY. - Add `renovate.json` configuring weekly dependency-update PRs across nix flake inputs, Cargo, pnpm, Helm, and docker-compose tags. - Document the recurring follow-ups and recent fixes in a new Operational Backlog section of ROADMAP.md.
…s.io 403s python-requests UA) (#461) The "Build sancta-claw" CI job has failed on every push since the agent-browser-cli 0.14.0 vendor FOD fell out of the binary cache: crates.io returns HTTP 403 to rustPlatform.fetchCargoVendor because its Python `requests`-based fetcher sends a `python-requests/*` User-Agent, which crates.io's crawler policy now blocks (rust-lang/crates.io#13482). Switch the single agent-browser-cli buildRustPackage call from cargoHash to cargoLock (importCargoLock), which fetches each crate via Nix's libcurl fetchurl — not blocked by crates.io. The CLI lockfile (cli/Cargo.lock, v4) has only crates.io-registry deps and zero git sources, so no cargoLock.outputHashes are needed and there is one fewer hash to maintain than cargoHash. Upstream fix is NixOS/nixpkgs#512735 (set a descriptive User-Agent), backported to release-25.11 on 2026-04-26 but not yet in this flake's nixpkgs pin (2026-03-18); revert to cargoHash once the pin carries it. Verified locally on aarch64-darwin: sancta-claw evaluates to a valid drvPath, and the importCargoLock vendor dir builds end-to-end (all 43 crates fetched via libcurl, zero 403). The x86_64-linux compile/link is exercised by the previously-failing "Build sancta-claw" CI job. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…g fetch crates.io now rejects python-requests' default User-Agent with HTTP 403, breaking every fetchCargoVendor fixed-output fetch at this pin. Functionally this is the upstream fix (8209ba2, NixOS#512735) adapted to the pre-v2-split script at this rev, with one refinement: the UA-fixed util is used ONLY by the fixed-output vendorStaging derivation (the only step that talks to the network). Because fixed-output derivations are absorbed by hashDerivationModulo, no input-addressed derivation changes: every package keeps its exact store path, cache.nixos.org substitution is unaffected, and existing cargoHash values remain valid. The naive whole-script patch would have cascaded through the input-addressed *-vendor step into python3Packages.cryptography and from there into Qt rebuilds. Applied on top of e9f00bd (the rev logos-co pins via logos-nix) so the package set is byte-identical. Context: logos-co/logos-module-builder#159 Co-Authored-By: Claude Fable 5 <[email protected]>
No Nix build of this module has ever got past vendoring. Every leg of
every run, on every platform, dies on its first crate:
Failed to fetch file from
https://crates.io/api/v1/crates/adler2/2.0.1/download. Status code: 403
darwin-arm64 fails the same way, so this is not something the Linux port
introduced -- it is what blocks today's macOS releases too, and it is the
only thing between PR #6 and six green legs.
crates.io answers 403 to the User-Agent nixpkgs' cargo vendor fetcher
sends. The fetcher sets none, so requests sends `python-requests/*`;
measured against the failing URL, that is a 403, `curl/*` is a 403, and a
descriptive one is a 200. Upstream fixed it in NixOS/nixpkgs#512735
(2026-04-26) and later moved the download off the API endpoint entirely.
The nixpkgs this flake follows through logos-module-builder is e9f00bd8
(2025-09), which predates both, and repinning it is not available: it is
this module's whole Qt/C++ toolchain.
So the fix is local. fetch-cargo-vendor.nix is re-expressed in the flake,
its two helper scripts rebuilt from the pinned tree with `readFile`, and
three substitutions applied to the fetching one.
The third is the one that actually resolves it: fetch tarballs from
`https://static.crates.io/crates/<name>/<name>-<version>.crate` instead
of `https://crates.io/api/v1/crates/<name>/<version>/download`. That is
the CDN cargo itself downloads from -- the registry's `dl` key -- and
where upstream moved after #512735. It applies neither the User-Agent
policy that produces the 403 nor the per-IP rate limit that produces the
429 six concurrent legs would hit next; measured, it returns 200 for
every user-agent tried, `python-requests/2.32.3` and `curl/*` included,
on the exact URLs that 403.
The other two are belt. A descriptive User-Agent, so the request is not
one crates.io has a policy against wherever it lands. And 429 added to
the urllib3 `Retry` upstream already mounts but scopes to 5xx only -- so
the one status that means "back off and come back" becomes the one it
retries -- with jitter so parallel legs do not retry in lockstep,
`respect_retry_after_header` pinned so a `Retry-After` beats our own
curve, and a bound of 12 attempts / 60s so a genuinely down registry
fails in minutes rather than riding a 90-minute timeout. 403 is
deliberately not retried: that is a policy answer, and retrying it would
only reach the same error slower. Retry alone was measured insufficient
in the sibling swap module -- legs rode the full budget and still came
out with `RetryError: ... too many 429 error responses` -- which is why
the CDN switch is the fix and this is only the belt.
Scoping matters as much as the substitutions. This patches a private
copy via `replaceStrings`, not the shared `fetch-cargo-vendor-util` via
`applyPatches`. Patching the real one moves the `outPath` of every Rust
package in nixpkgs -- `qt6.qtdeclarative`,
`python3Packages.cryptography` and `cargo-auditable` all shift -- which
would cost this build its binary-cache hits on exactly the cold CI
runners it is meant to help, and could mean hours of Qt rebuilds. The
scoped form leaves all three at their stock paths and moves nothing but
lez-faucet-ffi; nixpkgs' own `rustPlatform` is untouched. The scripts are
re-expressed rather than generated with `toFile` because a generated file
embeds `${nixpkgs}` store paths as text, and registering those as
references makes evaluation die with `path '...-source' is not valid` on
CI's Determinate Nix while evaluating clean on stock Nix.
The substitutions are asserted, so a nixpkgs bump that reshapes the
fetcher fails evaluation loudly with the string it could not find,
instead of silently reverting to a 403. All of it deletes once
logos-module-builder's nixpkgs carries the upstream fix
(logos-co/logos-module-builder#173) -- but nothing here waits on that.
cargoHash is unchanged, and now proven rather than asserted. It becomes
`cargoDeps.hash` so vendoring goes through the patched fetcher, but it
covers only the fixed-output vendor-staging tree -- checksum-verified
crate tarballs, git checkouts and Cargo.lock -- so it tracks the
lockfile, not the nixpkgs building it or the host serving the bytes. The
script checksums every tarball against Cargo.lock, so a changed download
host cannot quietly vendor something else; it would fail loudly.
Verified on an aarch64 macOS host:
- `lez-faucet-ffi-0.2.0-vendor-staging` builds cold and lands on the
committed sha256-bynsEIeov27VyVr8NdHVcpPwEQr8Kbmd93o+B61XWEM= -- a
real download of the full crate set through static.crates.io, matching
a hash measured against the API endpoint. Same bytes, different host.
- `nix build .#packages.aarch64-darwin.lez-faucet-ffi` succeeds, the
first time any Nix build of this module has. 9.3M dylib, install name
`@rpath/liblez_faucet_ffi.dylib`, exporting exactly the ten locked ABI
entry points and the header beside it.
- `nix eval .#packages.<sys>.lgx-portable.drvPath` instantiates the full
derivation graph for aarch64-darwin, x86_64-linux and aarch64-linux,
forcing every input including the vendor FOD.
- qt6.qtdeclarative, python3Packages.cryptography and cargo-auditable
evaluate to their stock outPaths, confirming the scoping.
Co-Authored-By: Claude <[email protected]>
No Nix build of this module has ever got past vendoring. Every leg of
every run, on every platform, dies on its first crate:
Failed to fetch file from
https://crates.io/api/v1/crates/adler2/2.0.1/download. Status code: 403
darwin-arm64 fails the same way, so this is not something the Linux port
introduced -- it is what blocks today's macOS releases too, and it is the
only thing between PR #6 and six green legs.
crates.io answers 403 to the User-Agent nixpkgs' cargo vendor fetcher
sends. The fetcher sets none, so requests sends `python-requests/*`;
measured against the failing URL, that is a 403, `curl/*` is a 403, and a
descriptive one is a 200. Upstream fixed it in NixOS/nixpkgs#512735
(2026-04-26) and later moved the download off the API endpoint entirely.
The nixpkgs this flake follows through logos-module-builder is e9f00bd8
(2025-09), which predates both, and repinning it is not available: it is
this module's whole Qt/C++ toolchain.
So the fix is local. fetch-cargo-vendor.nix is re-expressed in the flake,
its two helper scripts rebuilt from the pinned tree with `readFile`, and
three substitutions applied to the fetching one.
The third is the one that actually resolves it: fetch tarballs from
`https://static.crates.io/crates/<name>/<name>-<version>.crate` instead
of `https://crates.io/api/v1/crates/<name>/<version>/download`. That is
the CDN cargo itself downloads from -- the registry's `dl` key -- and
where upstream moved after #512735. It applies neither the User-Agent
policy that produces the 403 nor the per-IP rate limit that produces the
429 six concurrent legs would hit next; measured, it returns 200 for
every user-agent tried, `python-requests/2.32.3` and `curl/*` included,
on the exact URLs that 403.
The other two are belt. A descriptive User-Agent, so the request is not
one crates.io has a policy against wherever it lands. And 429 added to
the urllib3 `Retry` upstream already mounts but scopes to 5xx only -- so
the one status that means "back off and come back" becomes the one it
retries -- with jitter so parallel legs do not retry in lockstep,
`respect_retry_after_header` pinned so a `Retry-After` beats our own
curve, and a bound of 12 attempts / 60s so a genuinely down registry
fails in minutes rather than riding a 90-minute timeout. 403 is
deliberately not retried: that is a policy answer, and retrying it would
only reach the same error slower. Retry alone was measured insufficient
in the sibling swap module -- legs rode the full budget and still came
out with `RetryError: ... too many 429 error responses` -- which is why
the CDN switch is the fix and this is only the belt.
Scoping matters as much as the substitutions. This patches a private
copy via `replaceStrings`, not the shared `fetch-cargo-vendor-util` via
`applyPatches`. Patching the real one moves the `outPath` of every Rust
package in nixpkgs -- `qt6.qtdeclarative`,
`python3Packages.cryptography` and `cargo-auditable` all shift -- which
would cost this build its binary-cache hits on exactly the cold CI
runners it is meant to help, and could mean hours of Qt rebuilds. The
scoped form leaves all three at their stock paths and moves nothing but
lez-faucet-ffi; nixpkgs' own `rustPlatform` is untouched. The scripts are
re-expressed rather than generated with `toFile` because a generated file
embeds `${nixpkgs}` store paths as text, and registering those as
references makes evaluation die with `path '...-source' is not valid` on
CI's Determinate Nix while evaluating clean on stock Nix.
The substitutions are asserted, so a nixpkgs bump that reshapes the
fetcher fails evaluation loudly with the string it could not find,
instead of silently reverting to a 403. All of it deletes once
logos-module-builder's nixpkgs carries the upstream fix
(logos-co/logos-module-builder#173) -- but nothing here waits on that.
cargoHash is unchanged, and now proven rather than asserted. It becomes
`cargoDeps.hash` so vendoring goes through the patched fetcher, but it
covers only the fixed-output vendor-staging tree -- checksum-verified
crate tarballs, git checkouts and Cargo.lock -- so it tracks the
lockfile, not the nixpkgs building it or the host serving the bytes. The
script checksums every tarball against Cargo.lock, so a changed download
host cannot quietly vendor something else; it would fail loudly.
Verified on an aarch64 macOS host:
- `lez-faucet-ffi-0.2.0-vendor-staging` builds cold and lands on the
committed sha256-bynsEIeov27VyVr8NdHVcpPwEQr8Kbmd93o+B61XWEM= -- a
real download of the full crate set through static.crates.io, matching
a hash measured against the API endpoint. Same bytes, different host.
- `nix build .#packages.aarch64-darwin.lez-faucet-ffi` succeeds, the
first time any Nix build of this module has. 9.3M dylib, install name
`@rpath/liblez_faucet_ffi.dylib`, exporting exactly the ten locked ABI
entry points and the header beside it.
- `nix eval .#packages.<sys>.lgx-portable.drvPath` instantiates the full
derivation graph for aarch64-darwin, x86_64-linux and aarch64-linux,
forcing every input including the vendor FOD.
- qt6.qtdeclarative, python3Packages.cryptography and cargo-auditable
evaluate to their stock outPaths, confirming the scoping.
Co-Authored-By: Claude <[email protected]>
The rust example used a fairly old catalog page, on which the nixpkgs rust builder doesnt provide a user-agent for cargo.io, which causes strict rate limiting, leading to 403 errors in CI. Bumping the env and the associated nixpkgs should avoid this going forward. See Also: NixOS/nixpkgs#512735
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
The crates.io API server's 1 req/sec rate limit currently surfaces as intermittent HTTP 403 errors when vendoring lockfiles. Switch to the CDN endpoint as recommended by upstream (rust-lang/crates.io#13482), mirroring the fix already applied to fetchCargoVendor in NixOS#512735. fetchurl is content-addressed by sha256, so the URL change does not affect any downstream store paths. Fixes NixOS#524979 # Conflicts: # pkgs/build-support/rust/import-cargo-lock.nix
…t bump) crates.io returns 403 to python-requests' default User-Agent. The pinned nixpkgs (e9f00bd8) predates NixOS/nixpkgs#512735, so its fetch-cargo-vendor-util.py sets none and every *-vendor-staging FOD fails (logos-co/logos-module-builder#159). Add an overlay that wraps makeRustPlatform and, inside the scope, re-points fetchCargoVendor's vendor-staging FOD at a copy of the pin's helper with the two network-facing hunks of #512735 applied (User-Agent header, static.crates.io download URL). Only the FOD changes; consumer cargoHash values and every downstream outPath are unchanged. The overlay is the identity on a pin that already sends a User-Agent and fails evaluation if the helper drifted in any other way. Applied to the native package sets (forAllSystems, forAllTargets, legacyPackages) and exported as lib.overlays.fetchCargoVendorUserAgent. Not applied to the Windows set: nixpkgs-windows (b5aa0fbd) already contains the upstream fix. The nixpkgs pin and Qt are untouched; the Qt bump stays in #5. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01P5ByEqD8ff6pK1fJwL4EFV
crates.io started 403ing the python-requests default User-Agent, which is what the old fetch-cargo-vendor-util sent, so buildRustPackage could not vendor anything not already in the store. Fixed upstream in NixOS/nixpkgs#512735: the fetcher now sends an identifying UA and pulls from static.crates.io. Our lock predated it. Carries duckdb 1.4.4 -> 1.5.5 (fts hash already pinned) and a newer clippy, whose question_mark lint flags the operator chain in parse_file_size_filter; rewritten as a table so >= still wins over >.
…ing paths crates.io started 403'ing python-requests' default UA and rate-limiting its API endpoint (NixOS/nixpkgs#512735), breaking fetchCargoVendor, importCargoLock, and fetchCrate alike. Redirects each to static.crates.io / swaps in the fixed util script, scoped to cargo-pgrx's rustPlatform construction. Verified against Raminder's pg_graphql 1.6.2 bump (rs/bump-pg-graphql): builds clean end-to-end with these fixes applied. Co-Authored-By: Claude Sonnet 5 <[email protected]>
* fix(cargo-pgrx): work around crates.io UA blocklist across all vendoring paths crates.io started 403'ing python-requests' default UA and rate-limiting its API endpoint (NixOS/nixpkgs#512735), breaking fetchCargoVendor, importCargoLock, and fetchCrate alike. Redirects each to static.crates.io / swaps in the fixed util script, scoped to cargo-pgrx's rustPlatform construction. Verified against Raminder's pg_graphql 1.6.2 bump (rs/bump-pg-graphql): builds clean end-to-end with these fixes applied. Co-Authored-By: Claude Sonnet 5 <[email protected]> * chore(cargo-pgrx): rename fix-fetch-cargo.nix to fix-cargo.nix It fixes fetchCrate too, not just cargo vendoring. Co-Authored-By: Claude Sonnet 5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5 <[email protected]>
Rust package builds using
fetchCargoVendorhave started failing intermittently with HTTP 403 responses when downloading crate tarballs fromhttps://crates.io/api/v1/crates/<name>/<version>/download. The failures are not caused by any recent change in nixpkgs, they're triggered server-side by crates.io, which has begun blocklisting specificpython-requests/<version>User-Agent strings. Testing directly against crates.io confirms this:python-requests/2.32.5andpython-requests/2.33.1both return 403, while older versions, empty UAs, and any custom string return 302 as expected.fetch-cargo-vendor-util.pybuilds itsrequests.Sessionwithout overriding the default User-Agent, so every tarball request goes out aspython-requests/<version>and gets rejected. This also lines up with crates.io's long-standing published policy asking clients to identify themselves with a contact URL (https://crates.io/data-access), which the default UA doesn't satisfy.The fix is a one-line change in
create_http_session()to set User-Agent:nixpkgs fetchCargoVendor/2 (https://github.com/NixOS/nixpkgs)on the session. This identifies the client per crates.io's guidance and sidesteps the version-pattern blocklist. The PR also switches the download URL tohttps://static.crates.io/crates/<name>/<version>/downloadto bypass the 1 req/s rate limit on the API servers, as recommended by the crates.io maintainer in rust-lang/crates.io#13482.Landing this naively would change
fetch-cargo-vendor-util.py, which is an input to both the FODvendorStagingstage (where HTTP downloads happen and the UA matters) and the input-addressed-vendorrunCommandstage (where it doesn't). Even thoughvendorStagingis an FOD and its output path is stable, touching the util referenced by the-vendorstage rewrites every downstreambuildRustPackagederivation in the tree, a mass rebuild that has to go throughstaging. To avoid that,fetch-cargo-vendor-util.pyis left untouched and the fix is applied in a parallel copyfetch-cargo-vendor-util-v2.pythat's wired only into the FOD. Since the FOD output is content-addressed by declared hash, the rest of the world sees no change. The duplication is deliberate and temporary, it can be collapsed back into a single file on the nextstagingcycle.Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.