- Renamed shared-options.nix to shared/shared-options.nix - Created shared/default.nix importing git-identity.nix and shared-options.nix - Created shared/git-identity.nix with gitIdentity option set: - enable: Toggle for agent git identity - name: Git author name (default: m3ta-chiron) - email: Git author email (default: m3ta-chiron@agentmail.to) - signingKey: Optional GPG signing key path - sshKey: SSH private key path for git push auth - Updated opencode.nix, pi.nix, claude-code.nix to import shared/default.nix - Restructured modules to follow proper Nix module syntax with imports at top level
95 lines
3.1 KiB
Nix
95 lines
3.1 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}: {
|
|
imports = [
|
|
../shared/default.nix
|
|
];
|
|
|
|
options.coding.agents.claude-code = let
|
|
shared = import ../shared/shared-options.nix {inherit lib;};
|
|
mcpCfg = config.programs.mcp or null;
|
|
in
|
|
with lib; {
|
|
enable = mkEnableOption "Claude Code agent management via canonical agent.toml definitions";
|
|
|
|
agentsInput = shared.mkAgentsInputOption ''
|
|
The `agents` flake input (your personal AGENTS repo).
|
|
When set, agents are rendered from canonical agent.toml files
|
|
and symlinked to ~/.claude/agents/.
|
|
'';
|
|
|
|
modelOverrides = shared.mkModelOverridesOption;
|
|
|
|
externalSkills = shared.externalSkillsOption;
|
|
|
|
mcpServers = mkOption {
|
|
type = types.attrsOf types.anything;
|
|
default =
|
|
if mcpCfg != null
|
|
then mcpCfg.servers
|
|
else {};
|
|
defaultText = literalExpression "config.programs.mcp.servers";
|
|
description = ''
|
|
MCP server configurations for Claude Code.
|
|
Merged into ~/.claude/settings.json alongside permissions.
|
|
Automatically inherits from config.programs.mcp.servers.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = with lib; let
|
|
shared = import ../shared/shared-options.nix {inherit lib;};
|
|
cfg = config.coding.agents.claude-code;
|
|
agentsLib = (import ../../../../lib {inherit lib;}).agents;
|
|
in
|
|
mkIf cfg.enable (let
|
|
# Rendered agents + permissions (only if agentsInput is set)
|
|
rendered = mkIf (cfg.agentsInput != null) (
|
|
agentsLib.renderForClaudeCode {
|
|
inherit pkgs;
|
|
canonical = cfg.agentsInput.lib.loadAgents;
|
|
modelOverrides = cfg.modelOverrides;
|
|
}
|
|
);
|
|
|
|
# Merge MCP servers into the rendered settings.json.
|
|
# The renderer produces { permissions: { allow, deny } }.
|
|
# We add mcpServers on top.
|
|
settingsJson =
|
|
if cfg.agentsInput != null
|
|
then let
|
|
renderedSettings = builtins.fromJSON (builtins.readFile "${rendered}/.claude/settings.json");
|
|
withMcp =
|
|
if cfg.mcpServers != {}
|
|
then renderedSettings // {mcpServers = cfg.mcpServers;}
|
|
else renderedSettings;
|
|
in
|
|
pkgs.writeText "claude-settings.json" (builtins.toJSON withMcp)
|
|
else if cfg.mcpServers != {}
|
|
then pkgs.writeText "claude-settings.json" (builtins.toJSON {mcpServers = cfg.mcpServers;})
|
|
else null;
|
|
in {
|
|
# Rendered agent files symlinked to ~/.claude/agents/
|
|
home.file.".claude/agents" = mkIf (cfg.agentsInput != null) {
|
|
source = "${rendered}/.claude/agents";
|
|
};
|
|
|
|
# Skills (merged from personal AGENTS repo + optional external skills)
|
|
home.file.".claude/skills" = mkIf (cfg.agentsInput != null) {
|
|
source = cfg.agentsInput.lib.mkOpencodeSkills {
|
|
inherit pkgs;
|
|
customSkills = "${cfg.agentsInput}/skills";
|
|
externalSkills = shared.mapExternalSkills cfg.externalSkills;
|
|
};
|
|
};
|
|
|
|
# Rendered settings.json with permissions + MCP servers
|
|
home.file.".claude/settings.json" = mkIf (settingsJson != null) {
|
|
source = "${settingsJson}";
|
|
};
|
|
});
|
|
}
|