diff --git a/modules/programs/halloy.nix b/modules/programs/halloy.nix index 4ea21ebbf..cce655748 100644 --- a/modules/programs/halloy.nix +++ b/modules/programs/halloy.nix @@ -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: . ''; }; + themes = mkOption { + type = types.attrsOf ( + types.oneOf [ + tomlFormat.type + types.lines + types.path + ] + ); + default = { }; + example = { + general = { + background = ""; + border = ""; + horizontal_rule = ""; + unread_indicator = ""; + }; + text = { + primary = ""; + secondary = ""; + tertiary = ""; + success = ""; + error = ""; + }; + }; + description = '' + Each theme is written to {file}`$XDG_CONFIG_HOME/halloy/themes/NAME.toml`. + See 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) + ]; }; } diff --git a/tests/modules/programs/halloy/example-config.nix b/tests/modules/programs/halloy/example-config.nix index 1bd90548a..6580c59ee 100644 --- a/tests/modules/programs/halloy/example-config.nix +++ b/tests/modules/programs/halloy/example-config.nix @@ -9,11 +9,29 @@ channels = [ "#halloy" ]; }; }; + themes.my-theme = { + general = { + background = ""; + border = ""; + horizontal_rule = ""; + unread_indicator = ""; + }; + text = { + primary = ""; + secondary = ""; + tertiary = ""; + success = ""; + error = ""; + }; + }; }; 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} ''; } diff --git a/tests/modules/programs/halloy/my-theme.toml b/tests/modules/programs/halloy/my-theme.toml new file mode 100644 index 000000000..88f1d431f --- /dev/null +++ b/tests/modules/programs/halloy/my-theme.toml @@ -0,0 +1,12 @@ +[general] +background = "" +border = "" +horizontal_rule = "" +unread_indicator = "" + +[text] +error = "" +primary = "" +secondary = "" +success = "" +tertiary = ""