From 978d298b4b94024b15bf2ab79c65495b03076346 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Tue, 25 Nov 2025 05:30:36 +0800 Subject: [PATCH] rustPlatform.buildRustPackage: Pass env.RUSTFLAGS only when specified or needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent shadowing RUSTFLAGS-like variables with lower priorities, such as mint-mod-mamanager's CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS Co-authored-by: Gergő Gutyina --- .../rust/build-rust-package/default.nix | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 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..06f96b75ce05 100644 --- a/pkgs/build-support/rust/build-rust-package/default.nix +++ b/pkgs/build-support/rust/build-rust-package/default.nix @@ -89,17 +89,20 @@ lib.extendMkDerivation { "buildRustPackage: `useFetchCargoVendor` is non‐optional and enabled by default as of 25.05, remove it" true; { - env = { - PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0; - RUST_LOG = logLevel; - RUSTFLAGS = - lib.optionalString ( - stdenv.hostPlatform.isDarwin && buildType == "debug" - ) "-C split-debuginfo=packed " - # Workaround the existing RUSTFLAGS specified as a list. - + interpolateString (args.RUSTFLAGS or ""); - } - // args.env or { }; + env = + let + isDarwinDebug = stdenv.hostPlatform.isDarwin && buildType == "debug"; + in + { + PKG_CONFIG_ALLOW_CROSS = if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0; + RUST_LOG = logLevel; + # Prevent shadowing *_RUSTFLAGS environment variables + ${if args ? RUSTFLAGS || isDarwinDebug then "RUSTFLAGS" else null} = + lib.optionalString isDarwinDebug "-C split-debuginfo=packed " + # Workaround the existing RUSTFLAGS specified as a list. + + interpolateString (args.RUSTFLAGS or ""); + } + // args.env or { }; cargoDeps = if cargoVendorDir != null then