From f0f4db1be086c90286bee69176a3f66a25e3a030 Mon Sep 17 00:00:00 2001
From: matt1432 <matt@nelim.org>
Date: Wed, 4 Sep 2024 17:43:46 -0400
Subject: [PATCH] feat(hass): move whisper to nos for gpu

---
 devices/homie/modules/home-assistant.nix | 15 +++----------
 devices/nos/default.nix                  |  2 +-
 devices/nos/modules/llm.nix              | 28 ++++++++++++++++++++++++
 devices/nos/modules/ollama.nix           | 11 ----------
 4 files changed, 32 insertions(+), 24 deletions(-)
 create mode 100644 devices/nos/modules/llm.nix
 delete mode 100644 devices/nos/modules/ollama.nix

diff --git a/devices/homie/modules/home-assistant.nix b/devices/homie/modules/home-assistant.nix
index 472a13c9..cc06b840 100644
--- a/devices/homie/modules/home-assistant.nix
+++ b/devices/homie/modules/home-assistant.nix
@@ -15,6 +15,7 @@
       enable = true;
 
       extraComponents = [
+        "caldav"
         "esphome"
         "holiday"
         "isal"
@@ -71,20 +72,10 @@
         uri = "tcp://127.0.0.1:10200";
 
         # see https://github.com/rhasspy/rhasspy3/blob/master/programs/tts/piper/script/download.py
-        voice = "en-us-ryan-low";
+        voice = "en-us-ryan-low"; # using `hfc male (medium)` in GUI
         speaker = 0;
       };
 
-      faster-whisper.servers."en" = {
-        enable = true;
-        uri = "tcp://127.0.0.1:10300";
-
-        # see https://github.com/rhasspy/rhasspy3/blob/master/programs/asr/faster-whisper/script/download.py
-        model = "small-int8";
-        language = "en";
-        device = "cpu";
-      };
-
       openwakeword-docker = {
         enable = true;
         uri = "127.0.0.1:10400";
@@ -112,7 +103,7 @@
       then "--socket /run/esphome/esphome.sock"
       else "--address ${cfg.address} --port ${toString cfg.port}";
   in {
-    environment.PLATFORMIO_CORE_DIR = mkForce "/var/lib/private/esphome/.platformio";
+    environment.PLATFORMIO_CORE_DIR = mkForce "${stateDir}/.platformio";
 
     serviceConfig = {
       ExecStart = mkForce "${cfg.package}/bin/esphome dashboard ${esphomeParams} ${stateDir}";
diff --git a/devices/nos/default.nix b/devices/nos/default.nix
index 4ffefb8d..cffa6ca0 100644
--- a/devices/nos/default.nix
+++ b/devices/nos/default.nix
@@ -13,8 +13,8 @@ in {
 
     ./modules/docker
     ./modules/jellyfin
+    ./modules/llm.nix
     ./modules/mergerfs.nix
-    ./modules/ollama.nix
     ./modules/qbittorrent
     ./modules/snapraid.nix
     ./modules/subtitles
diff --git a/devices/nos/modules/llm.nix b/devices/nos/modules/llm.nix
new file mode 100644
index 00000000..5fb3cda1
--- /dev/null
+++ b/devices/nos/modules/llm.nix
@@ -0,0 +1,28 @@
+{self, ...}: let
+  tailscaleIP = "100.64.0.4";
+in {
+  imports = [self.nixosModules.wyoming-plus];
+
+  services = {
+    # Speech-to-Text
+    wyoming.faster-whisper.servers."en" = {
+      enable = true;
+      uri = "tcp://${tailscaleIP}:10300";
+
+      # see https://github.com/rhasspy/wyoming-faster-whisper/releases/tag/v2.0.0
+      model = "medium.en";
+      device = "cuda";
+    };
+
+    # Text-to-Intent
+    ollama = {
+      enable = true;
+      acceleration = "cuda";
+
+      host = tailscaleIP;
+      port = 11434;
+
+      loadModels = ["fixt/home-3b-v3"];
+    };
+  };
+}
diff --git a/devices/nos/modules/ollama.nix b/devices/nos/modules/ollama.nix
deleted file mode 100644
index f9325d7c..00000000
--- a/devices/nos/modules/ollama.nix
+++ /dev/null
@@ -1,11 +0,0 @@
-{...}: {
-  services.ollama = {
-    enable = true;
-    acceleration = "cuda";
-
-    host = "100.64.0.4";
-    port = 11434;
-
-    loadModels = ["fixt/home-3b-v3"];
-  };
-}