diff options
Diffstat (limited to 'pkgs/build-support/rust/fetchcargo.nix')
-rw-r--r-- | pkgs/build-support/rust/fetchcargo.nix | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/pkgs/build-support/rust/fetchcargo.nix b/pkgs/build-support/rust/fetchcargo.nix index 2670ed528640..9e77f8817b24 100644 --- a/pkgs/build-support/rust/fetchcargo.nix +++ b/pkgs/build-support/rust/fetchcargo.nix @@ -1,8 +1,26 @@ -{ stdenv, cacert, git, rust, cargo-vendor }: +{ stdenv, cacert, git, rust, cargo-vendor, python3 }: +let cargo-vendor-normalise = stdenv.mkDerivation { + name = "cargo-vendor-normalise"; + src = ./cargo-vendor-normalise.py; + nativeBuildInputs = [ python3.pkgs.wrapPython ]; + unpackPhase = ":"; + installPhase = "install -D $src $out/bin/cargo-vendor-normalise"; + pythonPath = [ python3.pkgs.toml ]; + postFixup = "wrapPythonPrograms"; + doInstallCheck = true; + installCheckPhase = '' + # check that ./fetchcargo-default-config.toml is a fix point + reference=${./fetchcargo-default-config.toml} + < $reference $out/bin/cargo-vendor-normalise > test; + cmp test $reference + ''; + 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"; @@ -23,9 +41,16 @@ stdenv.mkDerivation { ${cargoUpdateHook} - cargo vendor - - cp -ar vendor $out + mkdir -p $out + 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"; |