Merge pull request #178964 from linsui/cargo

fetch-cargo-tarball: allow use index mirror
This commit is contained in:
Benjamin Hipple 2022-09-17 12:04:27 -04:00 committed by GitHub
commit 1066f0ef92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 7 deletions

View file

@ -52,8 +52,9 @@
, buildAndTestSubdir ? null
, ... } @ args:
assert cargoVendorDir == null && cargoLock == null -> !(args ? cargoSha256) && !(args ? cargoHash)
-> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set";
assert cargoVendorDir == null && cargoLock == null
-> !(args ? cargoSha256 && args.cargoSha256 != null) && !(args ? cargoHash && args.cargoHash != null)
-> throw "cargoSha256, cargoHash, cargoVendorDir, or cargoLock must be set";
assert buildType == "release" || buildType == "debug";
let

View file

@ -13,7 +13,9 @@ def quote(s: str) -> str:
def main() -> None:
data = toml.load(sys.stdin)
assert list(data.keys()) == ["source"]
# There is no dependency to vendor in this project.
if not list(data.keys()) == ["source"]:
return
# this value is non deterministic
data["source"]["vendored-sources"]["directory"] = "@vendor@"

View file

@ -58,10 +58,21 @@ in stdenv.mkDerivation ({
export CARGO_HOME=$(mktemp -d cargo-home.XXX)
CARGO_CONFIG=$(mktemp cargo-config.XXXX)
if [[ -n "$NIX_CRATES_INDEX" ]]; then
cat >$CARGO_HOME/config.toml <<EOF
[source.crates-io]
replace-with = 'mirror'
[source.mirror]
registry = "$NIX_CRATES_INDEX"
EOF
fi
${cargoUpdateHook}
cargo vendor $name | cargo-vendor-normalise > $CARGO_CONFIG
cargo vendor $name --respect-source-config | cargo-vendor-normalise > $CARGO_CONFIG
# Create an empty vendor directory when there is no dependency to vendor
mkdir -p $name
# Add the Cargo.lock to allow hash invalidation
cp Cargo.lock.orig $name/Cargo.lock
@ -81,7 +92,7 @@ in stdenv.mkDerivation ({
inherit (hash_) outputHashAlgo outputHash;
impureEnvVars = lib.fetchers.proxyImpureEnvVars;
impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ "NIX_CRATES_INDEX" ];
} // (builtins.removeAttrs args [
"name" "sha256" "cargoUpdateHook" "nativeBuildInputs"
]))

View file

@ -11,8 +11,7 @@ rustPlatform.buildRustPackage rec {
sha256 = "sha256-NzFKNCCPWBj/fhaEJF34nyeyvLMeQwIcQgTlYc6mgYo=";
};
# There is no dependency to vendor in this project.
cargoLock.lockFile = ./Cargo.lock;
cargoHash = "sha256-Dc+SuLwbLFcNSr9RiNSc7dgisBOvOUEIDR8dFAkC/O0=";
meta = with lib; {
description = "ELF visualizer, generates HTML files from ELF binaries.";