opencode: handle string store paths in skill sources

Add support for store directory paths provided as strings, in addition
to the existing path type check for directories.
Context: certain project will include a `SKILL.md` file, and instead of
managing them via some 3rd party manager or manually, why not include
them from the source itself! I implemented this in my setup, since I
wanted to include the `SKILL.md` file from the
[beads](https://github.com/steveyegge/beads) project.
This commit is contained in:
Mirza Arnaut 2026-01-25 01:01:32 +01:00 committed by Austin Horstman
parent db9cf9232f
commit 63ecc7d495
3 changed files with 43 additions and 2 deletions

View file

@ -230,7 +230,13 @@ in
};
skills = lib.mkOption {
type = lib.types.either (lib.types.attrsOf (lib.types.either lib.types.lines lib.types.path)) lib.types.path;
type = lib.types.either (lib.types.attrsOf (
lib.types.oneOf [
lib.types.lines
lib.types.path
lib.types.str
]
)) lib.types.path;
default = { };
description = ''
Custom agent skills for opencode.
@ -245,6 +251,9 @@ in
- A path to a file (creates `opencode/skill/<name>/SKILL.md`)
- A path to a directory (creates `opencode/skill/<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.
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/skill/`.
@ -268,6 +277,9 @@ in
# A skill can also be a directory containing SKILL.md and other files.
data-analysis = ./skills/data-analysis;
# A skill can also be a subdirectory within a package source (store path)
beads = "''${pkgs.beads.src}/claude-plugin/skills/beads";
}
'';
};
@ -443,7 +455,11 @@ in
)
// lib.mapAttrs' (
name: content:
if lib.isPath content && lib.pathIsDirectory content then
if
(lib.isPath content && lib.pathIsDirectory content)
|| (builtins.isString content && lib.hasPrefix builtins.storeDir content)
then
lib.nameValuePair "opencode/skill/${name}" {
source = content;
recursive = true;