From 04c3e0defa78848cccbf0b38e8a47e9a1cb626bd Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Wed, 20 Aug 2025 19:08:27 +0800 Subject: [PATCH] rustPlatform.buildRustPackage: fix cargoDeps inherited attribute overriding Make `.cargoDeps` reference the overridden `.src` and other attributes. Let `stdenv.mkDerivation` handle the name of `.cargoDeps`. Make Rust package overriding *possible* before making further design decisions about the `.overrideAttrs` interface. --- .../rust/build-rust-package/default.nix | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-package/default.nix b/pkgs/build-support/rust/build-rust-package/default.nix index 7ad39a58935c..bb445d9f173a 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -16,6 +16,9 @@ }: let + getOptionalAttrs = + names: attrs: lib.getAttrs (lib.intersectLists names (lib.attrNames attrs)) attrs; + interpolateString = s: if lib.isList s then @@ -39,16 +42,9 @@ lib.extendMkDerivation { extendDrvArgs = finalAttrs: { - name ? "${args.pname}-${args.version}", - # Name for the vendored dependencies tarball - cargoDepsName ? name, + cargoDepsName ? null, - src ? null, - srcs ? null, - preUnpack ? null, - unpackPhase ? null, - postUnpack ? null, cargoPatches ? [ ], patches ? [ ], sourceRoot ? null, @@ -112,17 +108,20 @@ lib.extendMkDerivation { throw "cargoHash, cargoVendorDir, cargoDeps, or cargoLock must be set" else fetchCargoVendor ( - { - inherit - src - srcs - sourceRoot - cargoRoot - preUnpack - unpackPhase - postUnpack - ; - name = cargoDepsName; + getOptionalAttrs [ + "name" + "pname" + "version" + "src" + "srcs" + "sourceRoot" + "cargoRoot" + "preUnpack" + "unpackPhase" + "postUnpack" + ] finalAttrs + // { + ${if cargoDepsName != null then "name" else null} = cargoDepsName; patches = cargoPatches; hash = args.cargoHash; }