wrapper-manager-fds/modules: restructure env option

Now we have solved the problem of requiring separate options by
consolidating them together. This shouldn't be that breaking of a
change.
This commit is contained in:
Gabriel Arazas 2024-07-27 21:17:01 +08:00
parent 12686f3bad
commit dd389a65ec
4 changed files with 40 additions and 18 deletions

View File

@ -7,6 +7,32 @@ let
let
toStringType = with lib.types; coercedTo anything (x: builtins.toString x) str;
flagType = with lib.types; listOf toStringType;
envSubmodule = { config, lib, name, ... }: {
options = {
action = lib.mkOption {
type = lib.types.enum [ "unset" "set" "set-default" ];
description = ''
Sets the appropriate action for the environment variable.
* `unset`... unsets the given variable.
* `set-default` only sets the variable with the given value if
not already set.
* `set` forcibly sets the variable with given value.
'';
default = "set";
example = "unset";
};
value = lib.mkOption {
type = toStringType;
description = ''
The value of the variable that is holding.
'';
example = "HELLO THERE";
};
};
};
in
{
options = {
@ -56,9 +82,10 @@ let
};
env = lib.mkOption {
type = with lib.types; attrsOf toStringType;
type = with lib.types; attrsOf (submodule envSubmodule);
description = ''
A set of environment variables to be declared in the wrapper script.
A set of environment variables to be declared in the wrapper
script.
'';
default = { };
example = {
@ -67,15 +94,6 @@ let
};
};
unset = lib.mkOption {
type = with lib.types; listOf nonEmptyStr;
description = ''
A list of environment variables to be unset into the wrapper script.
'';
default = [ ];
example = [ "NO_COLOR" ];
};
pathAdd = lib.mkOption {
type = with lib.types; listOf path;
description = ''
@ -121,8 +139,12 @@ let
makeWrapperArgs = [
"--argv0" config.arg0
]
++ (builtins.map (v: "--unset ${lib.escapeShellArg v}") config.unset)
++ (lib.mapAttrsToList (n: v: "--set ${lib.escapeShellArg n} ${lib.escapeShellArg v}") config.env)
++ (lib.mapAttrsToList
(n: v:
if v.action == "unset"
then "--${v.action} ${lib.escapeShellArg n}"
else "--${v.action} ${lib.escapeShellArg n} ${lib.escapeShellArg v.value}")
config.env)
++ (builtins.map (v: "--add-flags ${lib.escapeShellArg v}") config.prependArgs)
++ (builtins.map (v: "--append-flags ${lib.escapeShellArg v}") config.appendArgs)
++ (lib.optionals (!envConfig.build.isBinary && config.preScript != "") (
@ -134,7 +156,7 @@ let
}
(lib.mkIf (config.pathAdd != [ ]) {
env.PATH = lib.concatStringsSep ":" config.pathAdd;
env.PATH.value = lib.concatStringsSep ":" config.pathAdd;
})

View File

@ -39,7 +39,7 @@ in
options.locale = localeModuleFactory { isGlobal = false; };
config = lib.mkIf submoduleCfg.enable {
env.LOCALE_ARCHIVE = "${submoduleCfg.package}/lib/locale/locale-archive";
env.LOCALE_ARCHIVE.value = "${submoduleCfg.package}/lib/locale/locale-archive";
};
};
in

View File

@ -52,11 +52,11 @@ in
}
(lib.mkIf (config.xdg.configDirs != [ ]) {
env.XDG_CONFIG_DIRS = lib.concatStringsSep ":" config.xdg.configDirs;
env.XDG_CONFIG_DIRS.value = lib.concatStringsSep ":" config.xdg.configDirs;
})
(lib.mkIf (config.xdg.dataDirs != [ ]) {
env.XDG_DATA_DIRS = lib.concatStringsSep ":" config.xdg.dataDirs;
env.XDG_DATA_DIRS.value = lib.concatStringsSep ":" config.xdg.dataDirs;
})
];
};

View File

@ -4,7 +4,7 @@
wrappers.fastfetch = {
arg0 = lib.getExe' pkgs.fastfetch "fastfetch";
appendArgs = [ "--logo" "Guix" ];
env.NO_COLOR = "1";
env.NO_COLOR.value = "1";
xdg.desktopEntry.enable = true;
};