diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 95b6f357e56a..db0d2c53bb1e 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -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 diff --git a/pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py b/pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py index 2d7a18957184..90933b089c92 100755 --- a/pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py +++ b/pkgs/build-support/rust/fetch-cargo-tarball/cargo-vendor-normalise.py @@ -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@" diff --git a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix b/pkgs/build-support/rust/fetch-cargo-tarball/default.nix index 2f1f3547dbb0..6d6219078bac 100644 --- a/pkgs/build-support/rust/fetch-cargo-tarball/default.nix +++ b/pkgs/build-support/rust/fetch-cargo-tarball/default.nix @@ -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 < $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" ])) diff --git a/pkgs/tools/misc/elfcat/default.nix b/pkgs/tools/misc/elfcat/default.nix index e2dec357d6d2..359bd6d3ab93 100644 --- a/pkgs/tools/misc/elfcat/default.nix +++ b/pkgs/tools/misc/elfcat/default.nix @@ -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.";