nix: backport importCargoLock static.crates.io fix#441
Merged
Conversation
|
Code coverage summary for 2a5379e: ✅ Region coverage 68% passes |
1ffef64 to
0e9f8a4
Compare
0e9f8a4 to
0479676
Compare
crates.io now rejects requests with curl/* User-Agent, returning HTTP 403 on `https://crates.io/api/v1/crates/<name>/<ver>/download`. nixpkgs `fetchurl` calls curl with its default UA, so `rustPlatform.buildRustPackage` with `cargoLock.lockFile` (which routes through `importCargoLock` and fetches each crate tarball via `fetchurl`) fails on the first uncached crate, e.g.: trying https://crates.io/api/v1/crates/autocfg/1.5.1/download curl: (22) The requested URL returned error: 403 Reproduced UA blocklist: curl/8.5.0 -> 403 empty UA -> 302 cargo (...) -> 200 static.crates.io/* -> 200 (no UA gate) Override `pkgs.makeRustPlatform` (not `pkgs.rustPlatform.importCargoLock`): nixpkgs' `pkgs/development/compilers/rust/make-rust-platform.nix` constructs a fresh `importCargoLock` via `buildPackages.callPackage` against a hardcoded path to `pkgs/build-support/rust/import-cargo-lock.nix`, so overriding the top-level `rustPlatform.importCargoLock` is ignored by every call site that goes through `makeRustPlatform`. Both `nix/modules/native.nix` and `nix/modules/cross.nix` build their `rustPlatform` via `(pkgsCross.)makeRustPlatform { cargo = ...; rustc = ...; }`, so a top-level override silently misses macOS, Linux musl, and every cross target. Intercept `makeRustPlatform` instead and re-inject the patched `importCargoLock` via `overrideScope` on the returned scope so that `buildRustPackage` (resolved through `callPackage` against the scope's `self`) picks it up. The patched `import-cargo-lock.nix` is materialised at evaluation time via `builtins.toFile`/`builtins.readFile`/`builtins.replaceStrings` rather than `runCommand`. `runCommand` adds a build-time dependency on `/bin/sh` which fails on macOS sandbox builds with "requested impure path '/bin/sh', but it was not in allowed-impure-host-deps". `builtins.toFile` produces a store path purely at eval time with no derivation to build, sidestepping the sandbox check entirely. The one-line URL change inside `import-cargo-lock.nix` mirrors NixOS/nixpkgs#524985 byte-for-byte. Verified across all four flake systems by inspecting the rendered `cargo-vendor-dir.drv` graph - every crate tarball URL resolves to `https://static.crates.io/crates/<name>/<ver>/download`: - x86_64-darwin (native + Darwin-to-Darwin cross) - aarch64-darwin (native + cross to x86_64-darwin) - x86_64-linux (native + gnu/musl cross) - aarch64-linux (native + gnu/musl cross) Upstream references: - rust-lang/crates.io#13482: original ticket (closed). Initially flagged python-requests/2.32.5+ UA; crates.io has since extended the blocklist to include curl/*. - NixOS/nixpkgs#512735 (merged 2026-04-26): sets `nixpkgs-fetchCargoVendor/2 (...)` UA and switches to `static.crates.io`. Only patches `fetchCargoVendor`. - NixOS/nixpkgs#524979 (closed 2026-05-27): tracking issue for the same 403 hitting `importCargoLock` (the path lightway uses). - NixOS/nixpkgs#524985 (merged 2026-05-27 to master): fix for `importCargoLock` - switches crate downloads to `https://static.crates.io/crates/<name>/<ver>/download`, which has no UA gate. As of this commit the fix is on master only; `nixpkgs-unstable` (the channel this flake tracks at f9d8b65, 2026-05-25) does not yet contain it. Drop this overlay once `flake.lock` is bumped to a `nixpkgs-unstable` revision that includes NixOS/nixpkgs#524985.
0479676 to
af86d1c
Compare
xv-thomas-leong
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
crates.io now rejects requests with curl/* User-Agent, returning HTTP 403 on
[https://crates.io/api/v1/crates/<name>/<ver>/download].nixpkgs
fetchurlcalls curl with its default UA, sorustPlatform.buildRustPackagewithcargoLock.lockFile(which routes throughimportCargoLockand fetches each crate tarball viafetchurl) fails on the first uncached crate, e.g.:Override
rustPlatform.importCargoLockwith a copy of the upstream file patched to use https://static.crates.io/crates instead of the API host.This mirrors NixOS/nixpkgs#524985.
Upstream references:
nixpkgs-fetchCargoVendor/2 (...)UA and switches tostatic.crates.io. Only patchesfetchCargoVendor.rustPlatform.importCargoLockerrors out with HTTP 403 error NixOS/nixpkgs#524979 (closed 2026-05-27): tracking issue for the same 403 hittingimportCargoLock(the path lightway uses).importCargoLock- switches crate downloads to[https://static.crates.io/crates/<name>/<ver>/download](), which has no UA gate. As of this commit the fix is on master only;nixpkgs-unstable(the channel this flake tracks at f9d8b65, 2026-05-25) does not yet contain it.Drop this overlay once
flake.lockis bumped to anixpkgs-unstablerevision that includes NixOS/nixpkgs#524985.Motivation and Context
nix builds are failing in PRs
How Has This Been Tested?
nix builds are passing with this overlay
Types of changes
Checklist:
main