From 641d717acedd9a468c762b77fa15b5d8a3728600 Mon Sep 17 00:00:00 2001 From: Victor SENE Date: Sat, 15 Jul 2023 14:36:53 +0200 Subject: [PATCH 1/6] nixos/mautrix-whatsapp: init module Import from PR https://github.com/NixOS/nixpkgs/pull/176025 Co-authored-by: Luflosi --- nixos/modules/module-list.nix | 3 +- .../services/matrix/mautrix-whatsapp.nix | 148 ++++++++++++++++++ 2 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 nixos/modules/services/matrix/mautrix-whatsapp.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 0d4369cc3f15..342354b51638 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -600,6 +600,7 @@ ./services/matrix/dendrite.nix ./services/matrix/mautrix-facebook.nix ./services/matrix/mautrix-telegram.nix + ./services/matrix/mautrix-whatsapp.nix ./services/matrix/mjolnir.nix ./services/matrix/mx-puppet-discord.nix ./services/matrix/pantalaimon.nix @@ -1479,5 +1480,5 @@ ./virtualisation/waydroid.nix ./virtualisation/xe-guest-utilities.nix ./virtualisation/xen-dom0.nix - { documentation.nixos.extraModules = [ ./virtualisation/qemu-vm.nix ]; } + {documentation.nixos.extraModules = [./virtualisation/qemu-vm.nix];} ] diff --git a/nixos/modules/services/matrix/mautrix-whatsapp.nix b/nixos/modules/services/matrix/mautrix-whatsapp.nix new file mode 100644 index 000000000000..8ba7fe752ca0 --- /dev/null +++ b/nixos/modules/services/matrix/mautrix-whatsapp.nix @@ -0,0 +1,148 @@ +{ + lib, + config, + pkgs, + ... +}: +with lib; let + cfg = config.services.mautrix-whatsapp; + dataDir = "/var/lib/mautrix-whatsapp"; + settingsFormat = pkgs.formats.json {}; + + registrationFile = "${dataDir}/whatsapp-registration.yaml"; + settingsFile = settingsFormat.generate "config.json" cfg.settings; + + startupScript = '' + ${pkgs.yq}/bin/yq -s '.[0].appservice.as_token = .[1].as_token + | .[0].appservice.hs_token = .[1].hs_token + | .[0]' ${settingsFile} ${registrationFile} \ + > ${dataDir}/config.yml + + ${pkgs.mautrix-whatsapp}/bin/mautrix-whatsapp \ + --config='${dataDir}/config.yml' \ + --registration='${registrationFile}' + ''; +in { + options.services.mautrix-whatsapp = { + enable = mkEnableOption "Mautrix-whatsapp, a puppeting bridge between Matrix and WhatsApp."; + + settings = mkOption rec { + apply = recursiveUpdate default; + inherit (settingsFormat) type; + + description = lib.mdDoc '' + {file}`config.yaml` configuration as a Nix attribute set. + Configuration options should match those described in + [example-config.yaml](https://github.com/mautrix/whatsapp/blob/master/example-config.yaml). + ''; + default = { + homeserver = { + domain = config.services.matrix-synapse.settings.server_name; + }; + appservice = rec { + address = "http://localhost:29318"; + hostname = "0.0.0.0"; + port = 29318; + database = { + type = "sqlite3"; + uri = "${dataDir}/mautrix-whatsapp.db"; + }; + id = "whatsapp"; + bot = { + username = "whatsappbot"; + displayname = "WhatsApp Bot"; + }; + as_token = ""; + hs_token = ""; + }; + bridge = { + username_template = "whatsapp_{{.}}"; + displayname_template = "{{if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}}"; + command_prefix = "!wa"; + permissions."*" = "relay"; + }; + relay = { + enabled = true; + management = "!whatsappbot:${toString (config.services.matrix-synapse.settings.server_name)}"; + }; + logging = { + directory = "${dataDir}/logs"; + file_name_format = "{{.Date}}-{{.Index}}.log"; + file_date_format = "2006-01-02"; + file_mode = 0384; + timestamp_format = "Jan _2, 2006 15:04:05"; + print_level = "info"; + }; + }; + example = { + settings = { + homeserver.address = https://matrix.myhomeserver.org; + bridge.permissions = { + "@admin:myhomeserver.org" = "admin"; + }; + }; + }; + }; + + serviceDependencies = mkOption { + type = with types; listOf str; + default = optional config.services.matrix-synapse.enable "matrix-synapse.service"; + defaultText = literalExpression '' + optional config.services.matrix-synapse.enable "matrix-synapse.service" + ''; + description = lib.mdDoc '' + List of Systemd services to require and wait for when starting the application service. + ''; + }; + }; + + config = mkIf cfg.enable { + systemd.services.mautrix-whatsapp = { + description = "Mautrix-WhatsApp Service - A WhatsApp bridge for Matrix"; + + wantedBy = ["multi-user.target"]; + wants = ["network-online.target"] ++ cfg.serviceDependencies; + after = ["network-online.target"] ++ cfg.serviceDependencies; + + preStart = '' + # generate the appservice's registration file if absent + if [ ! -f '${registrationFile}' ]; then + ${pkgs.mautrix-whatsapp}/bin/mautrix-whatsapp \ + --generate-registration \ + --config='${settingsFile}' \ + --registration='${registrationFile}' + fi + chmod 640 ${registrationFile} + ''; + + script = startupScript; + + serviceConfig = { + Type = "simple"; + #DynamicUser = true; + PrivateTmp = true; + StateDirectory = baseNameOf dataDir; + WorkingDirectory = "${dataDir}"; + + ProtectSystem = "strict"; + ProtectHome = true; + ProtectKernelTunables = true; + ProtectKernelModules = true; + ProtectControlGroups = true; + User = "mautrix-whatsapp"; + Group = "matrix-synapse"; + SupplementaryGroups = "matrix-synapse"; + UMask = 0027; + Restart = "always"; + }; + }; + + users.groups.mautrix-whatsapp = {}; + users.users.mautrix-whatsapp = { + isSystemUser = true; + group = "mautrix-whatsapp"; + home = dataDir; + }; + services.matrix-synapse.settings.app_service_config_files = ["${registrationFile}"]; + }; +} From b443a4d9406b83ea7819e9ea4d9dedb8a17821c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Christ?= Date: Sat, 15 Jul 2023 21:20:55 +0200 Subject: [PATCH 2/6] mautrix-whatsapp: Apply suggestions This contribution applies suggestions made by Luflosi in https://github.com/NixOS/nixpkgs/pull/176025#issuecomment-1237338551 as well as some general refactoring. Co-authored-by: Luflosi --- .../services/matrix/mautrix-whatsapp.nix | 147 +++++++++++------- 1 file changed, 90 insertions(+), 57 deletions(-) diff --git a/nixos/modules/services/matrix/mautrix-whatsapp.nix b/nixos/modules/services/matrix/mautrix-whatsapp.nix index 8ba7fe752ca0..1a959bc96e9d 100644 --- a/nixos/modules/services/matrix/mautrix-whatsapp.nix +++ b/nixos/modules/services/matrix/mautrix-whatsapp.nix @@ -7,41 +7,25 @@ with lib; let cfg = config.services.mautrix-whatsapp; dataDir = "/var/lib/mautrix-whatsapp"; - settingsFormat = pkgs.formats.json {}; - registrationFile = "${dataDir}/whatsapp-registration.yaml"; - settingsFile = settingsFormat.generate "config.json" cfg.settings; - - startupScript = '' - ${pkgs.yq}/bin/yq -s '.[0].appservice.as_token = .[1].as_token - | .[0].appservice.hs_token = .[1].hs_token - | .[0]' ${settingsFile} ${registrationFile} \ - > ${dataDir}/config.yml - - ${pkgs.mautrix-whatsapp}/bin/mautrix-whatsapp \ - --config='${dataDir}/config.yml' \ - --registration='${registrationFile}' - ''; + settingsFile = "${dataDir}/config.json"; + settingsFileUnsubstituted = settingsFormat.generate "mautrix-whatsapp-config-unsubstituted.json" cfg.settings; + settingsFormat = pkgs.formats.json {}; in { options.services.mautrix-whatsapp = { - enable = mkEnableOption "Mautrix-whatsapp, a puppeting bridge between Matrix and WhatsApp."; + enable = mkEnableOption "mautrix-whatsapp, a puppeting/relaybot bridge between Matrix and WhatsApp."; settings = mkOption rec { apply = recursiveUpdate default; inherit (settingsFormat) type; - description = lib.mdDoc '' - {file}`config.yaml` configuration as a Nix attribute set. - Configuration options should match those described in - [example-config.yaml](https://github.com/mautrix/whatsapp/blob/master/example-config.yaml). - ''; default = { homeserver = { domain = config.services.matrix-synapse.settings.server_name; }; appservice = rec { - address = "http://localhost:29318"; - hostname = "0.0.0.0"; + address = "http://localhost:${toString port}"; + hostname = "[::]"; port = 29318; database = { type = "sqlite3"; @@ -50,38 +34,62 @@ in { id = "whatsapp"; bot = { username = "whatsappbot"; - displayname = "WhatsApp Bot"; + displayname = "WhatsApp Bridge Bot"; }; as_token = ""; hs_token = ""; }; bridge = { username_template = "whatsapp_{{.}}"; - displayname_template = "{{if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}}"; + displayname_template = "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)"; + double_puppet_server_map = {}; + login_shared_secret_map = {}; command_prefix = "!wa"; permissions."*" = "relay"; - }; - relay = { - enabled = true; - management = "!whatsappbot:${toString (config.services.matrix-synapse.settings.server_name)}"; + relay = { + enabled = true; + }; }; logging = { - directory = "${dataDir}/logs"; - file_name_format = "{{.Date}}-{{.Index}}.log"; - file_date_format = "2006-01-02"; - file_mode = 0384; - timestamp_format = "Jan _2, 2006 15:04:05"; - print_level = "info"; + min_level = "info"; + writers = [ + { + type = "stdout"; + format = "pretty-colored"; + } + { + type = "file"; + format = "json"; + } + ]; }; }; example = { settings = { - homeserver.address = https://matrix.myhomeserver.org; + homeserver.address = "https://matrix.myhomeserver.org"; bridge.permissions = { "@admin:myhomeserver.org" = "admin"; }; }; }; + description = lib.mdDoc '' + {file}`config.yaml` configuration as a Nix attribute set. + Configuration options should match those described in + [example-config.yaml](https://github.com/mautrix/whatsapp/blob/master/example-config.yaml). + + Secret tokens should be specified using {option}`environmentFile` + instead of this world-readable attribute set. + ''; + }; + + environmentFile = mkOption { + type = types.nullOr types.path; + default = null; + description = lib.mdDoc '' + File containing environment variables to be passed to the mautrix-whatsapp service, + in which secret tokens can be specified securely by optionally defining a value for + `MAUTRIX_WHATSAPP_BRIDGE_LOGIN_SHARED_SECRET`. + ''; }; serviceDependencies = mkOption { @@ -105,6 +113,16 @@ in { after = ["network-online.target"] ++ cfg.serviceDependencies; preStart = '' + # substitute the settings file by environment variables + # in this case read from EnvironmentFile + test -f '${settingsFile}' && rm -f '${settingsFile}' + old_umask=$(umask) + umask 0177 + ${pkgs.envsubst}/bin/envsubst \ + -o '${settingsFile}' \ + -i '${settingsFileUnsubstituted}' + umask $old_umask + # generate the appservice's registration file if absent if [ ! -f '${registrationFile}' ]; then ${pkgs.mautrix-whatsapp}/bin/mautrix-whatsapp \ @@ -113,36 +131,51 @@ in { --registration='${registrationFile}' fi chmod 640 ${registrationFile} + + umask 0177 + ${pkgs.yq}/bin/yq -s '.[0].appservice.as_token = .[1].as_token + | .[0].appservice.hs_token = .[1].hs_token + | .[0]' '${settingsFile}' '${registrationFile}' \ + > '${settingsFile}.tmp' + mv '${settingsFile}.tmp' '${settingsFile}' + umask $old_umask ''; - script = startupScript; - serviceConfig = { - Type = "simple"; - #DynamicUser = true; - PrivateTmp = true; + DynamicUser = true; + EnvironmentFile = cfg.environmentFile; StateDirectory = baseNameOf dataDir; WorkingDirectory = "${dataDir}"; - - ProtectSystem = "strict"; - ProtectHome = true; - ProtectKernelTunables = true; - ProtectKernelModules = true; + ExecStart = '' + ${pkgs.mautrix-whatsapp}/bin/mautrix-whatsapp \ + --config='${settingsFile}' \ + --registration='${registrationFile}' + ''; + LockPersonality = true; + MemoryDenyWriteExecute = true; + NoNewPrivileges = true; + PrivateDevices = true; + PrivateTmp = true; + PrivateUsers = true; + ProtectClock = true; ProtectControlGroups = true; - User = "mautrix-whatsapp"; - Group = "matrix-synapse"; - SupplementaryGroups = "matrix-synapse"; + ProtectHome = true; + ProtectHostname = true; + ProtectKernelLogs = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectSystem = "strict"; + Restart = "on-failure"; + RestartSec = "30s"; + RestrictRealtime = true; + RestrictSUIDSGID = true; + SystemCallArchitectures = "native"; + SystemCallErrorNumber = "EPERM"; + SystemCallFilter = ["@system-service"]; + Type = "simple"; UMask = 0027; - Restart = "always"; }; + restartTriggers = [settingsFileUnsubstituted]; }; - - users.groups.mautrix-whatsapp = {}; - users.users.mautrix-whatsapp = { - isSystemUser = true; - group = "mautrix-whatsapp"; - home = dataDir; - }; - services.matrix-synapse.settings.app_service_config_files = ["${registrationFile}"]; }; } From 01733304267d0840bccf34bd5a6a39c16448b0ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Christ?= Date: Wed, 2 Aug 2023 21:24:29 +0200 Subject: [PATCH 3/6] mautrix-whatsapp: Add postgres options to example --- nixos/modules/services/matrix/mautrix-whatsapp.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nixos/modules/services/matrix/mautrix-whatsapp.nix b/nixos/modules/services/matrix/mautrix-whatsapp.nix index 1a959bc96e9d..366634d9fcc8 100644 --- a/nixos/modules/services/matrix/mautrix-whatsapp.nix +++ b/nixos/modules/services/matrix/mautrix-whatsapp.nix @@ -67,6 +67,10 @@ in { example = { settings = { homeserver.address = "https://matrix.myhomeserver.org"; + appservice.database = { + type = "postgres"; + uri = "postgresql:///mautrix_whatsapp?host=/run/postgresql"; + }; bridge.permissions = { "@admin:myhomeserver.org" = "admin"; }; From a71889c042b1e274671f5d84a19bf18e1516e816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Christ?= Date: Wed, 2 Aug 2023 21:37:30 +0200 Subject: [PATCH 4/6] mautrix-whatsapp: Add release notes --- nixos/doc/manual/release-notes/rl-2311.section.md | 2 ++ nixos/modules/module-list.nix | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/nixos/doc/manual/release-notes/rl-2311.section.md b/nixos/doc/manual/release-notes/rl-2311.section.md index 80b2066582a3..1ca8b2587038 100644 --- a/nixos/doc/manual/release-notes/rl-2311.section.md +++ b/nixos/doc/manual/release-notes/rl-2311.section.md @@ -18,6 +18,8 @@ - [wayfire](https://wayfire.org), A modular and extensible wayland compositor. Available as [programs.wayfire](#opt-programs.wayfire.enable). +- [mautrix-whatsapp](https://docs.mau.fi/bridges/go/whatsapp/index.html) A Matrix-WhatsApp puppeting bridge + - [GoToSocial](https://gotosocial.org/), an ActivityPub social network server, written in Golang. Available as [services.gotosocial](#opt-services.gotosocial.enable). - [Typesense](https://github.com/typesense/typesense), a fast, typo-tolerant search engine for building delightful search experiences. Available as [services.typesense](#opt-services.typesense.enable). diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 342354b51638..9720cf32e6c1 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -1480,5 +1480,5 @@ ./virtualisation/waydroid.nix ./virtualisation/xe-guest-utilities.nix ./virtualisation/xen-dom0.nix - {documentation.nixos.extraModules = [./virtualisation/qemu-vm.nix];} + { documentation.nixos.extraModules = [ ./virtualisation/qemu-vm.nix ]; } ] From 288d2ee55d193c476bd62312f7ed5326835e442f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Christ?= Date: Sat, 5 Aug 2023 13:57:15 +0200 Subject: [PATCH 5/6] mautrix-whatsapp: Move defaults to config section This contribution applies Example 32 (conventional settings option) from [nixpkgs](https://nixos.org/manual/nixos/stable/#sec-settings-nix-representable). --- .../services/matrix/mautrix-whatsapp.nix | 160 ++++++++++-------- 1 file changed, 87 insertions(+), 73 deletions(-) diff --git a/nixos/modules/services/matrix/mautrix-whatsapp.nix b/nixos/modules/services/matrix/mautrix-whatsapp.nix index 366634d9fcc8..c047d6638854 100644 --- a/nixos/modules/services/matrix/mautrix-whatsapp.nix +++ b/nixos/modules/services/matrix/mautrix-whatsapp.nix @@ -3,91 +3,60 @@ config, pkgs, ... -}: -with lib; let +}: let cfg = config.services.mautrix-whatsapp; dataDir = "/var/lib/mautrix-whatsapp"; registrationFile = "${dataDir}/whatsapp-registration.yaml"; settingsFile = "${dataDir}/config.json"; settingsFileUnsubstituted = settingsFormat.generate "mautrix-whatsapp-config-unsubstituted.json" cfg.settings; settingsFormat = pkgs.formats.json {}; + appservicePort = 29318; in { + imports = []; options.services.mautrix-whatsapp = { - enable = mkEnableOption "mautrix-whatsapp, a puppeting/relaybot bridge between Matrix and WhatsApp."; + enable = lib.mkEnableOption "mautrix-whatsapp, a puppeting/relaybot bridge between Matrix and WhatsApp."; - settings = mkOption rec { - apply = recursiveUpdate default; - inherit (settingsFormat) type; - - default = { - homeserver = { - domain = config.services.matrix-synapse.settings.server_name; - }; - appservice = rec { - address = "http://localhost:${toString port}"; - hostname = "[::]"; - port = 29318; - database = { - type = "sqlite3"; - uri = "${dataDir}/mautrix-whatsapp.db"; - }; - id = "whatsapp"; - bot = { - username = "whatsappbot"; - displayname = "WhatsApp Bridge Bot"; - }; - as_token = ""; - hs_token = ""; - }; - bridge = { - username_template = "whatsapp_{{.}}"; - displayname_template = "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)"; - double_puppet_server_map = {}; - login_shared_secret_map = {}; - command_prefix = "!wa"; - permissions."*" = "relay"; - relay = { - enabled = true; - }; - }; - logging = { - min_level = "info"; - writers = [ - { - type = "stdout"; - format = "pretty-colored"; - } - { - type = "file"; - format = "json"; - } - ]; - }; - }; - example = { - settings = { - homeserver.address = "https://matrix.myhomeserver.org"; - appservice.database = { - type = "postgres"; - uri = "postgresql:///mautrix_whatsapp?host=/run/postgresql"; - }; - bridge.permissions = { - "@admin:myhomeserver.org" = "admin"; - }; - }; - }; + settings = lib.mkOption { + type = settingsFormat.type; + default = {}; description = lib.mdDoc '' {file}`config.yaml` configuration as a Nix attribute set. Configuration options should match those described in [example-config.yaml](https://github.com/mautrix/whatsapp/blob/master/example-config.yaml). - Secret tokens should be specified using {option}`environmentFile` instead of this world-readable attribute set. ''; + example = { + appservice = { + database = { + type = "postgres"; + uri = "postgresql:///mautrix_whatsapp?host=/run/postgresql"; + }; + id = "whatsapp"; + ephemeral_events = false; + }; + bridge = { + history_sync = { + request_full_sync = true; + }; + private_chat_portal_meta = true; + mute_bridging = true; + encryption = { + allow = true; + default = true; + require = true; + }; + provisioning = { + shared_secret = "disable"; + }; + permissions = { + "example.com" = "user"; + }; + }; + }; }; - - environmentFile = mkOption { - type = types.nullOr types.path; + environmentFile = lib.mkOption { + type = lib.types.nullOr lib.types.path; default = null; description = lib.mdDoc '' File containing environment variables to be passed to the mautrix-whatsapp service, @@ -96,10 +65,10 @@ in { ''; }; - serviceDependencies = mkOption { - type = with types; listOf str; - default = optional config.services.matrix-synapse.enable "matrix-synapse.service"; - defaultText = literalExpression '' + serviceDependencies = lib.mkOption { + type = with lib.types; listOf str; + default = lib.optional config.services.matrix-synapse.enable "matrix-synapse.service"; + defaultText = lib.literalExpression '' optional config.services.matrix-synapse.enable "matrix-synapse.service" ''; description = lib.mdDoc '' @@ -108,7 +77,51 @@ in { }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { + services.mautrix-whatsapp.settings = { + homeserver = { + domain = lib.mkDefault config.services.matrix-synapse.settings.server_name; + }; + appservice = { + address = lib.mkDefault "http://localhost:${toString appservicePort}"; + hostname = lib.mkDefault "[::]"; + port = lib.mkDefault appservicePort; + database = { + type = lib.mkDefault "sqlite3"; + uri = lib.mkDefault "${dataDir}/mautrix-whatsapp.db"; + }; + id = lib.mkDefault "whatsapp"; + bot = { + username = lib.mkDefault "whatsappbot"; + displayname = lib.mkDefault "WhatsApp Bridge Bot"; + }; + as_token = lib.mkDefault ""; + hs_token = lib.mkDefault ""; + }; + bridge = { + username_template = lib.mkDefault "whatsapp_{{.}}"; + displayname_template = lib.mkDefault "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)"; + double_puppet_server_map = lib.mkDefault {}; + login_shared_secret_map = lib.mkDefault {}; + command_prefix = lib.mkDefault "!wa"; + permissions."*" = lib.mkDefault "relay"; + relay.enabled = lib.mkDefault true; + }; + logging = { + min_level = lib.mkDefault "info"; + writers = [ + { + type = lib.mkDefault "stdout"; + format = lib.mkDefault "pretty-colored"; + } + { + type = lib.mkDefault "file"; + format = lib.mkDefault "json"; + } + ]; + }; + }; + systemd.services.mautrix-whatsapp = { description = "Mautrix-WhatsApp Service - A WhatsApp bridge for Matrix"; @@ -182,4 +195,5 @@ in { restartTriggers = [settingsFileUnsubstituted]; }; }; + meta.maintainers = with lib.maintainers; [frederictobiasc]; } From 3a1f5757b9684c2636ffae30169f68eba08e2e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Christ?= Date: Sun, 6 Aug 2023 11:03:17 +0200 Subject: [PATCH 6/6] mautrix-whatsapp: move defaults back to options. As suggested by @nickcao this commit moves the defaults back to the options. Only `homeserver.domain` stays in the config section since the documentation module does not support referencing attributes of other modules. --- .../services/matrix/mautrix-whatsapp.nix | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/nixos/modules/services/matrix/mautrix-whatsapp.nix b/nixos/modules/services/matrix/mautrix-whatsapp.nix index c047d6638854..80c85980196f 100644 --- a/nixos/modules/services/matrix/mautrix-whatsapp.nix +++ b/nixos/modules/services/matrix/mautrix-whatsapp.nix @@ -18,7 +18,46 @@ in { settings = lib.mkOption { type = settingsFormat.type; - default = {}; + default = { + appservice = { + address = "http://localhost:${toString appservicePort}"; + hostname = "[::]"; + port = appservicePort; + database = { + type = "sqlite3"; + uri = "${dataDir}/mautrix-whatsapp.db"; + }; + id = "whatsapp"; + bot = { + username = "whatsappbot"; + displayname = "WhatsApp Bridge Bot"; + }; + as_token = ""; + hs_token = ""; + }; + bridge = { + username_template = "whatsapp_{{.}}"; + displayname_template = "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)"; + double_puppet_server_map = {}; + login_shared_secret_map = {}; + command_prefix = "!wa"; + permissions."*" = "relay"; + relay.enabled = true; + }; + logging = { + min_level = "info"; + writers = [ + { + type = "stdout"; + format = "pretty-colored"; + } + { + type = "file"; + format = "json"; + } + ]; + }; + }; description = lib.mdDoc '' {file}`config.yaml` configuration as a Nix attribute set. Configuration options should match those described in @@ -79,47 +118,7 @@ in { config = lib.mkIf cfg.enable { services.mautrix-whatsapp.settings = { - homeserver = { - domain = lib.mkDefault config.services.matrix-synapse.settings.server_name; - }; - appservice = { - address = lib.mkDefault "http://localhost:${toString appservicePort}"; - hostname = lib.mkDefault "[::]"; - port = lib.mkDefault appservicePort; - database = { - type = lib.mkDefault "sqlite3"; - uri = lib.mkDefault "${dataDir}/mautrix-whatsapp.db"; - }; - id = lib.mkDefault "whatsapp"; - bot = { - username = lib.mkDefault "whatsappbot"; - displayname = lib.mkDefault "WhatsApp Bridge Bot"; - }; - as_token = lib.mkDefault ""; - hs_token = lib.mkDefault ""; - }; - bridge = { - username_template = lib.mkDefault "whatsapp_{{.}}"; - displayname_template = lib.mkDefault "{{if .BusinessName}}{{.BusinessName}}{{else if .PushName}}{{.PushName}}{{else}}{{.JID}}{{end}} (WA)"; - double_puppet_server_map = lib.mkDefault {}; - login_shared_secret_map = lib.mkDefault {}; - command_prefix = lib.mkDefault "!wa"; - permissions."*" = lib.mkDefault "relay"; - relay.enabled = lib.mkDefault true; - }; - logging = { - min_level = lib.mkDefault "info"; - writers = [ - { - type = lib.mkDefault "stdout"; - format = lib.mkDefault "pretty-colored"; - } - { - type = lib.mkDefault "file"; - format = lib.mkDefault "json"; - } - ]; - }; + homeserver.domain = lib.mkDefault config.services.matrix-synapse.settings.server_name; }; systemd.services.mautrix-whatsapp = {