opencode: migrate rules to context

This commit is contained in:
Vinicius Deolindo 2026-04-08 11:43:58 -03:00 committed by Austin Horstman
parent 447796d64a
commit d6d2468b88
6 changed files with 52 additions and 26 deletions

View file

@ -50,6 +50,10 @@ in
{
meta.maintainers = with lib.maintainers; [ delafthi ];
imports = [
(lib.mkRenamedOptionModule [ "programs" "opencode" "rules" ] [ "programs" "opencode" "context" ])
];
options.programs.opencode = {
enable = mkEnableOption "opencode";
@ -156,15 +160,18 @@ in
};
};
rules = lib.mkOption {
context = lib.mkOption {
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`.
Global context for OpenCode.
The value is either:
- Inline content as a string
- A path to a file containing the content
The configured content is written to
{file}`$XDG_CONFIG_HOME/opencode/AGENTS.md`.
'';
example = lib.literalExpression ''
'''
@ -278,24 +285,24 @@ in
)) lib.types.path;
default = { };
description = ''
Custom agent skills for opencode.
Custom skills for OpenCode.
This option can either be:
This option can be either:
- An attribute set defining skills
- A path to a directory containing multiple skill folders
- A path to a directory containing skill folders
If an attribute set is used, the attribute name becomes the skill directory name,
and the value is either:
If an attribute set is used, the attribute name becomes the
skill directory name, and the value is either:
- Inline content as a string (creates `opencode/skills/<name>/SKILL.md`)
- A path to a file (creates `opencode/skills/<name>/SKILL.md`)
- A path to a directory (creates `opencode/skills/<name>/` with all files)
This also accepts Nix store paths (e.g., source from a package), allowing you to
reference subdirectories within a package source.
This also accepts Nix store paths, for example a skill directory
from a package.
If a path is used, it is expected to contain one folder per skill name, each
containing a {file}`SKILL.md`. The directory is symlinked to
{file}`$XDG_CONFIG_HOME/opencode/skills/`.
If a path is used, it is expected to contain one folder per
skill name, each containing a {file}`SKILL.md`. The directory is
symlinked to {file}`$XDG_CONFIG_HOME/opencode/skills/`.
See <https://opencode.ai/docs/skills/> for the documentation.
'';
@ -469,11 +476,11 @@ in
};
"opencode/AGENTS.md" = (
if lib.isPath cfg.rules then
{ source = cfg.rules; }
if lib.isPath cfg.context then
{ source = cfg.context; }
else
(mkIf (cfg.rules != "") {
text = cfg.rules;
(mkIf (cfg.context != "") {
text = cfg.context;
})
);

View file

@ -1,9 +1,9 @@
{
opencode-settings = ./settings.nix;
opencode-empty-settings = ./empty-settings.nix;
opencode-rules-inline = ./rules-inline.nix;
opencode-rules-path = ./rules-path.nix;
opencode-empty-rules = ./empty-rules.nix;
opencode-context-inline = ./rules-inline.nix;
opencode-context-path = ./rules-path.nix;
opencode-empty-context = ./empty-rules.nix;
opencode-agents-inline = ./agents-inline.nix;
opencode-commands-inline = ./commands-inline.nix;
opencode-agents-path = ./agents-path.nix;
@ -22,6 +22,7 @@
opencode-themes-inline = ./themes-inline.nix;
opencode-themes-path = ./themes-path.nix;
opencode-themes-bulk-directory = ./themes-bulk-directory.nix;
opencode-legacy-rules = ./legacy-rules.nix;
opencode-mcp-integration = ./mcp-integration.nix;
opencode-mcp-integration-with-override = ./mcp-integration-with-override.nix;
opencode-web-service = ./web-service.nix;

View file

@ -1,7 +1,7 @@
{
programs.opencode = {
enable = true;
rules = "";
context = "";
};
nmt.script = ''
assertPathNotExists home-files/.config/opencode/AGENTS.md

View file

@ -0,0 +1,18 @@
{ lib, options, ... }:
{
programs.opencode = {
enable = true;
rules = ./AGENTS.md;
};
test.asserts.warnings.expected = [
"The option `programs.opencode.rules' defined in ${lib.showFiles options.programs.opencode.rules.files} has been renamed to `programs.opencode.context'."
];
nmt.script = ''
assertFileExists home-files/.config/opencode/AGENTS.md
assertFileContent home-files/.config/opencode/AGENTS.md \
${./AGENTS.md}
'';
}

View file

@ -1,7 +1,7 @@
{
programs.opencode = {
enable = true;
rules = ''
context = ''
# TypeScript Project Rules
## External File Loading

View file

@ -1,7 +1,7 @@
{
programs.opencode = {
enable = true;
rules = ./AGENTS.md;
context = ./AGENTS.md;
};
nmt.script = ''
assertFileExists home-files/.config/opencode/AGENTS.md