Unverified Commit 0e327a55 authored by Martin Weinelt's avatar Martin Weinelt
Browse files

nixos/wyoming-openwakeword: refresh module

parent 2fa61164
Loading
Loading
Loading
Loading
+36 −28
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
  config,
  lib,
  pkgs,
  utils,
  ...
}:

@@ -9,14 +10,11 @@ let
  cfg = config.services.wyoming.openwakeword;

  inherit (lib)
    concatStringsSep
    concatMapStringsSep
    escapeShellArgs
    concatMap
    mkOption
    mkEnableOption
    mkIf
    mkPackageOption
    mkRemovedOptionModule
    types
    ;

@@ -24,20 +22,12 @@ let
    toString
    ;

  inherit (utils)
    escapeSystemdExecArgs
    ;
in

{
  imports = [
    (mkRemovedOptionModule [
      "services"
      "wyoming"
      "openwakeword"
      "models"
    ] "Configuring models has been removed, they are now dynamically discovered and loaded at runtime")
  ];

  meta.buildDocsInSandbox = false;

  options.services.wyoming.openwakeword = with types; {
    enable = mkEnableOption "Wyoming openWakeWord server";

@@ -79,10 +69,10 @@ in
    };

    threshold = mkOption {
      type = float;
      type = numbers.between 0.0 1.0;
      default = 0.5;
      description = ''
        Activation threshold (0-1), where higher means fewer activations.
        Activation threshold (0.0-1.0), where higher means fewer activations.

        See trigger level for the relationship between activations and
        wake word detections.
@@ -91,7 +81,7 @@ in
    };

    triggerLevel = mkOption {
      type = int;
      type = ints.unsigned;
      default = 1;
      description = ''
        Number of activations before a detection is registered.
@@ -107,7 +97,6 @@ in
      description = ''
        Extra arguments to pass to the server commandline.
      '';
      apply = escapeShellArgs;
    };
  };

@@ -127,15 +116,34 @@ in
        DynamicUser = true;
        User = "wyoming-openwakeword";
        # https://github.com/home-assistant/addons/blob/master/openwakeword/rootfs/etc/s6-overlay/s6-rc.d/openwakeword/run
        ExecStart = concatStringsSep " " [
          "${cfg.package}/bin/wyoming-openwakeword"
          "--uri ${cfg.uri}"
          (concatMapStringsSep " " (model: "--preload-model ${model}") cfg.preloadModels)
          (concatMapStringsSep " " (dir: "--custom-model-dir ${toString dir}") cfg.customModelsDirectories)
          "--threshold ${cfg.threshold}"
          "--trigger-level ${cfg.triggerLevel}"
          "${cfg.extraArgs}"
        ];
        ExecStart = escapeSystemdExecArgs (
          [
            (lib.getExe cfg.package)
            "--uri"
            cfg.uri
            "--threshold"
            cfg.threshold
            "--trigger-level"
            cfg.triggerLevel
          ]
          ++ concatMap (
            model:
            [
              "--preload-model"
              model
            ]
              cfg.preloadModels
          )
          ++ concatMap (
            dir:
            [
              "--custom-model-dir"
              (toString dir)
            ]
              cfg.customModelsDirectories
          )
          ++ cfg.extraArgs
        );
        CapabilityBoundingSet = "";
        DeviceAllow = "";
        DevicePolicy = "closed";