git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #113176 from danieldk/cargoDepsName

buildRustPackage: add cargoDepsName attribute

commit3ef281c3a2f950331f4154436ff511daf70fb724 authorGraham Christensen <graham@grahamc.com> dateTue 23 Feb 2021, 10:02 (6 years ago) parent5eafa29d923960
2 files changed+32−1
doc/languages-frameworks/rust.section.md+27 pkgs/build-support/rust/default.nix+5−1
doc/languages-frameworks/rust.section.md+27
@@ -80,6 +80,33 @@ The fetcher will verify that the `Cargo.lock` file is in sync with the `src`
8080attribute, and fail the build if not. It will also will compress the vendor
8181directory into a tar.gz archive.
8282
83+The tarball with vendored dependencies contains a directory with the
84+package's `name`, which is normally composed of `pname` and
85+`version`. This means that the vendored dependencies hash
86+(`cargoSha256`/`cargoHash`) is dependent on the package name and
87+version. The `cargoDepsName` attribute can be used to use another name
88+for the directory of vendored dependencies. For example, the hash can
89+be made invariant to the version by setting `cargoDepsName` to
90+`pname`:
91+
92+```nix
93+rustPlatform.buildRustPackage rec {
94+ pname = "broot";
95+ version = "1.2.0";
96+
97+ src = fetchCrate {
98+ inherit pname version;
99+ sha256 = "1mqaynrqaas82f5957lx31x80v74zwmwmjxxlbywajb61vh00d38";
100+ };
101+
102+ cargoHash = "sha256-JmBZcDVYJaK1cK05cxx5BrnGWp4t8ca6FLUbvIot67s=";
103+ cargoDepsName = pname;
104+
105+ # ...
106+}
107+```
108+
109+
83110### Cross compilation
84111
85112By default, Rust packages are compiled for the host platform, just like any
pkgs/build-support/rust/default.nix+5−1
@@ -23,6 +23,9 @@
2323 # Legacy hash
2424, cargoSha256 ? ""
2525
26+ # Name for the vendored dependencies tarball
27+, cargoDepsName ? name
28+
2629, src ? null
2730, srcs ? null
2831, unpackPhase ? null
@@ -60,7 +63,8 @@ let
6063
6164 cargoDeps = if cargoVendorDir == null
6265 then fetchCargoTarball ({
63− inherit name src srcs sourceRoot unpackPhase cargoUpdateHook;
66+ inherit src srcs sourceRoot unpackPhase cargoUpdateHook;
67+ name = cargoDepsName;
6468 hash = cargoHash;
6569 patches = cargoPatches;
6670 sha256 = cargoSha256;