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

164 lines
4 KiB
Nix
Raw Normal View History

{
2024-09-01 19:19:30 -04:00
config,
lib,
pkgs,
...
}: let
inherit
(lib)
attrNames
escapeShellArgs
flatten
filterAttrs
hasAttr
2024-09-01 19:19:30 -04:00
listToAttrs
map
mkEnableOption
mkForce
mkIf
mkOption
nameValuePair
optionals
splitString
types
;
flatMap = f: list: flatten (map f list);
cfg = config.services.wyoming.openwakeword-docker;
in {
options.services.wyoming.openwakeword-docker = {
enable = mkEnableOption "Wyoming openWakeWord server";
image = mkOption {
type = types.package;
default = pkgs.dockerTools.pullImage {
imageName = "docker.io/rhasspy/wyoming-openwakeword";
imageDigest = "sha256:88df83cfdaa5a0dd068f79662d06b81479ec7b59a4bea59751ff5d6f68bad24a";
sha256 = "1c2yhrhhj1wpd5bcc3zaz1gv8mw8dw5m76cjf42nhf2sgwp2hsjl";
finalImageName = "docker.io/rhasspy/wyoming-openwakeword";
finalImageTag = "latest";
};
description = ''
The image that docker will use.
'';
};
uri = mkOption {
type = types.str;
default = "0.0.0.0:10400";
example = "192.0.2.1:5000";
description = ''
URI to bind the wyoming server to.
'';
};
customModelsDirectories = mkOption {
type = types.listOf types.path;
default = [];
description = ''
Paths to directories with custom wake word models (*.tflite model files).
'';
};
preloadModels = mkOption {
type = with types; listOf str;
default = [
"ok_nabu"
];
example = [
# wyoming_openwakeword/models/*.tflite
"alexa"
"hey_jarvis"
"hey_mycroft"
"hey_rhasspy"
"ok_nabu"
];
description = ''
List of wake word models to preload after startup.
'';
};
threshold = mkOption {
type = types.float;
default = 0.5;
description = ''
Activation threshold (0-1), where higher means fewer activations.
See trigger level for the relationship between activations and
wake word detections.
'';
apply = toString;
};
triggerLevel = mkOption {
type = types.int;
default = 1;
description = ''
Number of activations before a detection is registered.
A higher trigger level means fewer detections.
'';
apply = toString;
};
extraArgs = mkOption {
type = with types; listOf str;
default = [];
description = ''
Extra arguments to pass to the server commandline.
'';
apply = escapeShellArgs;
};
};
config = {
assertions = [
{
assertion =
(cfg.enable
chore: update flake.lock Flake Inputs: • Updated input 'discord-overlay': 'github:matt1432/discord-nightly-overlay/a4a9f83' (2024-09-02) → 'github:matt1432/discord-nightly-overlay/0e14fde' (2024-09-05) • Updated input 'discord-overlay/Vencord-src': 'github:Vendicated/vencord/accfc15' (2024-09-02) → 'github:Vendicated/vencord/8890c8c' (2024-09-05) • Updated input 'gpu-screen-recorder-src': 'git+https://repo.dec05eba.com/gpu-screen-recorder?ref=refs/heads/master&rev=33251a4' (2024-08-31) → 'git+https://repo.dec05eba.com/gpu-screen-recorder?ref=refs/heads/master&rev=98f75b2' (2024-09-03) • Updated input 'hyprland': 'git+https://github.com/hyprwm/Hyprland?ref=refs/heads/main&rev=6934e7a&submodules=1' (2024-09-01) → 'git+https://github.com/hyprwm/Hyprland?ref=refs/heads/main&rev=027140b&submodules=1' (2024-09-04) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/12228ff' (2024-08-31) → 'github:NixOS/nixpkgs/ad416d0' (2024-09-04) • Updated input 'pcsd': 'github:matt1432/nixos-pcsd/cd327ff' (2024-09-02) → 'github:matt1432/nixos-pcsd/82a158d' (2024-09-04) • Updated input 'sops-nix': 'github:Mic92/sops-nix/5db5921' (2024-09-01) → 'github:Mic92/sops-nix/d9d7815' (2024-09-05) Docker Images: • vegardit/gitea-act-runner dind-latest: sha256:f7e6d2e86588d36b371b71f80356de04e774bba12c45b2246ea02020412b2cbf → sha256:d1071eb21edbb477b2d93dda5c8ba4e0aa471ee73e4e52776389744215d8536c • postgres 14: sha256:e3cc76b6d4dfc8f3547641d67053092e7c108e03ab159c00b48fa8d891e2f7b4 → sha256:148b383bf37b569f1b44d72b3558979540e9f5f951789b0b0c6e827decbeef09 • rssbridge/rss-bridge latest: sha256:a4e973ca2c1967d4dae52bfd0694aa38e547c1f3e0c52553d0789ad4d55e6423 → sha256:ed96ae6fb5be49a7c14fc35de039d53f2b42d99034c49c4e28fe0810e3886445 • nginx latest: sha256:447a8665cc1dab95b1ca778e162215839ccbb9189104c79d7ec3a81e14577add → sha256:1a2bb47140dd616774ffe05ea1ea8762e1f1f08e20a35632e1e6539376d44d60 • onlyoffice/documentserver latest: sha256:d9437b6d8455de45a02dd5ed2529c8c19c5d1407076c03ca73e0737941ec3748 → sha256:a69b1c43c6641e45789a6ebb7e84359ada749c8e2d4e83916d4e85945238f418 • ghcr.io/wg-easy/wg-easy latest: sha256:f6c2587da3fdc9d5927743fb4a92cff42d690b182396ffd0cdad034becb41053 → sha256:66352ccb4b5095992550aa567df5118a5152b6ed31be34b0a8e118a3c3a35bf5 • ghcr.io/linuxserver/bazarr latest: sha256:aa904c142512b64e98b0abd038bf8b07e1b0e8cf3a14a805cb9ae4df9415b933 → sha256:0364bb3d8d03cf0995036140322f6d0de78dd1924ba990499f67598f7c61ff62 • ghcr.io/linuxserver/sabnzbd latest: sha256:223197e9cbb70112244e44ba9660ba7ce1d2128771b8a03ad38e20f85c953583 → sha256:66576a72ecb80c8d9e8ebffd4699995b29bfff4aefba4c6eae14baac3cbf6716
2024-09-05 10:01:52 -04:00
&& hasAttr "khepri" config
&& hasAttr "rwDataDir" config.khepri)
|| !cfg.enable;
message = ''
The module `docker` from this same flake is needed to use
this openwakeword implementation.
'';
}
];
2024-09-01 19:19:30 -04:00
systemd.services = let
unitNames = attrNames (
filterAttrs (_: v: v.device == "cpu") config.services.wyoming.faster-whisper.servers
);
in
listToAttrs (map (x:
nameValuePair "wyoming-faster-whisper-${x}" {
serviceConfig.ProcSubset = mkForce "all";
})
unitNames);
khepri = mkIf cfg.enable {
compositions."openwakeword" = {
networks.default = {};
services."openwakeword" = {
image = cfg.image;
restart = "always";
networks = ["default"];
volumes = map (dir: "${toString dir}:${toString dir}") cfg.customModelsDirectories;
cmd =
(flatMap (model: ["--preload-model" model]) cfg.preloadModels)
++ (flatMap (dir: ["--custom-model-dir" (toString dir)]) cfg.customModelsDirectories)
++ ["--threshold" cfg.threshold]
++ ["--trigger-level" cfg.triggerLevel]
++ optionals (cfg.extraArgs != "") (splitString " " cfg.extraArgs);
ports = ["${cfg.uri}:10400"];
};
};
};
};
}