Merge pull request #205944 from ncfavier/structured-attrs-env
This commit is contained in:
commit
84eebc0fe4
@ -274,7 +274,7 @@ else let
|
|||||||
"__darwinAllowLocalNetworking"
|
"__darwinAllowLocalNetworking"
|
||||||
"__impureHostDeps" "__propagatedImpureHostDeps"
|
"__impureHostDeps" "__propagatedImpureHostDeps"
|
||||||
"sandboxProfile" "propagatedSandboxProfile"]
|
"sandboxProfile" "propagatedSandboxProfile"]
|
||||||
++ lib.optionals envIsExportable [ "env" ]))
|
++ lib.optional (__structuredAttrs || envIsExportable) "env"))
|
||||||
// (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
|
// (lib.optionalAttrs (attrs ? name || (attrs ? pname && attrs ? version)) {
|
||||||
name =
|
name =
|
||||||
let
|
let
|
||||||
@ -298,7 +298,7 @@ else let
|
|||||||
then attrs.name + hostSuffix
|
then attrs.name + hostSuffix
|
||||||
else "${attrs.pname}${staticMarker}${hostSuffix}-${attrs.version}"
|
else "${attrs.pname}${staticMarker}${hostSuffix}-${attrs.version}"
|
||||||
);
|
);
|
||||||
}) // lib.optionalAttrs (envIsExportable && __structuredAttrs) { env = checkedEnv; } // {
|
}) // lib.optionalAttrs __structuredAttrs { env = checkedEnv; } // {
|
||||||
builder = attrs.realBuilder or stdenv.shell;
|
builder = attrs.realBuilder or stdenv.shell;
|
||||||
args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
|
args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
|
||||||
inherit stdenv;
|
inherit stdenv;
|
||||||
@ -485,6 +485,8 @@ else let
|
|||||||
let
|
let
|
||||||
overlappingNames = lib.intersectLists (lib.attrNames env) (lib.attrNames derivationArg);
|
overlappingNames = lib.intersectLists (lib.attrNames env) (lib.attrNames derivationArg);
|
||||||
in
|
in
|
||||||
|
assert lib.assertMsg envIsExportable
|
||||||
|
"When using structured attributes, `env` must be an attribute set of environment variables.";
|
||||||
assert lib.assertMsg (overlappingNames == [ ])
|
assert lib.assertMsg (overlappingNames == [ ])
|
||||||
"The ‘env’ attribute set cannot contain any attributes passed to derivation. The following attributes are overlapping: ${lib.concatStringsSep ", " overlappingNames}";
|
"The ‘env’ attribute set cannot contain any attributes passed to derivation. The following attributes are overlapping: ${lib.concatStringsSep ", " overlappingNames}";
|
||||||
lib.mapAttrs
|
lib.mapAttrs
|
||||||
|
@ -383,10 +383,13 @@ printWords() {
|
|||||||
######################################################################
|
######################################################################
|
||||||
# Initialisation.
|
# Initialisation.
|
||||||
|
|
||||||
# export all vars that should be in the ENV
|
# If using structured attributes, export variables from `env` to the environment.
|
||||||
for envVar in "${!env[@]}"; do
|
# When not using structured attributes, those variables are already exported.
|
||||||
declare -x "${envVar}=${env[${envVar}]}"
|
if [[ -n $__structuredAttrs ]]; then
|
||||||
done
|
for envVar in "${!env[@]}"; do
|
||||||
|
declare -x "${envVar}=${env[${envVar}]}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Set a fallback default value for SOURCE_DATE_EPOCH, used by some build tools
|
# Set a fallback default value for SOURCE_DATE_EPOCH, used by some build tools
|
||||||
|
@ -49,6 +49,7 @@ let
|
|||||||
declare -p string
|
declare -p string
|
||||||
echo "env.string = $string"
|
echo "env.string = $string"
|
||||||
[[ $string == "testing-string" ]] || (echo "'\$string' was not 'testing-string'" && false)
|
[[ $string == "testing-string" ]] || (echo "'\$string' was not 'testing-string'" && false)
|
||||||
|
[[ "$(declare -p string)" == 'declare -x string="testing-string"' ]] || (echo "'\$string' was not exported" && false)
|
||||||
touch $out
|
touch $out
|
||||||
'';
|
'';
|
||||||
} // extraAttrs);
|
} // extraAttrs);
|
||||||
@ -100,6 +101,25 @@ in
|
|||||||
|
|
||||||
test-env-attrset = testEnvAttrset { name = "test-env-attrset"; stdenv' = bootStdenv; };
|
test-env-attrset = testEnvAttrset { name = "test-env-attrset"; stdenv' = bootStdenv; };
|
||||||
|
|
||||||
|
# Test compatibility with derivations using `env` as a regular variable.
|
||||||
|
test-env-derivation = bootStdenv.mkDerivation rec {
|
||||||
|
name = "test-env-derivation";
|
||||||
|
env = bootStdenv.mkDerivation {
|
||||||
|
name = "foo";
|
||||||
|
buildCommand = ''
|
||||||
|
mkdir "$out"
|
||||||
|
touch "$out/bar"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
passAsFile = [ "buildCommand" ];
|
||||||
|
buildCommand = ''
|
||||||
|
declare -p env
|
||||||
|
[[ $env == "${env}" ]]
|
||||||
|
touch "$out"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
test-prepend-append-to-var = testPrependAndAppendToVar {
|
test-prepend-append-to-var = testPrependAndAppendToVar {
|
||||||
name = "test-prepend-append-to-var";
|
name = "test-prepend-append-to-var";
|
||||||
stdenv' = bootStdenv;
|
stdenv' = bootStdenv;
|
||||||
|
Loading…
Reference in New Issue
Block a user