wrapper-manager-fds/modules: add global pathAdd and env variables

This commit is contained in:
Gabriel Arazas 2024-07-30 11:08:24 +08:00
parent 6b7b2ee9cd
commit b2c33db951
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360

View File

@ -1,13 +1,9 @@
{ config, lib, ... }: { config, lib, options, ... }:
let let
envConfig = config; envConfig = config;
wrapperType = { name, lib, config, pkgs, ... }:
let
toStringType = with lib.types; coercedTo anything (x: builtins.toString x) str; toStringType = with lib.types; coercedTo anything (x: builtins.toString x) str;
flagType = with lib.types; listOf toStringType;
envSubmodule = { config, lib, name, ... }: { envSubmodule = { config, lib, name, ... }: {
options = { options = {
action = lib.mkOption { action = lib.mkOption {
@ -37,6 +33,10 @@ let
}; };
}; };
}; };
wrapperType = { name, lib, config, pkgs, ... }:
let
flagType = with lib.types; listOf toStringType;
in in
{ {
options = { options = {
@ -84,36 +84,8 @@ let
example = "custom-name"; example = "custom-name";
}; };
env = lib.mkOption { env = options.environment.variables;
type = with lib.types; attrsOf (submodule envSubmodule); pathAdd = options.environment.pathAdd;
description = ''
A set of environment variables to be declared in the wrapper
script.
'';
default = { };
example = {
"FOO_TYPE".value = "custom";
"FOO_LOG_STYLE" = {
action = "set-default";
value = "systemd";
};
"USELESS_VAR".action = "unset";
};
};
pathAdd = lib.mkOption {
type = with lib.types; listOf path;
description = ''
A list of paths to be added as part of the `PATH` environment variable.
'';
default = [ ];
example = lib.literalExpression ''
wrapperManagerLib.getBin (with pkgs; [
yt-dlp
gallery-dl
])
'';
};
preScript = lib.mkOption { preScript = lib.mkOption {
type = lib.types.lines; type = lib.types.lines;
@ -143,6 +115,9 @@ let
config = lib.mkMerge [ config = lib.mkMerge [
{ {
env = envConfig.environment.variables;
pathAdd = envConfig.environment.pathAdd;
makeWrapperArgs = [ makeWrapperArgs = [
"--argv0" config.arg0 "--argv0" config.arg0
] ]
@ -164,9 +139,7 @@ let
(lib.mkIf (config.pathAdd != [ ]) { (lib.mkIf (config.pathAdd != [ ]) {
env.PATH.value = lib.concatStringsSep ":" config.pathAdd; env.PATH.value = lib.concatStringsSep ":" config.pathAdd;
}) })
]; ];
}; };
in in
@ -208,5 +181,37 @@ in
] ]
''; '';
}; };
environment.variables = lib.mkOption {
type = with lib.types; attrsOf (submodule envSubmodule);
description = ''
A global set of environment variables and their actions to be applied
per-wrapper.
'';
default = { };
example = {
"FOO_TYPE".value = "custom";
"FOO_LOG_STYLE" = {
action = "set-default";
value = "systemd";
};
"USELESS_VAR".action = "unset";
};
};
environment.pathAdd = lib.mkOption {
type = with lib.types; listOf path;
description = ''
A global list of paths to be added per-wrapper as part of the `PATH`
environment variable.
'';
default = [ ];
example = lib.literalExpression ''
wrapperManagerLib.getBin (with pkgs; [
yt-dlp
gallery-dl
])
'';
};
}; };
} }