From e85060f58c63a0589f6e89ff418fa142a6409508 Mon Sep 17 00:00:00 2001 From: Bernardo Meurer Costa Date: Mon, 23 Mar 2026 16:39:28 +0000 Subject: [PATCH] buildRustCrate: remap rustc store path to break rust-src closure leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the rust-src component is installed (common with rust-overlay toolchains via rust-toolchain.toml), rustc unvirtualises libstd source paths. Panic locations from monomorphised generic std code (BTreeMap, VecDeque, sync primitives, etc.) then embed the toolchain store path in .rodata, pulling the entire multi-GB toolchain into the runtime closure. This is not an RPATH issue — stdenv's patchelf --shrink-rpath already cleans that. The reference is a core::panic::Location string. Remap the rustc store path to /rustc so panic messages stay readable but no longer create a store-path dependency. This is a no-op for toolchains without rust-src (the prefix simply never matches). --- pkgs/build-support/rust/build-rust-crate/build-crate.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix index 24d51ce11382..befe5a1f1f7d 100644 --- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix @@ -31,6 +31,12 @@ let (if release then "-C opt-level=3" else "-C debuginfo=2") "-C codegen-units=${toString codegenUnits}" "--remap-path-prefix=$NIX_BUILD_TOP=/" + # When the rust-src component is present (common with rust-overlay + # toolchains), rustc unvirtualises libstd source paths. Panic + # locations from monomorphised generic std code then embed the + # toolchain store path in .rodata, pulling the entire toolchain into + # the closure. Remap to a stable placeholder to break the reference. + "--remap-path-prefix=${rustc}=/rustc" (mkRustcDepArgs dependencies crateRenames) (mkRustcFeatureArgs crateFeatures) ]