Skip to content

Commit 0c8cc4c

Browse files
committed
stdenv: pass meta.mainProgram to build environment as NIX_MAIN_PROGRAM
1 parent b0ae785 commit 0c8cc4c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkgs/stdenv/generic/make-derivation.nix

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,9 @@ let
716716
);
717717

718718
let
719-
envIsExportable = isAttrs env && !isDerivation env;
719+
mainProgram = meta.mainProgram or null;
720+
env' = env // lib.optionalAttrs (mainProgram != null) { NIX_MAIN_PROGRAM = mainProgram; };
721+
envIsExportable = isAttrs env' && !isDerivation env';
720722

721723
derivationArg = makeDerivationArgument (
722724
removeAttrs attrs (
@@ -746,11 +748,11 @@ let
746748

747749
checkedEnv =
748750
let
749-
overlappingNames = attrNames (builtins.intersectAttrs env derivationArg);
751+
overlappingNames = attrNames (builtins.intersectAttrs env' derivationArg);
750752
prettyPrint = lib.generators.toPretty { };
751753
makeError =
752754
name:
753-
" - ${name}: in `env`: ${prettyPrint env.${name}}; in derivation arguments: ${
755+
" - ${name}: in `env`: ${prettyPrint env'.${name}}; in derivation arguments: ${
754756
prettyPrint derivationArg.${name}
755757
}";
756758
errors = lib.concatMapStringsSep "\n" makeError overlappingNames;
@@ -764,7 +766,7 @@ let
764766
assert assertMsg (isString v || isBool v || isInt v || isDerivation v)
765767
"The `env` attribute set can only contain derivation, string, boolean or integer attributes. The `${n}` attribute is of type ${builtins.typeOf v}.";
766768
v
767-
) env;
769+
) env';
768770

769771
# Fixed-output derivations may not reference other paths, which means that
770772
# for a fixed-output derivation, the corresponding inputDerivation should

0 commit comments

Comments
 (0)