fetch-cargo-tarball: allow use index mirror

This commit is contained in:
linsui 2022-06-26 13:05:18 +08:00
parent 8508d5decf
commit 656e3022f4

View file

@ -58,9 +58,18 @@ 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
# Add the Cargo.lock to allow hash invalidation
cp Cargo.lock.orig $name/Cargo.lock
@ -81,7 +90,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"
]))