Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ci/checks/env-null.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
pkgs,
self,
}:

let
wrappedPackage = self.lib.wrapPackage {
inherit pkgs;
package = pkgs.hello;
env.MY_NULL_ENV = null;
envDefault.MY_NULL_DEFAULT = null;
};

in
pkgs.runCommand "env-null-test" { } ''
echo "Testing that null env and envDefault entries are omitted..."

wrapperScript="${wrappedPackage}/bin/hello"
if [ ! -f "$wrapperScript" ]; then
echo "FAIL: Wrapper script not found"
exit 1
fi

if grep -q "MY_NULL_ENV" "$wrapperScript"; then
echo "FAIL: MY_NULL_ENV should be omitted (value was null)"
cat "$wrapperScript"
exit 1
fi

if grep -q "MY_NULL_DEFAULT" "$wrapperScript"; then
echo "FAIL: MY_NULL_DEFAULT should be omitted (value was null)"
cat "$wrapperScript"
exit 1
fi

echo "SUCCESS: null env and envDefault entries correctly omitted"
touch $out
''
4 changes: 3 additions & 1 deletion lib/makeWrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ in
++ mapAndLiftDal "addFlag" (config.addFlag or [ ])
++ mapAndLiftDal "appendFlag" (config.appendFlag or [ ]);
in
if sortResult then wlib.dag.unwrapSort "makeWrapper" unsorted else unsorted;
builtins.filter (v: !(v.type == "env" || v.type == "envDefault") || v.data or null != null) (
if sortResult then wlib.dag.unwrapSort "makeWrapper" unsorted else unsorted
);

/*
splitDal receives the dal as returned by `aggregateSingleOptionSet` and splits it into 2 lists, `args` and `other`.
Expand Down
4 changes: 2 additions & 2 deletions modules/makeWrapper/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ let
];
};
options.${if !(excluded.env or false) then "env" else null} = lib.mkOption {
type = wlib.types.dagWithEsc wlib.types.stringable;
type = wlib.types.dagWithEsc (lib.types.nullOr wlib.types.stringable);
default = if mainConfig != null && config.mirror or false then mainConfig.env else { };
example = {
"XDG_DATA_HOME" = "/somewhere/on/your/machine";
Expand All @@ -425,7 +425,7 @@ let
'';
};
options.${if !(excluded.envDefault or false) then "envDefault" else null} = lib.mkOption {
type = wlib.types.dagWithEsc wlib.types.stringable;
type = wlib.types.dagWithEsc (lib.types.nullOr wlib.types.stringable);
default = if mainConfig != null && config.mirror or false then mainConfig.envDefault else { };
example = {
"XDG_DATA_HOME" = "/only/if/not/set";
Expand Down
Loading