8 cfg = config.services.tts;
12 options.services.tts = let
13 inherit (lib) literalExpression mkOption mkEnableOption types;
16 type = types.attrsOf (types.submodule (
19 enable = mkEnableOption "Coqui TTS server";
25 Port to bind the TTS server to.
30 type = types.nullOr types.str;
31 default = "tts_models/en/ljspeech/tacotron2-DDC";
34 Name of the model to download and use for speech synthesis.
36 Check `tts-server --list_models` for possible values.
38 Set to `null` to use a custom model.
47 Whether to offload computation onto a CUDA compatible GPU.
51 extraArgs = mkOption {
52 type = types.listOf types.str;
55 Extra arguments to pass to the server commandline.
62 example = literalExpression ''
66 model = "tts_models/en/ljspeech/tacotron2-DDC";
70 model = "tts_models/de/thorsten/tacotron2-DDC";
74 model = "tts_models/nl/mai/tacotron2-DDC";
85 inherit (lib) mkIf mapAttrs' nameValuePair optionalString concatMapStringsSep escapeShellArgs;
86 in mkIf (cfg.servers != {}) {
87 systemd.services = mapAttrs' (server: options:
88 nameValuePair "tts-${server}" {
89 description = "Coqui TTS server instance ${server}";
91 "network-online.target"
99 environment.HOME = "/var/lib/tts";
103 StateDirectory = "tts";
104 ExecStart = "${pkgs.tts}/bin/tts-server --port ${toString options.port}"
105 + optionalString (options.model != null) " --model_name ${options.model}"
106 + optionalString (options.useCuda) " --use_cuda"
107 + (concatMapStringsSep " " escapeShellArgs options.extraArgs);
108 CapabilityBoundingSet = "";
109 DeviceAllow = if options.useCuda then [
110 # https://docs.nvidia.com/dgx/pdf/dgx-os-5-user-guide.pdf
115 "/dev/nvidia-caps/nvidia-cap1"
116 "/dev/nvidia-caps/nvidia-cap2"
118 "/dev/nvidia-modeset"
120 "/dev/nvidia-uvm-tools"
122 DevicePolicy = "closed";
123 LockPersonality = true;
124 # jit via numba->llvmpipe
125 MemoryDenyWriteExecute = false;
126 PrivateDevices = true;
129 ProtectHostname = true;
130 ProtectKernelLogs = true;
131 ProtectKernelModules = true;
132 ProtectKernelTunables = true;
133 ProtectControlGroups = true;
134 ProtectProc = "invisible";
136 RestrictAddressFamilies = [
141 RestrictNamespaces = true;
142 RestrictRealtime = true;
143 SystemCallArchitectures = "native";