From fc43f076bbba14e7754f7f200509b95704796674 Mon Sep 17 00:00:00 2001 From: Eman Resu <78693624+quatquatt@users.noreply.github.com> Date: Sat, 9 May 2026 19:14:25 -0400 Subject: [PATCH] stdenv.mkDerivation: avoid listToAttrs if outputChecks will end up empty --- pkgs/stdenv/generic/make-derivation.nix | 68 ++++++++++++++----------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index a64b1119fead..701c1a1b0c93 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -775,35 +775,45 @@ let attrsOutputChecks = makeOutputChecks attrs; attrsOutputChecksFiltered = filterAttrs (_: v: v != null) attrsOutputChecks; in - builtins.listToAttrs ( - map (name: { - inherit name; - value = - let - raw = - if attrs ? outputChecks.${name} then - zipAttrsWith (_: concatLists) [ - attrsOutputChecksFiltered - (makeOutputChecks attrs.outputChecks.${name}) - ] - else - attrsOutputChecksFiltered; - in - # separateDebugInfo = true will put all sorts of files in - # the debug output which could carry references, but - # that's "normal". Notably it symlinks to the source. - # So disable reference checking for the debug output - if separateDebugInfo' && name == "debug" then - removeAttrs raw [ - "allowedReferences" - "allowedRequisites" - "disallowedReferences" - "disallowedRequisites" - ] - else - raw; - }) outputs - ); + # to avoid the listToAttrs in most common situations, we replicate + # what it would produce for most derivations. this can be improved + # in the future at the cost of a mass rebuild - empty attrsets for + # each output is a noop + if + !attrs ? outputs + && !attrs ? outputChecks + && (attrsOutputChecks == { } || attrsOutputChecksFiltered == { }) + then + { + out = { }; + ${if separateDebugInfo' then "debug" else null} = { }; + } + else + builtins.listToAttrs ( + map (name: { + inherit name; + value = + let + raw = zipAttrsWith (_: concatLists) [ + attrsOutputChecksFiltered + (makeOutputChecks (attrs.outputChecks.${name} or { })) + ]; + in + # separateDebugInfo = true will put all sorts of files in + # the debug output which could carry references, but + # that's "normal". Notably it symlinks to the source. + # So disable reference checking for the debug output + if separateDebugInfo' && name == "debug" then + removeAttrs raw [ + "allowedReferences" + "allowedRequisites" + "disallowedReferences" + "disallowedRequisites" + ] + else + raw; + }) outputs + ); }; in derivationArg;