diff --git a/modules/programs/opencode.nix b/modules/programs/opencode.nix index c8855dfe6..53b675aa6 100644 --- a/modules/programs/opencode.nix +++ b/modules/programs/opencode.nix @@ -45,8 +45,15 @@ in }; rules = lib.mkOption { - type = lib.types.lines; + type = lib.types.either lib.types.lines lib.types.path; default = ""; + description = '' + You can provide global custom instructions to opencode. + The value is either: + - Inline content as a string + - A path to a file containing the content + This value is written to {file}`$XDG_CONFIG_HOME/opencode/AGENTS.md`. + ''; example = lib.literalExpression '' ''' # TypeScript Project Rules @@ -73,10 +80,6 @@ in Read the following file immediately as it's relevant to all workflows: @rules/general-guidelines.md. ''' ''; - description = '' - You can provide global custom instructions to opencode; this value is - written to {file}`$XDG_CONFIG_HOME/opencode/AGENTS.md`. - ''; }; commands = lib.mkOption { @@ -162,9 +165,14 @@ in ); }; - "opencode/AGENTS.md" = mkIf (cfg.rules != "") { - text = cfg.rules; - }; + "opencode/AGENTS.md" = ( + if lib.isPath cfg.rules then + { source = cfg.rules; } + else + (mkIf (cfg.rules != "") { + text = cfg.rules; + }) + ); } // lib.mapAttrs' ( name: content: diff --git a/tests/modules/programs/opencode/default.nix b/tests/modules/programs/opencode/default.nix index 22188c670..48771b2a2 100644 --- a/tests/modules/programs/opencode/default.nix +++ b/tests/modules/programs/opencode/default.nix @@ -1,7 +1,8 @@ { opencode-settings = ./settings.nix; opencode-empty-settings = ./empty-settings.nix; - opencode-rules = ./rules.nix; + opencode-rules-inline = ./rules-inline.nix; + opencode-rules-path = ./rules-path.nix; opencode-empty-rules = ./empty-rules.nix; opencode-agents-inline = ./agents-inline.nix; opencode-commands-inline = ./commands-inline.nix; diff --git a/tests/modules/programs/opencode/rules.nix b/tests/modules/programs/opencode/rules-inline.nix similarity index 100% rename from tests/modules/programs/opencode/rules.nix rename to tests/modules/programs/opencode/rules-inline.nix diff --git a/tests/modules/programs/opencode/rules-path.nix b/tests/modules/programs/opencode/rules-path.nix new file mode 100644 index 000000000..7a4a93a22 --- /dev/null +++ b/tests/modules/programs/opencode/rules-path.nix @@ -0,0 +1,11 @@ +{ + programs.opencode = { + enable = true; + rules = ./AGENTS.md; + }; + nmt.script = '' + assertFileExists home-files/.config/opencode/AGENTS.md + assertFileContent home-files/.config/opencode/AGENTS.md \ + ${./AGENTS.md} + ''; +}