halloy: add themes option (#7043)

This commit is contained in:
awwpotato
2025-05-12 11:08:49 -07:00
committed by GitHub
parent 5879531462
commit 0b24658ec0
3 changed files with 82 additions and 6 deletions

View File

@@ -10,11 +10,12 @@ let
mkEnableOption
mkPackageOption
mkOption
types
;
cfg = config.programs.halloy;
formatter = pkgs.formats.toml { };
tomlFormat = pkgs.formats.toml { };
in
{
meta.maintainers = with lib.hm.maintainers; [ aguirre-matteo ];
@@ -23,7 +24,7 @@ in
enable = mkEnableOption "halloy";
package = mkPackageOption pkgs "halloy" { nullable = true; };
settings = mkOption {
type = formatter.type;
inherit (tomlFormat) type;
default = { };
example = {
"buffer.channel.topic".enabled = true;
@@ -38,12 +39,57 @@ in
found here: <https://halloy.chat/configuration/index.html>.
'';
};
themes = mkOption {
type = types.attrsOf (
types.oneOf [
tomlFormat.type
types.lines
types.path
]
);
default = { };
example = {
general = {
background = "<string>";
border = "<string>";
horizontal_rule = "<string>";
unread_indicator = "<string>";
};
text = {
primary = "<string>";
secondary = "<string>";
tertiary = "<string>";
success = "<string>";
error = "<string>";
};
};
description = ''
Each theme is written to {file}`$XDG_CONFIG_HOME/halloy/themes/NAME.toml`.
See <https://halloy.chat/configuration/themes/index.html> for more information.
'';
};
};
config = mkIf cfg.enable {
home.packages = mkIf (cfg.package != null) [ cfg.package ];
xdg.configFile."halloy/config.toml" = mkIf (cfg.settings != { }) {
source = formatter.generate "halloy-config" cfg.settings;
};
xdg.configFile = lib.mkMerge [
{
"halloy/config.toml" = mkIf (cfg.settings != { }) {
source = tomlFormat.generate "halloy-config" cfg.settings;
};
}
(lib.mapAttrs' (
name: value:
lib.nameValuePair "halloy/themes/${name}.toml" {
source =
if lib.isString value then
pkgs.writeText "halloy-theme-${name}" value
else if builtins.isPath value || lib.isStorePath value then
value
else
tomlFormat.generate "halloy-theme-${name}" value;
}
) cfg.themes)
];
};
}

View File

@@ -9,11 +9,29 @@
channels = [ "#halloy" ];
};
};
themes.my-theme = {
general = {
background = "<string>";
border = "<string>";
horizontal_rule = "<string>";
unread_indicator = "<string>";
};
text = {
primary = "<string>";
secondary = "<string>";
tertiary = "<string>";
success = "<string>";
error = "<string>";
};
};
};
nmt.script = ''
assertFileExists home-files/.config/halloy/config.toml
assertFileContent home-files/.config/halloy/config.toml \
${./example-config.toml}
${./example-config.toml}
assertFileExists home-files/.config/halloy/themes/my-theme.toml
assertFileContent home-files/.config/halloy/themes/my-theme.toml \
${./my-theme.toml}
'';
}

View File

@@ -0,0 +1,12 @@
[general]
background = "<string>"
border = "<string>"
horizontal_rule = "<string>"
unread_indicator = "<string>"
[text]
error = "<string>"
primary = "<string>"
secondary = "<string>"
success = "<string>"
tertiary = "<string>"