opencode: make the rules option also accept a path

This commit is contained in:
Thierry Delafontaine 2025-10-19 11:48:32 +02:00 committed by Austin Horstman
parent c199de6cd8
commit fddb33a1a5
4 changed files with 29 additions and 9 deletions

View file

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