cc: extract hm odule

This commit is contained in:
Sridhar Ratnakumar 2025-11-10 20:10:05 -05:00
parent 35bd34a271
commit 9a64b12e32
3 changed files with 154 additions and 77 deletions

View file

@ -1,71 +1,15 @@
{ flake, pkgs, lib, ... }:
let
claudeCodeDir = flake.inputs.self + /claude-code;
subagentsDir = claudeCodeDir + "/subagents";
agents = lib.mapAttrs'
(fileName: _:
lib.nameValuePair
(lib.removeSuffix ".md" fileName)
(builtins.readFile (subagentsDir + "/${fileName}"))
)
(builtins.readDir subagentsDir);
commandsDir = claudeCodeDir + "/commands";
commands = lib.mapAttrs'
(fileName: _:
lib.nameValuePair
(lib.removeSuffix ".md" fileName)
(builtins.readFile (commandsDir + "/${fileName}"))
)
(builtins.readDir commandsDir);
skillsDir = claudeCodeDir + "/skills";
skillDirs = lib.filterAttrs (_: type: type == "directory") (builtins.readDir skillsDir);
# Process skill: if it has default.nix, build and substitute; otherwise use as-is
processSkill = skillName:
let
skillPath = skillsDir + "/${skillName}";
hasDefaultNix = builtins.pathExists (skillPath + "/default.nix");
in
if hasDefaultNix then
let
skillPkg = pkgs.callPackage skillPath { };
in
pkgs.runCommand "${skillName}-skill" { } ''
mkdir -p $out
substitute ${skillPath}/SKILL.md $out/SKILL.md \
--replace-fail '@${skillName}@' '${skillPkg}/bin/${skillName}'
''
else
skillPath;
mcpDir = claudeCodeDir + "/mcp";
mcpServers = lib.mapAttrs'
(fileName: _:
lib.nameValuePair
(lib.removeSuffix ".nix" fileName)
(import (mcpDir + "/${fileName}"))
)
(builtins.readDir mcpDir);
in
{ flake, pkgs, ... }:
{
# Packages often used by Claude Code CLI.
# Import the general home-manager module
imports = [
../../../claude-code/nix/home-manager-module.nix
];
# Packages often used by Claude Code CLI
home.packages = with pkgs; [
tree
];
# Link skill directories to ~/.claude/skills/
# (home-manager module doesn't support skills yet, so we link manually)
home.file = lib.mapAttrs'
(skillName: _:
lib.nameValuePair ".claude/skills/${skillName}" {
source = processSkill skillName;
recursive = true;
}
)
skillDirs;
programs.claude-code = {
enable = true;
@ -75,19 +19,7 @@ in
then flake.inputs.self.packages.${pkgs.system}.claude # see claude-sandboxed.nix
else pkgs.claude-code;
# Basic settings for Claude Code
settings = import (claudeCodeDir + "/settings.nix");
# System prompt / memory
memory.text = builtins.readFile (claudeCodeDir + "/memory.md");
# Automatically discovered commands from commands/ directory
commands = commands;
# Automatically discovered agents from subagents/ directory
agents = agents;
# Automatically discovered MCP servers from mcp/ directory
mcpServers = mcpServers;
# Set the claude-code directory for auto-wiring
autoWire.dir = ../../../claude-code;
};
}