From b8e909d68bcb035648dda93f15de7863f444a3c4 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sat, 22 Nov 2025 00:43:12 +0530 Subject: Switch to kakoune + daffm --- modules/ai/default.nix | 51 +++++++++++++++++++++++++++++++++++++ modules/email.home/.gitignore | 1 + modules/email.home/aerc.conf | 4 +-- modules/kakoune/default.nix | 25 ++++++++++++++++++ modules/kakoune/kak-tree-sitter.nix | 19 ++++++++++++++ modules/xresources.home.nix | 2 +- 6 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 modules/ai/default.nix create mode 100644 modules/kakoune/default.nix create mode 100644 modules/kakoune/kak-tree-sitter.nix (limited to 'modules') diff --git a/modules/ai/default.nix b/modules/ai/default.nix new file mode 100644 index 0000000..034e33b --- /dev/null +++ b/modules/ai/default.nix @@ -0,0 +1,51 @@ +{ lib, pkgs, ... }: +let + llama-cpp-pkg = pkgs.llama-cpp-vulkan; + port = 9081; + ctx-size = 128; # 32 + hf-file = "gemma-3-4b-it-Q4_K_M.gguf"; + hf-repo = + "unsloth/gemma-3-4b-it-GGUF"; + # "itlwas/Phi-4-mini-instruct-Q4_K_M-GGUF"; + # "unsloth/gemma-3-4b-it-GGUF"; + # "yasserrmd/DeepSeek-7B-1M-gguf"; + # "unsloth/Seed-Coder-8B-Instruct-GGUF"; + api-key = "foobar"; + + llama-start-server = pkgs.writeShellScriptBin "llama-start-server" '' + exec ${llama-cpp-pkg}/bin/llama-server --log-disable \ + --port ${toString port} \ + --hf-repo ${hf-repo} \ + ${if hf-file != "" then "--hf-file ${hf-file}" else ""} \ + --ctx-size ${toString (ctx-size * 1024)} \ + --api-key ${api-key} \ + --threads 12 --no-perf + ''; + llama-start-server-background = pkgs.writeShellScriptBin "llama-start-server-background" '' + is_running() { ${pkgs.lsof}/bin/lsof -i ":${toString port}" >/dev/null 2>&1; } + + if ! is_running; then + setsid -f ${llama-start-server}/bin/llama-start-server >"$HOME/.local/state/local-ai-logs" 2>&1 + + attempts=20; + while ! ([ "$attempts" == "0" ] || is_running); do + sleep 5; + attempts=$((attempts - 1)); + done + fi + ''; +in +{ + environment.systemPackages = with pkgs; [ + llama-cpp-pkg + llama-start-server + llama-start-server-background + aichat + piper-tts + ]; + + environment.variables = { + AI_API_URL = "http://localhost:${toString port}"; + AI_API_KEY = api-key; + }; +} diff --git a/modules/email.home/.gitignore b/modules/email.home/.gitignore index a211cae..41d633b 100644 --- a/modules/email.home/.gitignore +++ b/modules/email.home/.gitignore @@ -1 +1,2 @@ private.nix +*.private.* diff --git a/modules/email.home/aerc.conf b/modules/email.home/aerc.conf index e7dc011..656d4a1 100644 --- a/modules/email.home/aerc.conf +++ b/modules/email.home/aerc.conf @@ -9,8 +9,8 @@ auto-mark-read = true parse-http-links = true [compose] -editor = nvim -file-picker-cmd = lf -selection-path=%f +editor = kak-tmux +file-picker-cmd = sh -c "DAFFM_SELECTIONS_OUT=%f daffm -c @picker" empty-subject-warning = true no-attachment-warning = ^[^>]*attach(ed|ment) edit-headers = true diff --git a/modules/kakoune/default.nix b/modules/kakoune/default.nix new file mode 100644 index 0000000..bacab15 --- /dev/null +++ b/modules/kakoune/default.nix @@ -0,0 +1,25 @@ +{ pkgs, lib, ... }: +with pkgs; +let + kak-tree-sitter-unstable = import ./kak-tree-sitter.nix { inherit pkgs lib; }; + kak-tmux = pkgs.writeShellScriptBin "kak-tmux" '' + if [ -t 0 ] && [ -z "$TMUX" ]; then + exec