nixos-configs/nixosModules/wyoming-plus/default.nix

76 lines
2.2 KiB
Nix
Raw Normal View History

{
2024-09-01 19:19:30 -04:00
config,
lib,
pkgs,
...
}: let
inherit
(lib)
attrNames
2024-09-12 18:21:31 -04:00
concatMapStringsSep
concatStringsSep
2024-09-01 19:19:30 -04:00
filterAttrs
listToAttrs
map
mkForce
mkIf
2024-09-12 18:21:31 -04:00
mkOverride
2024-09-01 19:19:30 -04:00
nameValuePair
2024-09-12 18:21:31 -04:00
optionalString
2024-09-01 19:19:30 -04:00
;
2024-09-12 18:21:31 -04:00
cfg = config.services.wyoming;
2024-09-01 19:19:30 -04:00
in {
2024-09-12 18:21:31 -04:00
config = let
forkedPkg = import ./pkgs/wyoming-openwakeword.nix pkgs;
whisperUnitNames = attrNames (
filterAttrs (_: v: v.device == "cpu") cfg.faster-whisper.servers
);
in {
systemd.services =
# https://github.com/felschr/nixos-config/blob/6a0f0bf76e3ae80c1e180ba6f6c7fd3b8e91d2d3/services/home-assistant/wyoming.nix#L29
mkIf (cfg.faster-whisper.servers != {})
(listToAttrs (map (x:
2024-09-01 19:19:30 -04:00
nameValuePair "wyoming-faster-whisper-${x}" {
serviceConfig.ProcSubset = mkForce "all";
})
2024-09-12 18:21:31 -04:00
whisperUnitNames))
#
# openWakeWord
// mkIf (cfg.openwakeword.enable) {
wyoming-openwakeword.serviceConfig = {
MemoryDenyWriteExecute = mkForce (cfg.openwakeword.package != forkedPkg);
# changes according to https://github.com/rhasspy/wyoming-openwakeword/pull/27
ExecStart = mkForce (concatStringsSep " " [
"${cfg.openwakeword.package}/bin/wyoming-openwakeword"
"--uri ${cfg.openwakeword.uri}"
"--threshold ${cfg.openwakeword.threshold}"
(concatMapStringsSep " "
(dir: "--custom-model-dir ${toString dir}")
cfg.openwakeword.customModelsDirectories)
# removed option https://github.com/rhasspy/wyoming-openwakeword/pull/27#issuecomment-2211822998
(optionalString
(cfg.openwakeword.package != forkedPkg)
(concatMapStringsSep " " (model: "--preload-model ${model}") cfg.openwakeword.preloadModels))
# removed option since preloading was removed
(optionalString
(cfg.openwakeword.package != forkedPkg)
"--trigger-level ${cfg.openwakeword.triggerLevel}")
"${cfg.openwakeword.extraArgs}"
]);
2024-09-01 19:19:30 -04:00
};
};
2024-09-12 18:21:31 -04:00
services.wyoming.openwakeword = mkIf (cfg.openwakeword.enable) {
package = mkOverride 900 forkedPkg;
2024-09-01 19:19:30 -04:00
};
};
}