8 cfg = config.services.marytts;
9 format = pkgs.formats.javaProperties { };
12 options.services.marytts = {
13 enable = lib.mkEnableOption "MaryTTS";
15 settings = lib.mkOption {
16 type = lib.types.submodule {
17 freeformType = format.type;
23 See the [default settings](https://github.com/marytts/marytts/blob/master/marytts-runtime/conf/marybase.config)
24 for a list of possible keys.
28 package = lib.mkPackageOption pkgs "marytts" { };
30 basePath = lib.mkOption {
31 type = lib.types.path;
32 default = "/var/lib/marytts";
34 The base path in which MaryTTS runs.
39 type = lib.types.port;
42 Port to bind the MaryTTS server to.
46 openFirewall = lib.mkOption {
47 type = lib.types.bool;
51 Whether to open the port in the firewall for MaryTTS.
55 voices = lib.mkOption {
56 type = lib.types.listOf lib.types.path;
58 example = lib.literalExpression ''
61 url = "https://github.com/marytts/voice-bits1-hsmm/releases/download/v5.2/voice-bits1-hsmm-5.2.zip";
62 hash = "sha256-1nK+qZxjumMev7z5lgKr660NCKH5FDwvZ9sw/YYYeaA=";
67 Paths to the JAR files that contain additional voices for MaryTTS.
69 Voices are automatically detected by MaryTTS, so there is no need to alter
70 your config to make use of new voices.
74 userDictionaries = lib.mkOption {
75 type = lib.types.listOf lib.types.path;
77 example = lib.literalExpression ''
80 name = "userdict-en_US";
81 destination = "/userdict-en_US.txt";
83 Nixpkgs | n I k s - ' p { - k @ - dZ @ s
89 Paths to the user dictionary files for MaryTTS.
94 config = lib.mkIf cfg.enable {
95 services.marytts.settings = {
96 "mary.base" = lib.mkDefault cfg.basePath;
97 "socket.port" = lib.mkDefault cfg.port;
100 environment.systemPackages = [ cfg.package ];
102 systemd.services.marytts = {
103 description = "MaryTTS server instance";
104 after = [ "network.target" ];
105 wantedBy = [ "multi-user.target" ];
107 # FIXME: MaryTTS's config loading mechanism appears to be horrendously broken
108 # and it doesn't seem to actually read config files outside of precompiled JAR files.
109 # Using system properties directly works for now, but this is really ugly.
111 ${lib.getExe pkgs.marytts} -classpath "${cfg.basePath}/lib/*:${cfg.package}/lib/*" ${
112 lib.concatStringsSep " " (lib.mapAttrsToList (n: v: ''-D${n}="${v}"'') cfg.settings)
116 restartTriggers = cfg.voices ++ cfg.userDictionaries;
121 RuntimeDirectory = "marytts";
122 StateDirectory = "marytts";
123 Restart = "on-failure";
129 ProtectKernelLogs = true;
130 ProtectControlGroups = true;
131 ProtectKernelModules = true;
132 ProtectHostname = true;
133 ProtectKernelTunables = true;
134 ProtectProc = "invisible";
139 PrivateNetwork = false;
140 PrivateUsers = cfg.port >= 1024;
141 PrivateDevices = true;
143 RestrictRealtime = true;
144 RestrictNamespaces = true;
145 RestrictAddressFamilies = [
150 MemoryDenyWriteExecute = false; # Java does not like w^x :(
151 LockPersonality = true;
152 AmbientCapabilities = lib.optional (cfg.port < 1024) "CAP_NET_BIND_SERVICE";
153 CapabilityBoundingSet = "";
154 SystemCallArchitectures = "native";
164 systemd.tmpfiles.settings."10-marytts" = {
165 "${cfg.basePath}/lib"."L+".argument = "${pkgs.symlinkJoin {
166 name = "marytts-lib";
168 # Put user paths before default ones so that user ones have priority
169 paths = cfg.voices ++ [ "${cfg.package}/lib" ];
172 "${cfg.basePath}/user-dictionaries"."L+".argument = "${pkgs.symlinkJoin {
173 name = "marytts-user-dictionaries";
175 # Put user paths before default ones so that user ones have priority
176 paths = cfg.userDictionaries ++ [ "${cfg.package}/user-dictionaries" ];
180 networking.firewall = lib.mkIf cfg.openFirewall {
181 allowedTCPPorts = [ cfg.port ];