c10761b1eb
They have no @file imports, so the module concatenates the shared claude-md fragments into one AGENTS.md per tool (.pi/agent/ and .config/opencode/), and links commands/ into opencode's commands dir. Skills need nothing: pi reads ~/.agents/skills and opencode auto-loads both skill roots, all already linked.
109 lines
4.1 KiB
Nix
109 lines
4.1 KiB
Nix
# Home-manager module: link centralized agent skills into Claude Code, Codex,
|
|
# Pi and opencode. Usage: add this flake as an input, then import this module
|
|
# in your home config.
|
|
#
|
|
# inputs.agent-skills.url = "git+https://git.naps.pt/yolo/agent-skills.git";
|
|
# # in home.nix imports: inputs.agent-skills.homeModules.default
|
|
# # and pick a machine profile:
|
|
# programs.agentSkills.machine = "yolo";
|
|
#
|
|
# recursive=true links each FILE individually, so machine-local skills can still
|
|
# live alongside the managed ones in the same dir (a whole-dir symlink would not).
|
|
{ agent-skills }:
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.programs.agentSkills;
|
|
|
|
# Pi and opencode have no `@file` imports in context files, so the shared
|
|
# fragments are concatenated into one AGENTS.md per tool.
|
|
concatMd =
|
|
name: files:
|
|
pkgs.writeText name (lib.concatMapStringsSep "\n" builtins.readFile files);
|
|
in
|
|
{
|
|
options.programs.agentSkills.machine = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "default";
|
|
example = "yolo";
|
|
description = ''
|
|
Which claude-md/machines/<name>.md to link as ~/.claude/machine.md.
|
|
The shared entry file @imports it, so it always has to resolve; the
|
|
"default" profile is the conservative one (no passwordless root).
|
|
'';
|
|
};
|
|
|
|
config.home.file = {
|
|
".claude/skills" = {
|
|
source = "${agent-skills}/skills";
|
|
recursive = true;
|
|
};
|
|
".agents/skills" = {
|
|
source = "${agent-skills}/skills";
|
|
recursive = true;
|
|
};
|
|
".claude/commands" = {
|
|
source = "${agent-skills}/commands";
|
|
recursive = true;
|
|
};
|
|
".claude/hooks" = {
|
|
source = "${agent-skills}/hooks";
|
|
recursive = true;
|
|
};
|
|
# Referenced by hook commands in settings.json, which this module does not
|
|
# own — so these have to exist under the same path on every machine.
|
|
".claude/scripts" = {
|
|
source = "${agent-skills}/scripts";
|
|
recursive = true;
|
|
};
|
|
|
|
# CLAUDE.md fragments land in ~/.claude root, pulled in by `@name.md` imports.
|
|
# Listed one by one: recursive on ~/.claude would fight every other tool
|
|
# writing there (settings.json, projects/, file-history/).
|
|
".claude/writing.md".source = "${agent-skills}/claude-md/writing.md";
|
|
".claude/operating.md".source = "${agent-skills}/claude-md/operating.md";
|
|
|
|
# Per-machine section: what this box permits (sudo, network exposure).
|
|
".claude/machine.md".source = "${agent-skills}/claude-md/machines/${cfg.machine}.md";
|
|
|
|
# Path-scoped: loads only when Claude reads a matching source file.
|
|
".claude/rules/code-comments.md".source = "${agent-skills}/claude-md/code-comments.md";
|
|
".claude/RTK.md".source = "${agent-skills}/claude-md/RTK.md";
|
|
|
|
# Entry files: machine-local sections + @imports of the fragments above.
|
|
".claude/CLAUDE.md".source = "${agent-skills}/entry/CLAUDE.md";
|
|
".codex/AGENTS.md".source = "${agent-skills}/entry/codex-AGENTS.md";
|
|
|
|
# Pi: skills need no wiring — pi reads ~/.agents/skills, linked above.
|
|
# Settings stay unmanaged: pi writes ~/.pi/agent/settings.json itself.
|
|
".pi/agent/AGENTS.md".source = concatMd "pi-AGENTS.md" [
|
|
"${agent-skills}/claude-md/machines/${cfg.machine}.md"
|
|
"${agent-skills}/claude-md/operating.md"
|
|
"${agent-skills}/claude-md/writing.md"
|
|
"${agent-skills}/claude-md/code-comments.md"
|
|
"${agent-skills}/claude-md/RTK.md"
|
|
];
|
|
|
|
# opencode auto-loads skills from ~/.claude/skills and ~/.agents/skills,
|
|
# so only the rules file and commands need linking here.
|
|
".config/opencode/AGENTS.md".source = concatMd "opencode-AGENTS.md" [
|
|
"${agent-skills}/claude-md/opencode-header.md"
|
|
"${agent-skills}/claude-md/machines/${cfg.machine}.md"
|
|
"${agent-skills}/claude-md/operating.md"
|
|
"${agent-skills}/claude-md/writing.md"
|
|
"${agent-skills}/claude-md/code-comments.md"
|
|
"${agent-skills}/claude-md/RTK.md"
|
|
];
|
|
".config/opencode/commands" = {
|
|
source = "${agent-skills}/commands";
|
|
recursive = true;
|
|
};
|
|
};
|
|
}
|
|
# Hook wiring lives in ~/.claude/settings.json, which this module does not own.
|
|
# See hooks/README.md for the snippet.
|