nixos/environment: make {sessionV,v}ariables items nullable (#354186)

This commit is contained in:
Aleksana
2025-03-27 10:10:31 +08:00
committed by GitHub
3 changed files with 19 additions and 4 deletions
+6 -2
View File
@@ -34,14 +34,18 @@ in
description = ''
A set of environment variables used in the global environment.
These variables will be set on shell initialisation (e.g. in /etc/profile).
The value of each variable can be either a string or a list of
strings. The latter is concatenated, interspersed with colon
characters.
Setting a variable to `null` does nothing. You can override a
variable set by another module to `null` to unset it.
'';
type = with lib.types; attrsOf (oneOf [ (listOf (oneOf [ int str path ])) int str path ]);
type = with lib.types; attrsOf (nullOr (oneOf [ (listOf (oneOf [ int str path ])) int str path ]));
apply = let
toStr = v: if lib.isPath v then "${v}" else toString v;
in lib.mapAttrs (n: v: if lib.isList v then lib.concatMapStringsSep ":" toStr v else toStr v);
in attrs: lib.mapAttrs (n: v: if lib.isList v then lib.concatMapStringsSep ":" toStr v else toStr v) (lib.filterAttrs (n: v: v != null) attrs);
};
environment.profiles = lib.mkOption {
@@ -21,6 +21,9 @@ in
list of strings. The latter is concatenated, interspersed with
colon characters.
Setting a variable to `null` does nothing. You can override a
variable set by another module to `null` to unset it.
Note, due to limitations in the PAM format values may not
contain the `"` character.
+10 -2
View File
@@ -4,7 +4,7 @@ import ./make-test-python.nix ({ pkgs, ...} : {
maintainers = [ nequissimus ];
};
nodes.machine = { pkgs, ... }:
nodes.machine = { pkgs, lib, ... }: lib.mkMerge [
{
boot.kernelPackages = pkgs.linuxPackages;
environment.etc.plainFile.text = ''
@@ -17,8 +17,15 @@ import ./make-test-python.nix ({ pkgs, ...} : {
environment.sessionVariables = {
TERMINFO_DIRS = "/run/current-system/sw/share/terminfo";
NIXCON = "awesome";
SHOULD_NOT_BE_SET = "oops";
};
};
}
{
environment.sessionVariables = {
SHOULD_NOT_BE_SET = lib.mkForce null;
};
}
];
testScript = ''
machine.succeed('[ -L "/etc/plainFile" ]')
@@ -32,5 +39,6 @@ import ./make-test-python.nix ({ pkgs, ...} : {
"echo ''${TERMINFO_DIRS}"
)
assert "awesome" in machine.succeed("echo ''${NIXCON}")
machine.fail("printenv SHOULD_NOT_BE_SET")
'';
})