From 534ea2e7c382e4fd4936711c055ef79a3065c260 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 27 Jul 2024 21:17:01 +0800 Subject: [PATCH] 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. --- .../modules/wrapper-manager/base.nix | 50 +++++++++++++------ .../modules/wrapper-manager/locale.nix | 2 +- .../modules/wrapper-manager/xdg-dirs.nix | 4 +- .../tests/configs/wrapper-fastfetch.nix | 2 +- 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix b/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix index 95ef7957..e8c8b79e 100644 --- a/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix +++ b/subprojects/wrapper-manager-fds/modules/wrapper-manager/base.nix @@ -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; }) diff --git a/subprojects/wrapper-manager-fds/modules/wrapper-manager/locale.nix b/subprojects/wrapper-manager-fds/modules/wrapper-manager/locale.nix index 41a3ef5e..470705d8 100644 --- a/subprojects/wrapper-manager-fds/modules/wrapper-manager/locale.nix +++ b/subprojects/wrapper-manager-fds/modules/wrapper-manager/locale.nix @@ -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 diff --git a/subprojects/wrapper-manager-fds/modules/wrapper-manager/xdg-dirs.nix b/subprojects/wrapper-manager-fds/modules/wrapper-manager/xdg-dirs.nix index ff448ea9..5209273d 100644 --- a/subprojects/wrapper-manager-fds/modules/wrapper-manager/xdg-dirs.nix +++ b/subprojects/wrapper-manager-fds/modules/wrapper-manager/xdg-dirs.nix @@ -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; }) ]; }; diff --git a/subprojects/wrapper-manager-fds/tests/configs/wrapper-fastfetch.nix b/subprojects/wrapper-manager-fds/tests/configs/wrapper-fastfetch.nix index 262c54a2..239e9798 100644 --- a/subprojects/wrapper-manager-fds/tests/configs/wrapper-fastfetch.nix +++ b/subprojects/wrapper-manager-fds/tests/configs/wrapper-fastfetch.nix @@ -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; };