From 675306ec9127d31440932d8539c92951579712e1 Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Wed, 22 Apr 2026 14:38:09 +0200 Subject: [PATCH] refactor: modularize 'ai-tools' --- home/modules/ai-tools/claude-code.nix | 60 +++++++++++++ home/modules/ai-tools/default.nix | 117 +------------------------- home/modules/ai-tools/opencode.nix | 40 +++++++++ home/modules/ai-tools/tirith.nix | 30 +++++++ 4 files changed, 134 insertions(+), 113 deletions(-) create mode 100644 home/modules/ai-tools/claude-code.nix create mode 100644 home/modules/ai-tools/opencode.nix create mode 100644 home/modules/ai-tools/tirith.nix diff --git a/home/modules/ai-tools/claude-code.nix b/home/modules/ai-tools/claude-code.nix new file mode 100644 index 00000000..f638dbb1 --- /dev/null +++ b/home/modules/ai-tools/claude-code.nix @@ -0,0 +1,60 @@ +{ + lib, + config, + pkgs, + ... +}: +let + cfg = config.ai-tools.claude-code; + rtk-version = "0.18.1"; +in +{ + options.ai-tools.claude-code.enable = lib.mkEnableOption "claude code with rtk and ccline"; + + config = lib.mkIf cfg.enable { + programs.claude-code.enable = true; + + home.packages = with pkgs; [ + (stdenv.mkDerivation { + name = "ccline"; + src = fetchurl { + url = "https://github.com/Haleclipse/CCometixLine/releases/download/v1.0.8/ccline-linux-x64.tar.gz"; + hash = "sha256-Joe3Dd6uSMGi66QT6xr2oY/Tz8rA5RuKa6ckBVJIzI0="; + }; + unpackPhase = "tar xzf $src"; + installPhase = '' + mkdir -p $out/bin + cp ccline $out/bin/ + chmod +x $out/bin/ccline + ''; + meta = { + description = "CCometixLine Linux x64 CLI (Claude Code statusline)"; + homepage = "https://github.com/Haleclipse/CCometixLine"; + license = lib.licenses.mit; + platforms = [ "x86_64-linux" ]; + }; + }) + (stdenv.mkDerivation { + name = "rtk-${rtk-version}"; + version = rtk-version; + src = fetchurl { + url = "https://github.com/rtk-ai/rtk/releases/download/v${rtk-version}/rtk-x86_64-unknown-linux-gnu.tar.gz"; + hash = "sha256-XoTia5K8b00OzcKYCufwx8ApkAS31DxUCpGSU0jFs2Q="; + }; + unpackPhase = "tar xzf $src"; + installPhase = '' + mkdir -p $out/bin + cp rtk $out/bin/ + chmod +x $out/bin/rtk + ''; + meta = { + description = "RTK - AI coding tool enhancer"; + homepage = "https://www.rtk-ai.app"; + license = lib.licenses.mit; + platforms = [ "x86_64-linux" ]; + }; + }) + mcp-nixos + ]; + }; +} diff --git a/home/modules/ai-tools/default.nix b/home/modules/ai-tools/default.nix index 5f8001b3..f24e040c 100644 --- a/home/modules/ai-tools/default.nix +++ b/home/modules/ai-tools/default.nix @@ -1,116 +1,7 @@ { - lib, - config, - pkgs, - ... -}: -let - cfg = config.ai-tools; - rtk-version = "0.18.1"; -in -{ - options.ai-tools = { - claude-code.enable = lib.mkEnableOption "claude code with rtk and ccline"; - tirith.enable = lib.mkEnableOption "tirith shell security guard"; - opencode.enable = lib.mkEnableOption "opencode"; - }; - - config = lib.mkMerge [ - (lib.mkIf cfg.claude-code.enable { - home.packages = with pkgs; [ - claude-code - (pkgs.stdenv.mkDerivation { - name = "ccline"; - src = pkgs.fetchurl { - url = "https://github.com/Haleclipse/CCometixLine/releases/download/v1.0.8/ccline-linux-x64.tar.gz"; - hash = "sha256-Joe3Dd6uSMGi66QT6xr2oY/Tz8rA5RuKa6ckBVJIzI0="; - }; - - unpackPhase = '' - tar xzf $src - ''; - - installPhase = '' - mkdir -p $out/bin - cp ccline $out/bin/ - chmod +x $out/bin/ccline - ''; - - meta = with pkgs.lib; { - description = "CCometixLine Linux x64 CLI (Claude Code statusline)"; - homepage = "https://github.com/Haleclipse/CCometixLine"; - license = licenses.mit; - platforms = [ "x86_64-linux" ]; - }; - }) - (pkgs.stdenv.mkDerivation { - name = "rtk-${rtk-version}"; - version = rtk-version; - src = pkgs.fetchurl { - url = "https://github.com/rtk-ai/rtk/releases/download/v${rtk-version}/rtk-x86_64-unknown-linux-gnu.tar.gz"; - hash = "sha256-XoTia5K8b00OzcKYCufwx8ApkAS31DxUCpGSU0jFs2Q="; - }; - - unpackPhase = '' - tar xzf $src - ''; - - installPhase = '' - mkdir -p $out/bin - cp rtk $out/bin/ - chmod +x $out/bin/rtk - ''; - - meta = with pkgs.lib; { - description = "RTK - AI coding tool enhancer"; - homepage = "https://www.rtk-ai.app"; - license = licenses.mit; - platforms = [ "x86_64-linux" ]; - }; - }) - # mcp-nixos - ]; - }) - (lib.mkIf cfg.tirith.enable { - home.packages = with pkgs; [ - tirith - ]; - }) - (lib.mkIf (cfg.tirith.enable && cfg.claude-code.enable) { - home.file.".claude/hooks/tirith-check.py" = { - source = ./tirith-check.py; - executable = true; - }; - - home.activation.tirith-claude-code = lib.hm.dag.entryAfter [ "writeBoundary" ] '' - ${pkgs.tirith}/bin/tirith setup claude-code --with-mcp --scope user --force 2>/dev/null || true - ''; - }) - (lib.mkIf cfg.opencode.enable { - home.packages = with pkgs; [ - opencode - ]; - home.file.".config/opencode/opencode.json".text = builtins.toJSON { - "$schema" = "https://opencode.ai/config.json"; - permission = { - external_directory = { - "/run/secrets/" = "deny"; - "~/.config/sops/age/keys.txt" = "deny"; - "~/.ssh/id_rsa" = "deny"; - "~/.ssh/id_ed25519" = "deny"; - "~/.ssh/id_ecdsa" = "deny"; - "~/.ssh/id_dsa" = "deny"; - "/etc/ssh/ssh_host_rsa_key" = "deny"; - "/etc/ssh/ssh_host_ed25519_key" = "deny"; - "/etc/ssh/ssh_host_ecdsa_key" = "deny"; - "/etc/ssh/ssh_host_dsa_key" = "deny"; - }; - command = { - sops = "deny"; - }; - }; - plugin = [ "@mohak34/opencode-notifier@latest" ]; - }; - }) + imports = [ + ./claude-code.nix + ./opencode.nix + ./tirith.nix ]; } diff --git a/home/modules/ai-tools/opencode.nix b/home/modules/ai-tools/opencode.nix new file mode 100644 index 00000000..5eba098e --- /dev/null +++ b/home/modules/ai-tools/opencode.nix @@ -0,0 +1,40 @@ +{ + lib, + config, + pkgs, + ... +}: +let + cfg = config.ai-tools.opencode; +in +{ + options.ai-tools.opencode = { + enable = lib.mkEnableOption "opencode"; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ pkgs.opencode ]; + + home.file.".config/opencode/opencode.json".text = builtins.toJSON { + "$schema" = "https://opencode.ai/config.json"; + permission = { + external_directory = { + "/run/secrets/" = "deny"; + "~/.config/sops/age/keys.txt" = "deny"; + "~/.ssh/id_rsa" = "deny"; + "~/.ssh/id_ed25519" = "deny"; + "~/.ssh/id_ecdsa" = "deny"; + "~/.ssh/id_dsa" = "deny"; + "/etc/ssh/ssh_host_rsa_key" = "deny"; + "/etc/ssh/ssh_host_ed25519_key" = "deny"; + "/etc/ssh/ssh_host_ecdsa_key" = "deny"; + "/etc/ssh/ssh_host_dsa_key" = "deny"; + }; + command = { + sops = "deny"; + }; + }; + plugin = [ "@mohak34/opencode-notifier@latest" ]; + }; + }; +} diff --git a/home/modules/ai-tools/tirith.nix b/home/modules/ai-tools/tirith.nix new file mode 100644 index 00000000..c2b93900 --- /dev/null +++ b/home/modules/ai-tools/tirith.nix @@ -0,0 +1,30 @@ +{ + lib, + config, + pkgs, + ... +}: +let + cfg = config.ai-tools.tirith; +in +{ + options.ai-tools.tirith = { + enable = lib.mkEnableOption "tirith shell security guard"; + }; + + config = lib.mkMerge [ + (lib.mkIf cfg.enable { + home.packages = [ pkgs.tirith ]; + }) + (lib.mkIf (cfg.enable && config.ai-tools.claude-code.enable) { + home.file.".claude/hooks/tirith-check.py" = { + source = ./tirith-check.py; + executable = true; + }; + + home.activation.tirith-claude-code = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + ${pkgs.tirith}/bin/tirith setup claude-code --with-mcp --scope user --force 2>/dev/null || true + ''; + }) + ]; +}