rust: store the cargo-vendor config

cargo-vendor generates almost the right cargo config. Store it with the
vendored files and patch it on use.

This allows to re-use the generated config when using git dependencies.
This commit is contained in:
zimbatm 2017-10-23 16:13:08 +00:00 committed by Robin Gloster
parent c5456dbfec
commit 0af2c5891b
4 changed files with 20 additions and 20 deletions

View File

@ -2,11 +2,11 @@
let let
inherit (stdenv) system; inherit (stdenv) system;
version = "0.1.12"; version = "0.1.13";
hashes = { hashes = {
x86_64-linux = "1hxlavcxy374yypfamlkygjg662lhll8j434qcvdawkvlidg5ii5"; x86_64-linux = "1znv8hm4z4bfb6kncf95jv6h20qkmz3yhhr8f4vz2wamynklm9pr";
x86_64-darwin = "1jkvhh710gwjnnjx59kaplx2ncfvkx9agfa76rr94sbjqq4igddm"; x86_64-darwin = "0hcib4yli216qknjv7r2w8afakhl9yj19yyppp12c1p4pxhr1qr6";
}; };
hash = hashes. ${system} or badSystem; hash = hashes. ${system} or badSystem;

View File

@ -43,21 +43,15 @@ in stdenv.mkDerivation (args // {
postUnpack = '' postUnpack = ''
eval "$cargoDepsHook" eval "$cargoDepsHook"
unpackFile "$cargoDeps" if [[ ! -f $cargoDeps/.config ]]; then
cargoDepsCopy=$(stripHash $(basename $cargoDeps)) echo "ERROR: file not found: $cargoDeps/.config"
chmod -R +w "$cargoDepsCopy" echo "try updating the cargoSha256"
exit 1
fi
mkdir .cargo mkdir -p .cargo
cat >.cargo/config <<-EOF # inherit cargo config from the deps, rewrite the target directory
[source.crates-io] cat $cargoDeps/.config | sed "s|REPLACEME|$cargoDeps|g" > .cargo/config
registry = 'https://github.com/rust-lang/crates.io-index'
replace-with = 'vendored-sources'
[source.vendored-sources]
directory = '$(pwd)/$cargoDepsCopy'
EOF
unset cargoDepsCopy
export RUST_LOG=${logLevel} export RUST_LOG=${logLevel}
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt

View File

@ -22,9 +22,15 @@ stdenv.mkDerivation {
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
export CARGO_HOME=$(mktemp -d cargo-home.XXX) export CARGO_HOME=$(mktemp -d cargo-home.XXX)
cargo vendor cargo vendor --locked | tee result.txt
cp -ar vendor $out mkdir $out
# keep the outputted cargo config but remove the target directory.
# the target directory should be $out but that should change the sha256
cat result.txt | sed "s|directory = \".*|directory = \"REPLACEME\"|" > $out/.config
cp -ar vendor/* $out/
''; '';
outputHashAlgo = "sha256"; outputHashAlgo = "sha256";

View File

@ -32,7 +32,7 @@ rec {
cargo = callPackage ./cargo.nix rec { cargo = callPackage ./cargo.nix rec {
version = "0.23.0"; version = "0.23.0";
srcSha = "14b2n1msxma19ydchj54hd7f2zdsr524fg133dkmdn7j65f1x6aj"; srcSha = "14b2n1msxma19ydchj54hd7f2zdsr524fg133dkmdn7j65f1x6aj";
cargoSha256 = "1sj59z0w172qvjwg1ma5fr5am9dgw27086xwdnrvlrk4hffcr7y7"; cargoSha256 = "1mcqv45l0d1gw8v3v48gm1902xckj6r0s8l1z46nbmrsjs34rzhx";
inherit rustc; # the rustc that will be wrapped by cargo inherit rustc; # the rustc that will be wrapped by cargo
inherit rustPlatform; # used to build cargo inherit rustPlatform; # used to build cargo