diff --git a/doc/languages-frameworks/rust.section.md b/doc/languages-frameworks/rust.section.md index 8f6db28ab4d6..18d3cd9c9269 100644 --- a/doc/languages-frameworks/rust.section.md +++ b/doc/languages-frameworks/rust.section.md @@ -80,6 +80,33 @@ The fetcher will verify that the `Cargo.lock` file is in sync with the `src` attribute, and fail the build if not. It will also will compress the vendor directory into a tar.gz archive. +The tarball with vendored dependencies contains a directory with the +package's `name`, which is normally composed of `pname` and +`version`. This means that the vendored dependencies hash +(`cargoSha256`/`cargoHash`) is dependent on the package name and +version. The `cargoDepsName` attribute can be used to use another name +for the directory of vendored dependencies. For example, the hash can +be made invariant to the version by setting `cargoDepsName` to +`pname`: + +```nix +rustPlatform.buildRustPackage rec { + pname = "broot"; + version = "1.2.0"; + + src = fetchCrate { + inherit pname version; + sha256 = "1mqaynrqaas82f5957lx31x80v74zwmwmjxxlbywajb61vh00d38"; + }; + + cargoHash = "sha256-JmBZcDVYJaK1cK05cxx5BrnGWp4t8ca6FLUbvIot67s="; + cargoDepsName = pname; + + # ... +} +``` + + ### Cross compilation By default, Rust packages are compiled for the host platform, just like any diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index dc86a7dc581f..4213598b8a31 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -23,6 +23,9 @@ # Legacy hash , cargoSha256 ? "" + # Name for the vendored dependencies tarball +, cargoDepsName ? name + , src ? null , srcs ? null , unpackPhase ? null @@ -60,7 +63,8 @@ let cargoDeps = if cargoVendorDir == null then fetchCargoTarball ({ - inherit name src srcs sourceRoot unpackPhase cargoUpdateHook; + inherit src srcs sourceRoot unpackPhase cargoUpdateHook; + name = cargoDepsName; hash = cargoHash; patches = cargoPatches; sha256 = cargoSha256;