Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdenv: handle env gracefully #205944

Merged
merged 2 commits into from
Dec 15, 2022
Merged

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)

@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
Copy link
Member Author

Confirmed that the test fails on the previous commit.

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 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants