lol

Merge pull request #205944 from ncfavier/structured-attrs-env

authored by

Naïm Favier and committed by
GitHub
84eebc0f d6038881

+31 -6
+4 -2
pkgs/stdenv/generic/make-derivation.nix
··· 274 274 "__darwinAllowLocalNetworking" 275 275 "__impureHostDeps" "__propagatedImpureHostDeps" 276 276 "sandboxProfile" "propagatedSandboxProfile"] 277 - ++ lib.optionals envIsExportable [ "env" ])) 277 + ++ lib.optional (__structuredAttrs || envIsExportable) "env")) 278 278 // (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) { 279 279 name = 280 280 let ··· 298 298 then attrs.name + hostSuffix 299 299 else "${attrs.pname}${staticMarker}${hostSuffix}-${attrs.version}" 300 300 ); 301 - }) // lib.optionalAttrs (envIsExportable && __structuredAttrs) { env = checkedEnv; } // { 301 + }) // lib.optionalAttrs __structuredAttrs { env = checkedEnv; } // { 302 302 builder = attrs.realBuilder or stdenv.shell; 303 303 args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; 304 304 inherit stdenv; ··· 485 485 let 486 486 overlappingNames = lib.intersectLists (lib.attrNames env) (lib.attrNames derivationArg); 487 487 in 488 + assert lib.assertMsg envIsExportable 489 + "When using structured attributes, `env` must be an attribute set of environment variables."; 488 490 assert lib.assertMsg (overlappingNames == [ ]) 489 491 "The ‘env’ attribute set cannot contain any attributes passed to derivation. The following attributes are overlapping: ${lib.concatStringsSep ", " overlappingNames}"; 490 492 lib.mapAttrs
+7 -4
pkgs/stdenv/generic/setup.sh
··· 383 383 ###################################################################### 384 384 # Initialisation. 385 385 386 - # export all vars that should be in the ENV 387 - for envVar in "${!env[@]}"; do 388 - declare -x "${envVar}=${env[${envVar}]}" 389 - done 386 + # If using structured attributes, export variables from `env` to the environment. 387 + # When not using structured attributes, those variables are already exported. 388 + if [[ -n $__structuredAttrs ]]; then 389 + for envVar in "${!env[@]}"; do 390 + declare -x "${envVar}=${env[${envVar}]}" 391 + done 392 + fi 390 393 391 394 392 395 # Set a fallback default value for SOURCE_DATE_EPOCH, used by some build tools
+20
pkgs/test/stdenv/default.nix
··· 49 49 declare -p string 50 50 echo "env.string = $string" 51 51 [[ $string == "testing-string" ]] || (echo "'\$string' was not 'testing-string'" && false) 52 + [[ "$(declare -p string)" == 'declare -x string="testing-string"' ]] || (echo "'\$string' was not exported" && false) 52 53 touch $out 53 54 ''; 54 55 } // extraAttrs); ··· 99 100 hooks = lib.recurseIntoAttrs (import ./hooks.nix { stdenv = bootStdenv; pkgs = earlyPkgs; }); 100 101 101 102 test-env-attrset = testEnvAttrset { name = "test-env-attrset"; stdenv' = bootStdenv; }; 103 + 104 + # Test compatibility with derivations using `env` as a regular variable. 105 + test-env-derivation = bootStdenv.mkDerivation rec { 106 + name = "test-env-derivation"; 107 + env = bootStdenv.mkDerivation { 108 + name = "foo"; 109 + buildCommand = '' 110 + mkdir "$out" 111 + touch "$out/bar" 112 + ''; 113 + }; 114 + 115 + passAsFile = [ "buildCommand" ]; 116 + buildCommand = '' 117 + declare -p env 118 + [[ $env == "${env}" ]] 119 + touch "$out" 120 + ''; 121 + }; 102 122 103 123 test-prepend-append-to-var = testPrependAndAppendToVar { 104 124 name = "test-prepend-append-to-var";