2023-09-29 23:07:34 +02:00
|
|
|
{ config
|
|
|
|
, lib
|
|
|
|
, pkgs
|
|
|
|
, ...
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.wyoming.openwakeword;
|
|
|
|
|
|
|
|
inherit (lib)
|
2023-10-30 17:57:48 +01:00
|
|
|
concatStringsSep
|
2023-09-29 23:07:34 +02:00
|
|
|
concatMapStringsSep
|
|
|
|
escapeShellArgs
|
|
|
|
mkOption
|
|
|
|
mdDoc
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
2023-11-30 19:03:14 +01:00
|
|
|
mkPackageOption
|
2023-10-30 17:57:48 +01:00
|
|
|
mkRemovedOptionModule
|
2023-09-29 23:07:34 +02:00
|
|
|
types
|
|
|
|
;
|
|
|
|
|
|
|
|
inherit (builtins)
|
|
|
|
toString
|
|
|
|
;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2023-10-30 17:57:48 +01:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "services" "wyoming" "openwakeword" "models" ] "Configuring models has been removed, they are now dynamically discovered and loaded at runtime")
|
|
|
|
];
|
|
|
|
|
2023-09-29 23:07:34 +02:00
|
|
|
meta.buildDocsInSandbox = false;
|
|
|
|
|
|
|
|
options.services.wyoming.openwakeword = with types; {
|
|
|
|
enable = mkEnableOption (mdDoc "Wyoming openWakeWord server");
|
|
|
|
|
2023-11-30 19:03:14 +01:00
|
|
|
package = mkPackageOption pkgs "wyoming-openwakeword" { };
|
2023-09-29 23:07:34 +02:00
|
|
|
|
|
|
|
uri = mkOption {
|
|
|
|
type = strMatching "^(tcp|unix)://.*$";
|
|
|
|
default = "tcp://0.0.0.0:10400";
|
|
|
|
example = "tcp://192.0.2.1:5000";
|
|
|
|
description = mdDoc ''
|
|
|
|
URI to bind the wyoming server to.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2023-10-30 17:57:48 +01:00
|
|
|
customModelsDirectories = mkOption {
|
|
|
|
type = listOf types.path;
|
|
|
|
default = [];
|
|
|
|
description = lib.mdDoc ''
|
|
|
|
Paths to directories with custom wake word models (*.tflite model files).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
preloadModels = mkOption {
|
2023-10-30 16:21:58 +01:00
|
|
|
type = listOf str;
|
|
|
|
default = [
|
2023-10-30 17:57:48 +01:00
|
|
|
"ok_nabu"
|
|
|
|
];
|
|
|
|
example = [
|
2023-10-30 16:21:58 +01:00
|
|
|
# wyoming_openwakeword/models/*.tflite
|
|
|
|
"alexa"
|
|
|
|
"hey_jarvis"
|
|
|
|
"hey_mycroft"
|
|
|
|
"hey_rhasspy"
|
|
|
|
"ok_nabu"
|
|
|
|
];
|
2023-09-29 23:07:34 +02:00
|
|
|
description = mdDoc ''
|
|
|
|
List of wake word models to preload after startup.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
threshold = mkOption {
|
|
|
|
type = float;
|
|
|
|
default = 0.5;
|
|
|
|
description = mdDoc ''
|
|
|
|
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 = int;
|
|
|
|
default = 1;
|
|
|
|
description = mdDoc ''
|
|
|
|
Number of activations before a detection is registered.
|
|
|
|
|
|
|
|
A higher trigger level means fewer detections.
|
|
|
|
'';
|
|
|
|
apply = toString;
|
|
|
|
};
|
|
|
|
|
|
|
|
extraArgs = mkOption {
|
|
|
|
type = listOf str;
|
|
|
|
default = [ ];
|
|
|
|
description = mdDoc ''
|
|
|
|
Extra arguments to pass to the server commandline.
|
|
|
|
'';
|
|
|
|
apply = escapeShellArgs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services."wyoming-openwakeword" = {
|
|
|
|
description = "Wyoming openWakeWord server";
|
|
|
|
after = [
|
|
|
|
"network-online.target"
|
|
|
|
];
|
|
|
|
wantedBy = [
|
|
|
|
"multi-user.target"
|
|
|
|
];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
User = "wyoming-openwakeword";
|
|
|
|
# https://github.com/home-assistant/addons/blob/master/openwakeword/rootfs/etc/s6-overlay/s6-rc.d/openwakeword/run
|
2023-10-30 17:57:48 +01:00
|
|
|
ExecStart = concatStringsSep " " [
|
|
|
|
"${cfg.package}/bin/wyoming-openwakeword"
|
|
|
|
"--uri ${cfg.uri}"
|
|
|
|
(concatMapStringsSep " " (model: "--preload-model ${model}") cfg.preloadModels)
|
2023-10-31 00:42:04 +01:00
|
|
|
(concatMapStringsSep " " (dir: "--custom-model-dir ${toString dir}") cfg.customModelsDirectories)
|
2023-10-30 17:57:48 +01:00
|
|
|
"--threshold ${cfg.threshold}"
|
|
|
|
"--trigger-level ${cfg.triggerLevel}"
|
|
|
|
"${cfg.extraArgs}"
|
|
|
|
];
|
2023-09-29 23:07:34 +02:00
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
DeviceAllow = "";
|
|
|
|
DevicePolicy = "closed";
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectProc = "invisible";
|
2023-10-16 19:50:14 +02:00
|
|
|
ProcSubset = "all"; # reads /proc/cpuinfo
|
2023-09-29 23:07:34 +02:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
"AF_UNIX"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RuntimeDirectory = "wyoming-openwakeword";
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@privileged"
|
|
|
|
];
|
|
|
|
UMask = "0077";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|