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 .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 ); }; }