CLI (add, remove, list, outdated, update, import) over a skills.json manifest and a skills.lock.json pinned with nix flake prefetch, plus a home-manager module that links each locked skill via builtins.fetchTree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
2.1 KiB
Nix
77 lines
2.1 KiB
Nix
self:
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.programs.skill-manager;
|
|
inherit (lib) mkOption types;
|
|
|
|
# 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
|
|
) (lib.importJSON cfg.lockFile).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.";
|
|
};
|
|
|
|
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
|
|
);
|
|
};
|
|
}
|