diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix index 2575c7f3107..e027853255c 100644 --- a/pkgs/build-support/rust/default.nix +++ b/pkgs/build-support/rust/default.nix @@ -77,6 +77,7 @@ let ''; targetIsJSON = stdenv.lib.hasSuffix ".json" target; + useSysroot = targetIsJSON && !__internal_dontAddSysroot; # see https://github.com/rust-lang/cargo/blob/964a16a28e234a3d397b2a7031d4ab4a428b1391/src/cargo/core/compiler/compile_kind.rs#L151-L168 # the "${}" is needed to transform the path into a /nix/store path before baseNameOf @@ -202,8 +203,8 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // { "CXX_${rust.toRustTarget stdenv.buildPlatform}"="${cxxForBuild}" \ "CC_${rust.toRustTarget stdenv.hostPlatform}"="${ccForHost}" \ "CXX_${rust.toRustTarget stdenv.hostPlatform}"="${cxxForHost}" \ - ${stdenv.lib.optionalString - (targetIsJSON && !__internal_dontAddSysroot) "RUSTFLAGS=\"--sysroot ${sysroot} $RUSTFLAGS\" " + ${stdenv.lib.optionalString useSysroot + "RUSTFLAGS=\"--sysroot ${sysroot} $RUSTFLAGS\" " }cargo build -j $NIX_BUILD_CORES \ ${stdenv.lib.optionalString (buildType == "release") "--release"} \ --target ${target} \