Skip to content

Commit eb0312e

Browse files
committed
rustPlatform.buildRustPackage: fix cargoDeps inherited attribute overriding
Make <rust-package>.cargoDeps reference the overridden <rust-package>.src and other attributes. Make Rust package overriding *possible* before making further design decisions about the <pkg>.overrideAttrs interface.
1 parent fbcf476 commit eb0312e

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
rustc,
1515
windows,
1616
}:
17-
17+
let
18+
getOptionalAttrs =
19+
names: attrs: lib.getAttrs (lib.intersectLists names (lib.attrNames attrs)) attrs;
20+
in
1821
lib.extendMkDerivation {
1922
constructDrv = stdenv.mkDerivation;
2023

@@ -28,16 +31,9 @@ lib.extendMkDerivation {
2831
extendDrvArgs =
2932
finalAttrs:
3033
{
31-
name ? "${args.pname}-${args.version}",
32-
3334
# Name for the vendored dependencies tarball
34-
cargoDepsName ? name,
35+
cargoDepsName ? finalAttrs.name,
3536

36-
src ? null,
37-
srcs ? null,
38-
preUnpack ? null,
39-
unpackPhase ? null,
40-
postUnpack ? null,
4137
cargoPatches ? [ ],
4238
patches ? [ ],
4339
sourceRoot ? null,
@@ -82,6 +78,8 @@ lib.extendMkDerivation {
8278
RUSTFLAGS = "-C split-debuginfo=packed " + (args.RUSTFLAGS or "");
8379
}
8480
// {
81+
name = args.name or "${finalAttrs.pname}-${finalAttrs.version}";
82+
8583
cargoDeps =
8684
if cargoVendorDir != null then
8785
null
@@ -93,16 +91,16 @@ lib.extendMkDerivation {
9391
throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set"
9492
else
9593
fetchCargoVendor (
96-
{
97-
inherit
98-
src
99-
srcs
100-
sourceRoot
101-
cargoRoot
102-
preUnpack
103-
unpackPhase
104-
postUnpack
105-
;
94+
getOptionalAttrs [
95+
"src"
96+
"srcs"
97+
"sourceRoot"
98+
"cargoRoot"
99+
"preUnpack"
100+
"unpackPhase"
101+
"postUnpack"
102+
] finalAttrs
103+
// {
106104
name = cargoDepsName;
107105
patches = cargoPatches;
108106
hash = args.cargoHash;

0 commit comments

Comments
 (0)