From 4d23848ad079731a650f663e8a6b1e6b87079938 Mon Sep 17 00:00:00 2001 From: linsui <36977733+linsui@users.noreply.github.com> Date: Sat, 8 Feb 2025 21:25:39 +0800 Subject: [PATCH] nixos/speechd: add config --- .../services/accessibility/speechd.nix | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/nixos/modules/services/accessibility/speechd.nix b/nixos/modules/services/accessibility/speechd.nix index ff98c363fc29..fc8920e70820 100644 --- a/nixos/modules/services/accessibility/speechd.nix +++ b/nixos/modules/services/accessibility/speechd.nix @@ -7,9 +7,11 @@ let cfg = config.services.speechd; inherit (lib) + mapAttrs' mkEnableOption mkIf mkPackageOption + mkOption ; in { @@ -17,13 +19,72 @@ in # FIXME: figure out how to deprecate this EXTREMELY CAREFULLY # default guessed conservatively in ../misc/graphical-desktop.nix enable = mkEnableOption "speech-dispatcher speech synthesizer daemon"; + package = mkPackageOption pkgs "speechd" { }; + + config = mkOption { + type = with lib.types; nullOr lines; + default = null; + description = '' + System wide configuration file for Speech Dispatcher. This will be used if no user configuration file is found. + ''; + example = '' + AddModule "module_name" "module_binary" "module_config" + ''; + }; + + modules = mkOption { + type = with lib.types; submodule { freeformType = attrsOf lines; }; + default = { }; + description = '' + Configuration files of output modules. + ''; + example = { + generic-epos = '' + AddVoice "cs" "male1" "kadlec" + AddVoice "sk" "male1" "bob" + ''; + }; + }; + + clients = mkOption { + type = with lib.types; submodule { freeformType = attrsOf lines; }; + default = { }; + description = '' + Client specific configuration. + ''; + example = { + emacs = '' + BeginClient "emacs:*" + # Example: + # DefaultPunctuationMode "some" + EndClient + ''; + }; + }; }; config = mkIf cfg.enable { environment = { systemPackages = [ cfg.package ]; + + etc = + if cfg.config == null then + { speech-dispatcher.source = "${cfg.package}/etc/speech-dispatcher"; } + else + { + "speech-dispatcher/speechd.conf".text = cfg.config; + } + // (mapAttrs' (name: value: { + name = "speech-dispatcher/modules/${name}.conf"; + value.text = value; + }) cfg.modules) + // (mapAttrs' (name: value: { + name = "speech-dispatcher/clients/${name}.conf"; + value.text = value; + }) cfg.clients); }; + systemd.packages = [ cfg.package ]; # have to set `wantedBy` since `systemd.packages` ignores `[Install]` systemd.user.sockets.speech-dispatcher.wantedBy = [ "sockets.target" ];