Files
skm/nix/module.nix
T
johannesandClaude Sonnet 5.5 df8d11d8cb feat: pin agent definitions next to skills
A source can install agents (agents/<name>.md files with a frontmatter
name) alongside or instead of skills.

- manifest: optional "agents" selection; lock: "agents" map
- add --agent / --all-agents, remove --agent, list shows the kind
- check/update diff agents like skills (files, not directories)
- dashboard lists and removes agents
- home-manager module: agentTargets (default .claude/agents) links <name>.md

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-28 13:42:45 +01:00

98 lines
2.8 KiB
Nix

self:
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.skill-manager;
inherit (lib) mkOption types;
sources = (lib.importJSON cfg.lockFile).sources;
# installed name -> store path of the skill directory
skills = lib.concatMapAttrs (
_: src:
let
tree = builtins.fetchTree src.locked;
in
lib.mapAttrs (_: path: if path == "." then "${tree}" else "${tree}/${path}") src.skills
) sources;
# installed name -> store path of the agent definition (a .md file)
agents = lib.concatMapAttrs (
_: src:
let
tree = builtins.fetchTree src.locked;
in
lib.mapAttrs (_: path: "${tree}/${path}") (src.agents or { })
) sources;
in
{
options.programs.skill-manager = {
enable = lib.mkEnableOption "skm and the skills pinned in its lock file";
package = mkOption {
type = types.package;
default = self.packages.${pkgs.stdenv.hostPlatform.system}.skm;
defaultText = lib.literalExpression "skill-manager.packages.\${system}.skm";
};
manifestDir = mkOption {
type = types.str;
example = "/home/me/Repos/nix/home/agents";
description = "Working-tree directory holding skills.json and skills.lock.json. skm writes here.";
};
lockFile = mkOption {
type = types.path;
example = lib.literalExpression "./home/agents/skills.lock.json";
description = ''
skills.lock.json as a path inside your flake, read at evaluation time.
Same file as in manifestDir; pure evaluation can't read manifestDir directly.
'';
};
targets = mkOption {
type = types.listOf types.str;
default = [
".claude/skills"
".agents/skills"
];
description = "Directories, relative to home, that get one symlink per skill.";
};
agentTargets = mkOption {
type = types.listOf types.str;
default = [ ".claude/agents" ];
description = "Directories, relative to home, that get one <name>.md symlink per agent definition.";
};
switchCommand = mkOption {
type = types.str;
default = "";
example = "cd ~/Repos/nix && devenv shell rebuild";
description = "Shell command `skm update --switch` runs to apply a new lock.";
};
};
config = lib.mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg.configFile."skill-manager/config.json".text = builtins.toJSON {
inherit (cfg) manifestDir switchCommand;
};
home.file = lib.listToAttrs (
lib.concatMap (
target: lib.mapAttrsToList (name: source: lib.nameValuePair "${target}/${name}" { inherit source; }) skills
) cfg.targets
++ lib.concatMap (
target:
lib.mapAttrsToList (name: source: lib.nameValuePair "${target}/${name}.md" { inherit source; }) agents
) cfg.agentTargets
);
};
}