Skip to content

stdenv: handle env gracefully#205944

Merged
ncfavier merged 2 commits intoNixOS:stagingfrom
ncfavier:structured-attrs-env
Dec 15, 2022
Merged

stdenv: handle env gracefully#205944
ncfavier merged 2 commits intoNixOS:stagingfrom
ncfavier:structured-attrs-env

Conversation

@ncfavier
Copy link
Member

Derivations not using __structuredAttrs should not attempt to set environment variables from env.

Derivations using __structuredAttrs should fail if env is not exportable.

See #175649 (comment)

@github-actions github-actions bot added the 6.topic: stdenv Standard environment label Dec 13, 2022
@roberth
Copy link
Member

roberth commented Dec 13, 2022

Could you test this in pkgs/test/stdenv/default.nix?

@Artturin
Copy link
Member

Artturin commented Dec 13, 2022

diff --git a/pkgs/test/stdenv/default.nix b/pkgs/test/stdenv/default.nix
index b27fc25356a..2274a20ff17 100644
--- a/pkgs/test/stdenv/default.nix
+++ b/pkgs/test/stdenv/default.nix
@@ -100,6 +100,25 @@ in
 
   test-env-attrset = testEnvAttrset { name = "test-env-attrset"; stdenv' = bootStdenv; };
 
+  test-env-equals-derivation = bootStdenv.mkDerivation rec {
+    name = "test-env-equals-derivation";
+    env = bootStdenv.mkDerivation {
+      name = "foo";
+      buildCommand = ''
+        mkdir $out
+        touch $out/bar
+      '';
+    };
+
+    passAsFile = [ "buildCommand" ];
+    buildCommand = ''
+      declare -p env
+      echo ''${env[0]}
+      [[ "''${env[0]}" == "${env.out}" ]]
+      touch $out
+    '';
+  };
+
   test-prepend-append-to-var = testPrependAndAppendToVar {
     name = "test-prepend-append-to-var";
     stdenv' = bootStdenv;

@ncfavier ncfavier force-pushed the structured-attrs-env branch from a12b1c2 to f65096c Compare December 13, 2022 19:24
@ncfavier
Copy link
Member Author

Confirmed that the test fails on the previous commit.

@ofborg ofborg bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Dec 13, 2022
@ncfavier ncfavier force-pushed the structured-attrs-env branch from f65096c to f3de115 Compare December 14, 2022 08:50
ncfavier and others added 2 commits December 15, 2022 13:27
Derivations not using `__structuredAttrs` should not attempt to set
environment variables from `env`.

Derivations using `__structuredAttrs` should fail if `env` is not
exportable.
@ncfavier ncfavier force-pushed the structured-attrs-env branch from 6e1bab3 to 9b1e8d7 Compare December 15, 2022 12:27
@ncfavier ncfavier merged commit 84eebc0 into NixOS:staging Dec 15, 2022
@ncfavier ncfavier deleted the structured-attrs-env branch December 15, 2022 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: stdenv Standard environment 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux-stdenv This PR causes stdenv to rebuild on Linux and must target a staging branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants