From 52e84a040e2db9a78267a7e30576cfb472d15fa4 Mon Sep 17 00:00:00 2001 From: Gabriel Fontes Date: Thu, 30 Sep 2021 00:56:05 -0300 Subject: [PATCH] xsettingsd: make configurable through module --- modules/services/xsettingsd.nix | 46 ++++++++++++++++++- tests/default.nix | 1 + .../xsettingsd/basic-configuration.conf | 4 ++ .../xsettingsd/basic-configuration.nix | 26 +++++++++++ tests/modules/services/xsettingsd/default.nix | 1 + 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 tests/modules/services/xsettingsd/basic-configuration.conf create mode 100644 tests/modules/services/xsettingsd/basic-configuration.nix create mode 100644 tests/modules/services/xsettingsd/default.nix diff --git a/modules/services/xsettingsd.nix b/modules/services/xsettingsd.nix index 86336b21..56d83f92 100644 --- a/modules/services/xsettingsd.nix +++ b/modules/services/xsettingsd.nix @@ -6,6 +6,20 @@ let cfg = config.services.xsettingsd; + renderSettings = settings: + concatStrings (mapAttrsToList renderSetting settings); + + renderSetting = key: value: '' + ${key} ${renderValue value} + ''; + + renderValue = value: + { + int = toString value; + bool = if value then "1" else "0"; + string = ''"${value}"''; + }.${builtins.typeOf value}; + in { meta.maintainers = [ maintainers.imalison ]; @@ -21,6 +35,34 @@ in { Package containing the xsettingsd program. ''; }; + + settings = mkOption { + type = with types; attrsOf (oneOf [ bool int str ]); + default = { }; + example = literalExample '' + { + "Net/ThemeName" = "Numix"; + "Xft/Antialias" = true; + "Xft/Hinting" = true; + "Xft/RGBA" = "rgb"; + } + ''; + description = '' + Xsettingsd options for configuration file. See + + for documentation on these values. + ''; + }; + + configFile = mkOption { + type = types.nullOr types.package; + internal = true; + readOnly = true; + default = if cfg.settings == { } then + null + else + pkgs.writeText "xsettingsd.conf" (renderSettings cfg.settings); + }; }; }; @@ -41,7 +83,9 @@ in { Service = { Environment = "PATH=${config.home.profileDirectory}/bin"; - ExecStart = "${cfg.package}/bin/xsettingsd"; + ExecStart = "${cfg.package}/bin/xsettingsd" + + optionalString (cfg.configFile != null) + " -c ${escapeShellArg cfg.configFile}"; Restart = "on-abort"; }; }; diff --git a/tests/default.nix b/tests/default.nix index a6daa4c0..cf51d4aa 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -139,6 +139,7 @@ import nmt { ./modules/services/window-managers/i3 ./modules/services/window-managers/sway ./modules/services/wlsunset + ./modules/services/xsettingsd ./modules/systemd ./modules/targets-linux ] ++ lib.optionals enableBig [ diff --git a/tests/modules/services/xsettingsd/basic-configuration.conf b/tests/modules/services/xsettingsd/basic-configuration.conf new file mode 100644 index 00000000..4e502c98 --- /dev/null +++ b/tests/modules/services/xsettingsd/basic-configuration.conf @@ -0,0 +1,4 @@ +Net/ThemeName "Numix" +Xft/Antialias 1 +Xft/Hinting 1 +Xft/RGBA "rgb" diff --git a/tests/modules/services/xsettingsd/basic-configuration.nix b/tests/modules/services/xsettingsd/basic-configuration.nix new file mode 100644 index 00000000..8ea2ec78 --- /dev/null +++ b/tests/modules/services/xsettingsd/basic-configuration.nix @@ -0,0 +1,26 @@ +{ config, pkgs, ... }: + +{ + config = { + services.xsettingsd = { + enable = true; + package = config.lib.test.mkStubPackage { }; + settings = { + "Net/ThemeName" = "Numix"; + "Xft/Antialias" = true; + "Xft/Hinting" = true; + "Xft/RGBA" = "rgb"; + }; + }; + nmt.script = '' + serviceFile=home-files/.config/systemd/user/xsettingsd.service + + assertFileExists $serviceFile + assertFileRegex $serviceFile 'ExecStart=.*/bin/xsettingsd.*' + + assertFileExists ${config.services.xsettingsd.configFile} + assertFileContent ${config.services.xsettingsd.configFile} \ + ${./basic-configuration.conf} + ''; + }; +} diff --git a/tests/modules/services/xsettingsd/default.nix b/tests/modules/services/xsettingsd/default.nix new file mode 100644 index 00000000..98c99f4c --- /dev/null +++ b/tests/modules/services/xsettingsd/default.nix @@ -0,0 +1 @@ +{ xsettingsd-basic-configuration = ./basic-configuration.nix; }