fectchcargo: don't break old sha256

This commit is contained in:
Symphorien Gibol
2018-09-11 23:44:14 +02:00
parent ccf72b8537
commit f20b229aa1
5 changed files with 25 additions and 57 deletions
+6 -20
View File
@@ -17,15 +17,9 @@ in
, cargoBuildFlags ? []
, cargoVendorDir ? null
# This tells cargo-vendor to include a Cargo config file in the fixed-output
# derivation. This is desirable in every case, so please set it to true.
# Eventually this will default to true and even later this option and the old
# behaviour will be removed.
, useRealVendorConfig ? false
, ... } @ args:
assert cargoVendorDir == null -> cargoSha256 != "unset";
assert cargoVendorDir != null -> !useRealVendorConfig;
let
cargoDeps = if cargoVendorDir == null
@@ -33,7 +27,6 @@ let
inherit name src srcs sourceRoot cargoUpdateHook;
patches = cargoPatches;
sha256 = cargoSha256;
writeVendorConfig = useRealVendorConfig;
}
else null;
@@ -68,19 +61,12 @@ in stdenv.mkDerivation (args // {
${setupVendorDir}
mkdir .cargo
'' + (if useRealVendorConfig then ''
substitute "$(pwd)/$cargoDepsCopy/.cargo/config" .cargo/config \
--subst-var-by vendor "$(pwd)/$cargoDepsCopy"
'' else ''
cat >.cargo/config <<-EOF
[source.crates-io]
registry = 'https://github.com/rust-lang/crates.io-index'
replace-with = 'vendored-sources'
[source.vendored-sources]
directory = '$(pwd)/$cargoDepsCopy'
EOF
'') + ''
config="$(pwd)/$cargoDepsCopy/.cargo/config";
if [[ ! -e $config ]]; then
config=${./fetchcargo-default-config.toml};
fi;
substitute $config .cargo/config \
--subst-var-by vendor "$(pwd)/$cargoDepsCopy"
unset cargoDepsCopy
+7
View File
@@ -0,0 +1,7 @@
[source."crates-io"]
"replace-with" = "vendored-sources"
[source."vendored-sources"]
"directory" = "@vendor@"
+11 -6
View File
@@ -1,5 +1,4 @@
{ stdenv, cacert, git, rust, cargo-vendor, python3 }:
{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "", writeVendorConfig ? false }:
let cargo-vendor-normalise = stdenv.mkDerivation {
name = "cargo-vendor-normalise";
src = ./cargo-vendor-normalise.py;
@@ -9,9 +8,10 @@ let cargo-vendor-normalise = stdenv.mkDerivation {
preferLocalBuild = true;
};
in
{ name ? "cargo-deps", src, srcs, patches, sourceRoot, sha256, cargoUpdateHook ? "" }:
stdenv.mkDerivation {
name = "${name}-vendor";
nativeBuildInputs = [ cacert cargo-vendor git rust.cargo ];
nativeBuildInputs = [ cacert cargo-vendor git cargo-vendor-normalise rust.cargo ];
inherit src srcs patches sourceRoot;
phases = "unpackPhase patchPhase installPhase";
@@ -33,10 +33,15 @@ stdenv.mkDerivation {
${cargoUpdateHook}
mkdir -p $out
cargo vendor $out > config
'' + stdenv.lib.optionalString writeVendorConfig ''
mkdir $out/.cargo
< config ${cargo-vendor-normalise}/bin/cargo-vendor-normalise > $out/.cargo/config
cargo vendor $out | cargo-vendor-normalise > config
# fetchcargo used to never keep the config output by cargo vendor
# and instead hardcode the config in ./fetchcargo-default-config.toml.
# This broke on packages needing git dependencies, so now we keep the config.
# But not to break old cargoSha256, if the previous behavior was enough,
# we don't store the config.
if ! cmp config ${./fetchcargo-default-config.toml} > /dev/null; then
install -Dt $out/.cargo config;
fi;
'';
outputHashAlgo = "sha256";