2024-01-06 01:19:35 +01:00
|
|
|
# SPDX-FileCopyrightText: 2021-2023 Simon Bruder <simon@sbruder.de>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2021-04-02 14:01:38 +02:00
|
|
|
# somewhat adapted from https://github.com/NixOS/nixpkgs/pull/59211
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
2022-05-31 14:43:51 +02:00
|
|
|
synapseCfg = config.services.matrix-synapse.settings;
|
2021-04-02 14:01:38 +02:00
|
|
|
in
|
|
|
|
let
|
|
|
|
config = rec {
|
|
|
|
homeserver = {
|
|
|
|
address = synapseCfg.public_baseurl;
|
|
|
|
domain = synapseCfg.server_name;
|
|
|
|
};
|
|
|
|
appservice = rec {
|
|
|
|
hostname = "127.0.0.1";
|
|
|
|
port = 29318;
|
|
|
|
address = "http://${hostname}:${toString port}";
|
|
|
|
provisioning.shared_secret = "disable";
|
|
|
|
database = {
|
|
|
|
type = "sqlite3";
|
|
|
|
uri = "/var/lib/mautrix-whatsapp/mautrix-whatsapp.db";
|
|
|
|
};
|
|
|
|
id = "whatsapp";
|
|
|
|
bot = {
|
|
|
|
username = "whatsappbot";
|
|
|
|
displayname = "WhatsApp bridge bot";
|
|
|
|
avatar = "mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
whatsapp = {
|
|
|
|
browser_name = "mx-wa";
|
|
|
|
os_name = "Mautrix-WhatsApp bridge";
|
|
|
|
};
|
|
|
|
bridge = {
|
|
|
|
command_prefix = "!wa";
|
|
|
|
delivery_receipts = true;
|
2021-12-01 19:09:52 +01:00
|
|
|
displayname_template = "{{if .FullName}}{{.FullName}}{{else if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}} (WA)";
|
|
|
|
history_sync = {
|
|
|
|
backfill = true;
|
2021-04-02 14:01:38 +02:00
|
|
|
};
|
2021-12-01 19:09:52 +01:00
|
|
|
identity_change_notices = true;
|
2021-04-02 14:01:38 +02:00
|
|
|
permissions = {
|
|
|
|
# Only one user since using the name from the address book does not
|
|
|
|
# work with multiple users
|
|
|
|
"@simon:${homeserver.domain}" = 100;
|
|
|
|
};
|
2021-12-01 19:09:52 +01:00
|
|
|
private_chat_portal_meta = true;
|
|
|
|
reaction_notices = true;
|
|
|
|
relay.enable = false;
|
2021-04-02 14:01:38 +02:00
|
|
|
};
|
2023-02-07 11:26:42 +01:00
|
|
|
logging = {
|
|
|
|
print_level = "info";
|
|
|
|
file_name_format = null;
|
|
|
|
};
|
2021-04-02 14:01:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
generatedConfig = pkgs.runCommandNoCC "mautrix-whatsapp-config"
|
|
|
|
{
|
|
|
|
buildInputs = with pkgs; [ mautrix-whatsapp ];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
mkdir $out
|
|
|
|
cat ${pkgs.writeText "mautrix-whatsapp.yaml" (lib.generators.toYAML { } config)} > $out/config.yaml
|
|
|
|
mautrix-whatsapp -c $out/config.yaml -g -r $out/registration.yaml
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
systemd.services.mautrix-whatsapp = {
|
|
|
|
description = "Mautrix-WhatsApp Service - A WhatsApp bridge for Matrix";
|
|
|
|
after = [ "network.target" "matrix-synapse.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "mautrix-whatsapp";
|
2021-12-01 19:09:52 +01:00
|
|
|
WorkingDirectory = "/var/lib/mautrix-whatsapp";
|
2021-06-19 16:02:04 +02:00
|
|
|
ExecStart = "${pkgs.mautrix-whatsapp}/bin/mautrix-whatsapp -c ${generatedConfig}/config.yaml";
|
2021-04-02 14:01:38 +02:00
|
|
|
Restart = "on-failure";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-31 14:43:51 +02:00
|
|
|
services.matrix-synapse.settings.app_service_config_files = lib.singleton "${generatedConfig}/registration.yaml";
|
2021-04-02 14:01:38 +02:00
|
|
|
}
|