1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-12-11 11:31:06 +01:00

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 != "") {
"opencode/AGENTS.md" = (
if lib.isPath cfg.rules then
{ source = cfg.rules; }
else
(mkIf (cfg.rules != "") {
text = cfg.rules;
};
})
);
}
// lib.mapAttrs' (
name: content:

View file

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

View file

@ -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}
'';
}