From 6ea30b26cdd22b9535620495e026aabed76daa16 Mon Sep 17 00:00:00 2001 From: Thierry Delafontaine Date: Sun, 19 Oct 2025 11:57:37 +0200 Subject: [PATCH] opencode: make the themes also accept path - Removed unnecessary empty-themes test. --- modules/programs/opencode.nix | 26 +++++++++++++------ tests/modules/programs/opencode/default.nix | 3 ++- .../programs/opencode/empty-themes.nix | 9 ------- .../{themes.nix => themes-inline.nix} | 0 .../modules/programs/opencode/themes-path.nix | 11 ++++++++ 5 files changed, 31 insertions(+), 18 deletions(-) delete mode 100644 tests/modules/programs/opencode/empty-themes.nix rename tests/modules/programs/opencode/{themes.nix => themes-inline.nix} (100%) create mode 100644 tests/modules/programs/opencode/themes-path.nix diff --git a/modules/programs/opencode.nix b/modules/programs/opencode.nix index 53b675aa6..538cff2a3 100644 --- a/modules/programs/opencode.nix +++ b/modules/programs/opencode.nix @@ -141,10 +141,13 @@ in }; themes = mkOption { - inherit (jsonFormat) type; + type = lib.types.attrsOf (lib.types.either jsonFormat.type lib.types.path); default = { }; description = '' - Custom themes for opencode. The attribute name becomes the theme filename. + Custom themes for opencode. The attribute name becomes the theme + filename, and the value is either: + - An attribute set, that is converted to a json + - A path to a file conaining the content Themes are stored in {file}`$XDG_CONFIG_HOME/opencode/themes/` directory. Set `programs.opencode.settings.theme` to enable the custom theme. See for the documentation. @@ -188,14 +191,21 @@ in ) cfg.agents // lib.mapAttrs' ( name: content: - lib.nameValuePair "opencode/themes/${name}.json" { - source = jsonFormat.generate "opencode-${name}.json" ( + lib.nameValuePair "opencode/themes/${name}.json" ( + if lib.isPath content then { - "$schema" = "https://opencode.ai/theme.json"; + source = content; } - // content - ); - } + else + { + source = jsonFormat.generate "opencode-${name}.json" ( + { + "$schema" = "https://opencode.ai/theme.json"; + } + // content + ); + } + ) ) cfg.themes; }; } diff --git a/tests/modules/programs/opencode/default.nix b/tests/modules/programs/opencode/default.nix index 48771b2a2..62d780d5d 100644 --- a/tests/modules/programs/opencode/default.nix +++ b/tests/modules/programs/opencode/default.nix @@ -9,5 +9,6 @@ opencode-agents-path = ./agents-path.nix; opencode-commands-path = ./commands-path.nix; opencode-mixed-content = ./mixed-content.nix; - opencode-themes = ./themes.nix; + opencode-themes-inline = ./themes-inline.nix; + opencode-themes-path = ./themes-path.nix; } diff --git a/tests/modules/programs/opencode/empty-themes.nix b/tests/modules/programs/opencode/empty-themes.nix deleted file mode 100644 index b436828af..000000000 --- a/tests/modules/programs/opencode/empty-themes.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - programs.opencode = { - enable = true; - themes = { }; - }; - nmt.script = '' - assertPathNotExists home-files/.config/opencode/themes - ''; -} diff --git a/tests/modules/programs/opencode/themes.nix b/tests/modules/programs/opencode/themes-inline.nix similarity index 100% rename from tests/modules/programs/opencode/themes.nix rename to tests/modules/programs/opencode/themes-inline.nix diff --git a/tests/modules/programs/opencode/themes-path.nix b/tests/modules/programs/opencode/themes-path.nix new file mode 100644 index 000000000..937571c9c --- /dev/null +++ b/tests/modules/programs/opencode/themes-path.nix @@ -0,0 +1,11 @@ +{ + nmt.script = '' + assertFileExists home-files/.config/opencode/themes/my-theme.json + assertFileContent home-files/.config/opencode/themes/my-theme.json \ + ${./my-theme.json} + ''; + programs.opencode = { + enable = true; + themes.my-theme = ./my-theme.json; + }; +}