···173 separateDebugInfo' = separateDebugInfo && stdenv.hostPlatform.isLinux && !(stdenv.hostPlatform.useLLVM or false);
174 outputs' = outputs ++ lib.optional separateDebugInfo' "debug";
175176+ # Turn a derivation into its outPath without a string context attached.
177+ # See the comment at the usage site.
178+ unsafeDerivationToUntrackedOutpath = drv:
179+ if lib.isDerivation drv
180+ then builtins.unsafeDiscardStringContext drv.outPath
181+ else drv;
182+183 noNonNativeDeps = builtins.length (depsBuildTarget ++ depsBuildTargetPropagated
184 ++ depsHostHost ++ depsHostHostPropagated
185 ++ buildInputs ++ propagatedBuildInputs
···453 "/bin/sh"
454 ];
455 __propagatedImpureHostDeps = computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps;
456+ } //
457+ # If we use derivations directly here, they end up as build-time dependencies.
458+ # This is especially problematic in the case of disallowed*, since the disallowed
459+ # derivations will be built by nix as build-time dependencies, while those
460+ # derivations might take a very long time to build, or might not even build
461+ # successfully on the platform used.
462+ # We can improve on this situation by instead passing only the outPath,
463+ # without an attached string context, to nix. The out path will be a placeholder
464+ # which will be replaced by the actual out path if the derivation in question
465+ # is part of the final closure (and thus needs to be built). If it is not
466+ # part of the final closure, then the placeholder will be passed along,
467+ # but in that case we know for a fact that the derivation is not part of the closure.
468+ # This means that passing the out path to nix does the right thing in either
469+ # case, both for disallowed and allowed references/requisites, and we won't
470+ # build the derivation if it wouldn't be part of the closure, saving time and resources.
471+ # While the problem is less severe for allowed*, since we want the derivation
472+ # to be built eventually, we would still like to get the error early and without
473+ # having to wait while nix builds a derivation that might not be used.
474+ # See also https://github.com/NixOS/nix/issues/4629
475+ lib.optionalAttrs (attrs ? disallowedReferences) {
476+ disallowedReferences =
477+ map unsafeDerivationToUntrackedOutpath attrs.disallowedReferences;
478+ } //
479+ lib.optionalAttrs (attrs ? disallowedRequisites) {
480+ disallowedRequisites =
481+ map unsafeDerivationToUntrackedOutpath attrs.disallowedRequisites;
482+ } //
483+ lib.optionalAttrs (attrs ? allowedReferences) {
484+ allowedReferences =
485+ lib.mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedReferences;
486+ } //
487+ lib.optionalAttrs (attrs ? allowedRequisites) {
488+ allowedRequisites =
489+ lib.mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedRequisites;
490 };
491492 validity = checkMeta { inherit meta attrs; };