Skip to content

Commit 04c3e0d

Browse files
committed
rustPlatform.buildRustPackage: fix cargoDeps inherited attribute overriding
Make `<rust-package>.cargoDeps` reference the overridden `<rust-package>.src` and other attributes. Let `stdenv.mkDerivation` handle the name of `<rust-package>.cargoDeps`. Make Rust package overriding *possible* before making further design decisions about the `<pkg>.overrideAttrs` interface.
1 parent 1b0d806 commit 04c3e0d

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

pkgs/build-support/rust/build-rust-package/default.nix

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
}:
1717

1818
let
19+
getOptionalAttrs =
20+
names: attrs: lib.getAttrs (lib.intersectLists names (lib.attrNames attrs)) attrs;
21+
1922
interpolateString =
2023
s:
2124
if lib.isList s then
@@ -39,16 +42,9 @@ lib.extendMkDerivation {
3942
extendDrvArgs =
4043
finalAttrs:
4144
{
42-
name ? "${args.pname}-${args.version}",
43-
4445
# Name for the vendored dependencies tarball
45-
cargoDepsName ? name,
46+
cargoDepsName ? null,
4647

47-
src ? null,
48-
srcs ? null,
49-
preUnpack ? null,
50-
unpackPhase ? null,
51-
postUnpack ? null,
5248
cargoPatches ? [ ],
5349
patches ? [ ],
5450
sourceRoot ? null,
@@ -112,17 +108,20 @@ lib.extendMkDerivation {
112108
throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set"
113109
else
114110
fetchCargoVendor (
115-
{
116-
inherit
117-
src
118-
srcs
119-
sourceRoot
120-
cargoRoot
121-
preUnpack
122-
unpackPhase
123-
postUnpack
124-
;
125-
name = cargoDepsName;
111+
getOptionalAttrs [
112+
"name"
113+
"pname"
114+
"version"
115+
"src"
116+
"srcs"
117+
"sourceRoot"
118+
"cargoRoot"
119+
"preUnpack"
120+
"unpackPhase"
121+
"postUnpack"
122+
] finalAttrs
123+
// {
124+
${if cargoDepsName != null then "name" else null} = cargoDepsName;
126125
patches = cargoPatches;
127126
hash = args.cargoHash;
128127
}

0 commit comments

Comments
 (0)