From e749b0a6c79dd13e42d84ad26f6761518d8bf1bd Mon Sep 17 00:00:00 2001 From: Lily Ballard Date: Tue, 14 Apr 2026 21:40:50 -0700 Subject: [PATCH 1/4] cargo: remove runtime references to cargo-bootstrap The shell completions were being generated by cargo-bootstrap instead of by the just-built cargo, which meant they were embedding the cargo-bootstrap path and causing it to be part of the runtime closure. --- pkgs/development/compilers/rust/cargo.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index a86e4a3d186d..87903ed443d5 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -80,9 +80,9 @@ rustPlatform.buildRustPackage.override if stdenv.buildPlatform.canExecute stdenv.hostPlatform then '' installShellCompletion --cmd cargo \ - --bash <(CARGO_COMPLETE=bash cargo) \ - --fish <(CARGO_COMPLETE=fish cargo) \ - --zsh <(CARGO_COMPLETE=zsh cargo) + --bash <(CARGO_COMPLETE=bash $out/bin/cargo) \ + --fish <(CARGO_COMPLETE=fish $out/bin/cargo) \ + --zsh <(CARGO_COMPLETE=zsh $out/bin/cargo) '' else '' From 8eb3c82575d6ea29bb031db9ac450847d73069f9 Mon Sep 17 00:00:00 2001 From: Lily Ballard Date: Wed, 15 Apr 2026 21:28:26 -0700 Subject: [PATCH 2/4] rustPlatform.rust: undeprecate These attributes were deprecated in #230951 because they confused things with splicing, e.g. passing `rustPlatform.rust.rustc` to `nativeBuildInputs` would get the wrong derivation when cross-compiling. This was a consequence of the fact that they come from the buildPackages set. But we still want to expose these packages as otherwise Rust packages have no way to reference the rustc and cargo that build them, which means they can't e.g. use `disallowedReferences` to ensure they don't end up in the runtime closure. Just as `stdenv.cc` itself isn't spliced, we can solve this problem by unsplicing the packages. --- .../compilers/rust/make-rust-platform.nix | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index 1f69bb92e213..254ae918bbf6 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -72,14 +72,16 @@ maturinBuildHook bindgenHook ; + + # Let packages reference the build derivations, e.g. for disallowedReferences. + # Get rid of the splicing though, so `nativeBuildInputs = [ rustPlatform.rust.rustc ]` works. + rust = { + rustc = rustc.__spliced.hostTarget or rustc; + cargo = cargo.__spliced.hostTarget or cargo; + }; }; }) // lib.optionalAttrs config.allowAliases { - rust = { - rustc = lib.warn "rustPlatform.rust.rustc is deprecated. Use rustc instead." rustc; - cargo = lib.warn "rustPlatform.rust.cargo is deprecated. Use cargo instead." cargo; - }; - # Added in 25.05. fetchCargoTarball = throw "`rustPlatform.fetchCargoTarball` has been removed in 25.05, use `rustPlatform.fetchCargoVendor` instead"; } From 126bd3b578fdeedd9af7887e028dfdfbf4a223dd Mon Sep 17 00:00:00 2001 From: Lily Ballard Date: Tue, 14 Apr 2026 21:39:14 -0700 Subject: [PATCH 3/4] cargo: disallow references to bootstrap cargo, rustc cargo recently accidentally gained a runtime dependency on cargo-bootstrap, we don't want to let that happen again. --- pkgs/development/compilers/rust/cargo.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index 87903ed443d5..3fb4f948a223 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -109,6 +109,13 @@ rustPlatform.buildRustPackage.override runHook postInstallCheck ''; + # Make sure our build rustc/cargo never make it into our runtime closure + disallowedReferences = [ + rustPlatform.rust.cargo + rustPlatform.rust.rustc + rustPlatform.rust.rustc.unwrapped + ]; + meta = { homepage = "https://crates.io"; description = "Downloads your Rust project's dependencies and builds your project"; From 19d080de23ecc22a508509f0f6734c972a785e62 Mon Sep 17 00:00:00 2001 From: Lily Ballard Date: Wed, 15 Apr 2026 22:44:18 -0700 Subject: [PATCH 4/4] rustc-unwrapped: disallow references to build rustc/cargo --- pkgs/development/compilers/rust/rustc.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index 8b816b08f9b2..2419ab02c761 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -443,6 +443,12 @@ stdenv.mkDerivation (finalAttrs: { requiredSystemFeatures = [ "big-parallel" ]; + # Make sure our bootstrap packages don't end up in our runtime closure + disallowedReferences = [ + cargo + rustc + ]; + passthru = { llvm = llvmShared; inherit llvmPackages;