Merge: stdenv.mkDerivation: support output checks with and without structuredAttrs (#357054)

authored by

Maximilian Bosch and committed by
GitHub
65b948d4 cde67126

+53 -52
+1 -12
pkgs/by-name/ne/neovim-unwrapped/package.nix
··· 188 188 -e "s|\$<TARGET_FILE:nvim|\${stdenv.hostPlatform.emulator buildPackages} &|g" 189 189 ''; 190 190 # check that the above patching actually works 191 - outputChecks = 192 - let 193 - disallowedRequisites = [ stdenv.cc ] ++ lib.optional (lua != codegenLua) codegenLua; 194 - in 195 - { 196 - out = { 197 - inherit disallowedRequisites; 198 - }; 199 - debug = { 200 - inherit disallowedRequisites; 201 - }; 202 - }; 191 + disallowedRequisites = [ stdenv.cc ] ++ lib.optional (lua != codegenLua) codegenLua; 203 192 204 193 cmakeFlags = 205 194 [
+4 -6
pkgs/servers/sql/postgresql/generic.nix
··· 132 132 disallowedReferences = [ "dev" "doc" "man" ]; 133 133 disallowedRequisites = [ 134 134 stdenv'.cc 135 + llvmPackages.llvm.out 135 136 ] ++ ( 136 137 map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs) 137 - ) ++ lib.optionals jitSupport [ 138 - llvmPackages.llvm.out 139 - ]; 138 + ); 140 139 }; 141 140 outputChecks.lib = { 142 141 disallowedReferences = [ "out" "dev" "doc" "man" ]; 143 142 disallowedRequisites = [ 144 143 stdenv'.cc 144 + llvmPackages.llvm.out 145 145 ] ++ ( 146 146 map lib.getDev (builtins.filter (drv: drv ? "dev") finalAttrs.buildInputs) 147 - ) ++ lib.optionals jitSupport [ 148 - llvmPackages.llvm.out 149 - ]; 147 + ); 150 148 }; 151 149 152 150 buildInputs = [
+48 -34
pkgs/stdenv/generic/make-derivation.nix
··· 134 134 "__darwinAllowLocalNetworking" 135 135 "__impureHostDeps" "__propagatedImpureHostDeps" 136 136 "sandboxProfile" "propagatedSandboxProfile" 137 + "disallowedReferences" "disallowedRequisites" 138 + "allowedReferences" "allowedRequisites" 137 139 ]; 138 140 139 141 # Turn a derivation into its outPath without a string context attached. ··· 142 144 if isDerivation drv && (!drv.__contentAddressed or false) 143 145 then builtins.unsafeDiscardStringContext drv.outPath 144 146 else drv; 147 + 148 + makeOutputChecks = attrs: 149 + # If we use derivations directly here, they end up as build-time dependencies. 150 + # This is especially problematic in the case of disallowed*, since the disallowed 151 + # derivations will be built by nix as build-time dependencies, while those 152 + # derivations might take a very long time to build, or might not even build 153 + # successfully on the platform used. 154 + # We can improve on this situation by instead passing only the outPath, 155 + # without an attached string context, to nix. The out path will be a placeholder 156 + # which will be replaced by the actual out path if the derivation in question 157 + # is part of the final closure (and thus needs to be built). If it is not 158 + # part of the final closure, then the placeholder will be passed along, 159 + # but in that case we know for a fact that the derivation is not part of the closure. 160 + # This means that passing the out path to nix does the right thing in either 161 + # case, both for disallowed and allowed references/requisites, and we won't 162 + # build the derivation if it wouldn't be part of the closure, saving time and resources. 163 + # While the problem is less severe for allowed*, since we want the derivation 164 + # to be built eventually, we would still like to get the error early and without 165 + # having to wait while nix builds a derivation that might not be used. 166 + # See also https://github.com/NixOS/nix/issues/4629 167 + optionalAttrs (attrs ? disallowedReferences) { 168 + disallowedReferences = 169 + map unsafeDerivationToUntrackedOutpath attrs.disallowedReferences; 170 + } // 171 + optionalAttrs (attrs ? disallowedRequisites) { 172 + disallowedRequisites = 173 + map unsafeDerivationToUntrackedOutpath attrs.disallowedRequisites; 174 + } // 175 + optionalAttrs (attrs ? allowedReferences) { 176 + allowedReferences = 177 + mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedReferences; 178 + } // 179 + optionalAttrs (attrs ? allowedRequisites) { 180 + allowedRequisites = 181 + mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedRequisites; 182 + }; 145 183 146 184 makeDerivationArgument = 147 185 ··· 455 493 "/bin/sh" 456 494 ]; 457 495 __propagatedImpureHostDeps = computedPropagatedImpureHostDeps ++ __propagatedImpureHostDeps; 458 - }) // 459 - # If we use derivations directly here, they end up as build-time dependencies. 460 - # This is especially problematic in the case of disallowed*, since the disallowed 461 - # derivations will be built by nix as build-time dependencies, while those 462 - # derivations might take a very long time to build, or might not even build 463 - # successfully on the platform used. 464 - # We can improve on this situation by instead passing only the outPath, 465 - # without an attached string context, to nix. The out path will be a placeholder 466 - # which will be replaced by the actual out path if the derivation in question 467 - # is part of the final closure (and thus needs to be built). If it is not 468 - # part of the final closure, then the placeholder will be passed along, 469 - # but in that case we know for a fact that the derivation is not part of the closure. 470 - # This means that passing the out path to nix does the right thing in either 471 - # case, both for disallowed and allowed references/requisites, and we won't 472 - # build the derivation if it wouldn't be part of the closure, saving time and resources. 473 - # While the problem is less severe for allowed*, since we want the derivation 474 - # to be built eventually, we would still like to get the error early and without 475 - # having to wait while nix builds a derivation that might not be used. 476 - # See also https://github.com/NixOS/nix/issues/4629 477 - optionalAttrs (attrs ? disallowedReferences) { 478 - disallowedReferences = 479 - map unsafeDerivationToUntrackedOutpath attrs.disallowedReferences; 480 - } // 481 - optionalAttrs (attrs ? disallowedRequisites) { 482 - disallowedRequisites = 483 - map unsafeDerivationToUntrackedOutpath attrs.disallowedRequisites; 484 - } // 485 - optionalAttrs (attrs ? allowedReferences) { 486 - allowedReferences = 487 - mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedReferences; 488 - } // 489 - optionalAttrs (attrs ? allowedRequisites) { 490 - allowedRequisites = 491 - mapNullable unsafeDerivationToUntrackedOutpath attrs.allowedRequisites; 496 + }) // lib.optionalAttrs (!__structuredAttrs) ( 497 + makeOutputChecks attrs 498 + ) // lib.optionalAttrs (__structuredAttrs) { 499 + outputChecks = builtins.listToAttrs (map (name: { 500 + inherit name; 501 + value = lib.zipAttrsWith (_: builtins.concatLists) [ 502 + (makeOutputChecks attrs) 503 + (makeOutputChecks attrs.outputChecks.${name} or {}) 504 + ]; 505 + }) outputs); 492 506 }; 493 507 494 508 in