xsettingsd: make configurable through module

This commit is contained in:
Gabriel Fontes 2021-09-30 00:56:05 -03:00 committed by Robert Helgesson
parent 959217e51d
commit 52e84a040e
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
5 changed files with 77 additions and 1 deletions

View file

@ -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 <command>xsettingsd</command> 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
<link xlink:href="https://github.com/derat/xsettingsd/wiki/Settings"/>
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";
};
};

View file

@ -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 [

View file

@ -0,0 +1,4 @@
Net/ThemeName "Numix"
Xft/Antialias 1
Xft/Hinting 1
Xft/RGBA "rgb"

View file

@ -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}
'';
};
}

View file

@ -0,0 +1 @@
{ xsettingsd-basic-configuration = ./basic-configuration.nix; }