Skip to content

Commit

Permalink
stdenv: fix env pass through with structured attrs
Browse files Browse the repository at this point in the history
When using structured attributes, `env` attributes must not be
derivation arguments.

Fixes the following example:
```
let
  drv = stdenv.mkDerivation {
    name = "foo";
    __structuredAttrs = true;
    env.FOO = "foo";
  };
in
stdenv.mkDerivation drv.drvAttrs
```

Note that passthru takes precedence over env.

```
nix-repl> (stdenv.mkDerivation {
            name = "foo";
            env.FOO = "foo";
            passthru.FOO = "bar";
          }).FOO
"bar"
```
  • Loading branch information
tie committed Aug 15, 2024
1 parent e0626c7 commit f7c973d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,14 @@ extendDerivation
# Pass through extra attributes that are not inputs, but
# should be made available to Nix expressions using the
# derivation (e.g., in assertions).
#
# For structured attributes, we do not want checkedEnv to end up in
# derivation arguments (i.e. drvAttrs) to allow reusing them as mkDerivation
# argument again (checkedEnv does not allow collisions between derivation
# arguments and `env` contents).
optionalAttrs (envIsExportable && __structuredAttrs) checkedEnv //
passthru)
(derivation (derivationArg // optionalAttrs envIsExportable checkedEnv));
(derivation (derivationArg // optionalAttrs (envIsExportable && !__structuredAttrs) checkedEnv));

in
{
Expand Down

0 comments on commit f7c973d

Please sign in to comment.