refactor: reorganize, add package (opencode, osgrep, beads), add ai agent shell
This commit is contained in:
parent
7e0a207778
commit
a0f0f39399
58 changed files with 7867 additions and 42 deletions
179
modules/home/devtools/ai-tools.nix
Normal file
179
modules/home/devtools/ai-tools.nix
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
mkEnableOption mkOption types mkIf concatMap unique warn escapeShellArg;
|
||||
cfg = config.rsydn.aiTools;
|
||||
|
||||
getPkgsPackage = name: lib.attrByPath [ name ] null pkgs;
|
||||
|
||||
codexDefault = getPkgsPackage "codex";
|
||||
|
||||
crushDefault = getPkgsPackage "crush";
|
||||
|
||||
claudeDefault = getPkgsPackage "claude-code";
|
||||
|
||||
toolOption = { name, description, defaultPackage, extraOptions ? { }
|
||||
, extraDefaults ? { } }:
|
||||
mkOption {
|
||||
type = types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Enable the ${name} CLI.";
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = defaultPackage;
|
||||
description =
|
||||
"Package providing ${name}. Set to null to skip installation.";
|
||||
};
|
||||
} // extraOptions;
|
||||
};
|
||||
default = {
|
||||
enable = true;
|
||||
package = defaultPackage;
|
||||
} // extraDefaults;
|
||||
description = description;
|
||||
};
|
||||
|
||||
gatherToolPackages = tools:
|
||||
concatMap (tool:
|
||||
let
|
||||
name = tool.name;
|
||||
cfgTool = tool.cfg;
|
||||
in if cfgTool.enable then
|
||||
if cfgTool.package != null then
|
||||
[ cfgTool.package ]
|
||||
else
|
||||
warn "rsydn.aiTools.${name}: package is null, skipping install" [ ]
|
||||
else
|
||||
[ ]) tools;
|
||||
|
||||
toolPackages = gatherToolPackages [
|
||||
{
|
||||
name = "codex";
|
||||
cfg = cfg.codex;
|
||||
}
|
||||
{
|
||||
name = "crush";
|
||||
cfg = cfg.crush;
|
||||
}
|
||||
{
|
||||
name = "claude";
|
||||
cfg = cfg.claude;
|
||||
}
|
||||
];
|
||||
|
||||
zaiWrapperPackages = let
|
||||
claudeCfg = cfg.claude;
|
||||
zaiCfg = claudeCfg.zai or { enable = false; };
|
||||
in if claudeCfg.enable && zaiCfg.enable then
|
||||
if claudeCfg.package != null then
|
||||
let
|
||||
claudeExe = lib.getExe claudeCfg.package;
|
||||
commandName = zaiCfg.commandName;
|
||||
baseUrl = zaiCfg.baseUrl;
|
||||
model = zaiCfg.model;
|
||||
tokenEnvVar = zaiCfg.tokenEnvVar;
|
||||
in [
|
||||
(pkgs.writeShellApplication {
|
||||
name = commandName;
|
||||
text = ''
|
||||
if [ -z "''${${tokenEnvVar}:-}" ]; then
|
||||
echo "${commandName}: environment variable ${tokenEnvVar} is not set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export ANTHROPIC_BASE_URL=${escapeShellArg baseUrl}
|
||||
export ANTHROPIC_AUTH_TOKEN="''${${tokenEnvVar}}"
|
||||
export ANTHROPIC_MODEL=${escapeShellArg model}
|
||||
|
||||
exec ${claudeExe} "$@"
|
||||
'';
|
||||
})
|
||||
]
|
||||
else
|
||||
warn "rsydn.aiTools.claude: Z.AI wrapper requested but package is null"
|
||||
[ ]
|
||||
else
|
||||
[ ];
|
||||
|
||||
in {
|
||||
options.rsydn.aiTools = {
|
||||
enable = mkEnableOption "AI-oriented command line tooling";
|
||||
|
||||
codex = toolOption {
|
||||
name = "Codex";
|
||||
description = "OpenAI Codex CLI packaged in nixpkgs.";
|
||||
defaultPackage = codexDefault;
|
||||
};
|
||||
|
||||
crush = toolOption {
|
||||
name = "Crush";
|
||||
description = "Charmbracelet Crush CLI packaged in nixpkgs.";
|
||||
defaultPackage = crushDefault;
|
||||
};
|
||||
|
||||
# Note: OpenCode is now managed by its own module at ./opencode.nix
|
||||
|
||||
claude = toolOption {
|
||||
name = "Claude Code";
|
||||
description = "Anthropic Claude Code CLI packaged in nixpkgs.";
|
||||
defaultPackage = claudeDefault;
|
||||
extraOptions = {
|
||||
zai = mkOption {
|
||||
type = types.submodule {
|
||||
options = {
|
||||
enable = mkEnableOption
|
||||
"Expose the Z.AI Gateway wrapper command for Claude.";
|
||||
commandName = mkOption {
|
||||
type = types.str;
|
||||
default = "glm";
|
||||
description =
|
||||
"Name of the wrapper command that launches Claude via Z.AI.";
|
||||
};
|
||||
baseUrl = mkOption {
|
||||
type = types.str;
|
||||
default = "https://api.z.ai/api/anthropic";
|
||||
description = "Gateway base URL used for the Anthropic client.";
|
||||
};
|
||||
model = mkOption {
|
||||
type = types.str;
|
||||
default = "glm-4.6";
|
||||
description = "Model identifier passed via ANTHROPIC_MODEL.";
|
||||
};
|
||||
tokenEnvVar = mkOption {
|
||||
type = types.str;
|
||||
default = "ZAI_API_KEY";
|
||||
description =
|
||||
"Environment variable that stores the Z.AI API token.";
|
||||
};
|
||||
};
|
||||
};
|
||||
default = {
|
||||
enable = false;
|
||||
commandName = "glm";
|
||||
baseUrl = "https://api.z.ai/api/anthropic";
|
||||
model = "glm-4.6";
|
||||
tokenEnvVar = "ZAI_API_KEY";
|
||||
};
|
||||
description =
|
||||
"Configuration for the Claude wrapper that targets the Z.AI gateway.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
extraPackages = mkOption {
|
||||
type = types.listOf types.package;
|
||||
default = [ ];
|
||||
description =
|
||||
"Additional AI tooling packages to add alongside the defaults.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages =
|
||||
unique (toolPackages ++ zaiWrapperPackages ++ cfg.extraPackages);
|
||||
};
|
||||
}
|
||||
20
modules/home/devtools/default.nix
Normal file
20
modules/home/devtools/default.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types mkIf;
|
||||
cfg = config.rsydn.devTools;
|
||||
in {
|
||||
options.rsydn.devTools = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
description = "Enable per-user development tooling packages.";
|
||||
};
|
||||
packages = mkOption {
|
||||
type = types.listOf types.package;
|
||||
default = [ ];
|
||||
description = "Extra user-scoped packages to install.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable { home.packages = cfg.packages; };
|
||||
}
|
||||
127
modules/home/devtools/languages.nix
Normal file
127
modules/home/devtools/languages.nix
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption mkIf types warn unique;
|
||||
cfg = config.rsydn.languages;
|
||||
|
||||
hasPkg = name: builtins.hasAttr name pkgs;
|
||||
getPkg = name: if hasPkg name then pkgs.${name} else null;
|
||||
|
||||
mkToolOption = { name, defaultPackage, description }:
|
||||
mkOption {
|
||||
type = types.submodule {
|
||||
options = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = defaultPackage != null;
|
||||
description = "Enable ${name} tooling globally.";
|
||||
};
|
||||
package = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = defaultPackage;
|
||||
description =
|
||||
"Package derivation to install for ${name}. Set to null to skip.";
|
||||
};
|
||||
};
|
||||
};
|
||||
default = {
|
||||
enable = defaultPackage != null;
|
||||
package = defaultPackage;
|
||||
};
|
||||
description = description;
|
||||
};
|
||||
|
||||
mkToolPackages = specs:
|
||||
builtins.concatMap (tool:
|
||||
let toolCfg = tool.cfg;
|
||||
in if toolCfg.enable then
|
||||
if toolCfg.package != null then
|
||||
[ toolCfg.package ]
|
||||
else
|
||||
warn "rsydn.languages.${tool.name}: package is null, skipping" [ ]
|
||||
else
|
||||
[ ]) specs;
|
||||
|
||||
uvPackage = getPkg "uv";
|
||||
goPackage = getPkg "go";
|
||||
nodePackage = if builtins.hasAttr "nodejs_20" pkgs then
|
||||
pkgs.nodejs_20
|
||||
else
|
||||
getPkg "nodejs";
|
||||
cargoPackage = getPkg "cargo";
|
||||
bunPackage = getPkg "bun";
|
||||
|
||||
toolSpecs = [
|
||||
{
|
||||
name = "uv";
|
||||
cfg = cfg.uv;
|
||||
defaultPackage = uvPackage;
|
||||
}
|
||||
{
|
||||
name = "go";
|
||||
cfg = cfg.go;
|
||||
defaultPackage = goPackage;
|
||||
}
|
||||
{
|
||||
name = "node";
|
||||
cfg = cfg.node;
|
||||
defaultPackage = nodePackage;
|
||||
}
|
||||
{
|
||||
name = "cargo";
|
||||
cfg = cfg.cargo;
|
||||
defaultPackage = cargoPackage;
|
||||
}
|
||||
{
|
||||
name = "bun";
|
||||
cfg = cfg.bun;
|
||||
defaultPackage = bunPackage;
|
||||
}
|
||||
];
|
||||
|
||||
languagePackages = mkToolPackages toolSpecs;
|
||||
|
||||
in {
|
||||
options.rsydn.languages = {
|
||||
enable = mkEnableOption "Language tooling packages for everyday workflows";
|
||||
|
||||
uv = mkToolOption {
|
||||
name = "uv";
|
||||
defaultPackage = uvPackage;
|
||||
description = "Python package installer and virtualenv manager.";
|
||||
};
|
||||
|
||||
go = mkToolOption {
|
||||
name = "Go";
|
||||
defaultPackage = goPackage;
|
||||
description = "Go compiler and GOPATH toolchain.";
|
||||
};
|
||||
|
||||
node = mkToolOption {
|
||||
name = "Node.js";
|
||||
defaultPackage = nodePackage;
|
||||
description = "Node.js runtime for CLI tooling.";
|
||||
};
|
||||
|
||||
cargo = mkToolOption {
|
||||
name = "Cargo";
|
||||
defaultPackage = cargoPackage;
|
||||
description = "Rust package manager and toolchain.";
|
||||
};
|
||||
|
||||
bun = mkToolOption {
|
||||
name = "Bun";
|
||||
defaultPackage = bunPackage;
|
||||
description = "Fast all-in-one JavaScript runtime.";
|
||||
};
|
||||
|
||||
extraPackages = mkOption {
|
||||
type = types.listOf types.package;
|
||||
default = [ ];
|
||||
description = "Additional language tooling packages to install globally.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = unique (languagePackages ++ cfg.extraPackages);
|
||||
};
|
||||
}
|
||||
107
modules/home/devtools/opencode.nix
Normal file
107
modules/home/devtools/opencode.nix
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
{ config, lib, pkgs, customPkgs, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types mkIf;
|
||||
cfg = config.rsydn.opencode;
|
||||
|
||||
# Build the config JSON, filtering out null/empty values
|
||||
opencodeConfig = lib.filterAttrs (_: v: v != null && v != { }) {
|
||||
"$schema" = "https://opencode.ai/config.json";
|
||||
theme = cfg.theme;
|
||||
model = cfg.model;
|
||||
small_model = cfg.smallModel;
|
||||
autoupdate = false; # Nix manages updates
|
||||
mcp = if cfg.mcpServers != { } then cfg.mcpServers else null;
|
||||
keybinds = if cfg.keybinds != { } then cfg.keybinds else null;
|
||||
};
|
||||
in {
|
||||
options.rsydn.opencode = {
|
||||
enable = mkEnableOption "OpenCode CLI with managed configuration";
|
||||
|
||||
package = mkOption {
|
||||
type = types.nullOr types.package;
|
||||
default = customPkgs.opencode;
|
||||
description = ''
|
||||
OpenCode package to use. Defaults to the custom-built package
|
||||
from packages/opencode.nix via customPkgs.
|
||||
'';
|
||||
};
|
||||
|
||||
theme = mkOption {
|
||||
type = types.str;
|
||||
default = "catppuccin";
|
||||
description = "UI theme for OpenCode TUI";
|
||||
};
|
||||
|
||||
model = mkOption {
|
||||
type = types.str;
|
||||
default = "anthropic/claude-sonnet-4-5";
|
||||
description = "Primary LLM model identifier";
|
||||
};
|
||||
|
||||
smallModel = mkOption {
|
||||
type = types.str;
|
||||
default = "anthropic/claude-haiku-3-5";
|
||||
description = "Lightweight model for tasks like title generation";
|
||||
};
|
||||
|
||||
mcpServers = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
example = {
|
||||
nixos = {
|
||||
type = "stdio";
|
||||
command = "uvx";
|
||||
args = [ "mcp-nixos" ];
|
||||
};
|
||||
};
|
||||
description = "MCP server configurations";
|
||||
};
|
||||
|
||||
keybinds = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
description = "Custom keybinding overrides";
|
||||
};
|
||||
|
||||
# Future extension points (joelhooks-style)
|
||||
agents = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
default = { };
|
||||
description = ''
|
||||
Custom agent markdown files.
|
||||
Keys become filenames under ~/.config/opencode/agent/
|
||||
'';
|
||||
};
|
||||
|
||||
commands = mkOption {
|
||||
type = types.attrsOf types.path;
|
||||
default = { };
|
||||
description = ''
|
||||
Custom command markdown files.
|
||||
Keys become filenames under ~/.config/opencode/command/
|
||||
'';
|
||||
};
|
||||
|
||||
extraConfig = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
description = "Additional config options to merge into opencode.json";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
home.packages = lib.optional (cfg.package != null) cfg.package;
|
||||
|
||||
xdg.configFile = {
|
||||
# Global config file
|
||||
"opencode/opencode.json".text =
|
||||
builtins.toJSON (opencodeConfig // cfg.extraConfig);
|
||||
} // lib.mapAttrs' (name: path:
|
||||
# Agent markdown files
|
||||
lib.nameValuePair "opencode/agent/${name}.md" { source = path; })
|
||||
cfg.agents // lib.mapAttrs' (name: path:
|
||||
# Command markdown files
|
||||
lib.nameValuePair "opencode/command/${name}.md" { source = path; })
|
||||
cfg.commands;
|
||||
};
|
||||
}
|
||||
24
modules/home/devtools/try.nix
Normal file
24
modules/home/devtools/try.nix
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{ config, lib, pkgs, try, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types mkIf;
|
||||
cfg = config.rsydn.try;
|
||||
in {
|
||||
imports = [ try.homeModules.default ];
|
||||
|
||||
options.rsydn.try = {
|
||||
enable = mkEnableOption "Try - temporary project directory manager";
|
||||
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
default = "~/src/tries";
|
||||
description = "Storage directory for try experiment instances.";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
programs.try = {
|
||||
enable = true;
|
||||
path = cfg.path;
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue