add mautrix-slack

This commit is contained in:
Charlotte 🦝 Delenk 2024-09-23 20:26:18 +02:00
parent 1cc6693050
commit 2f383a3313
4 changed files with 207 additions and 3 deletions

View file

@ -40,6 +40,7 @@
#./services/kubernetes.nix
./services/forgejo-runner.nix
./services/renovate.nix
./services/mautrix-slack.nix
];
hardware.cpu.amd.updateMicrocode = true;

View file

@ -0,0 +1,49 @@
{
config,
pkgs,
...
}: {
imports = [
../../modules/matrix/mautrix-slack.nix
];
services.mautrix-slack = {
enable = true;
environmentFile = config.sops.secrets."services/mautrix/shared_secret".path;
settings = {
bridge = {
permissions = {
"*" = "relay";
"@miifox:chir.rs" = "user";
"@lotte:chir.rs" = "admin";
};
};
database = {
type = "postgres";
uri = "postgres:///mautrix_slack?sslmode=disable&host=/run/postgresql";
};
homeserver = {
address = "https://matrix.chir.rs";
domain = "chir.rs";
async_media = true;
};
appservice = {
ephemeral_events = true;
async_transactions = true;
};
backfill = {
enabled = true;
queue.enabled = true;
};
encryption = {
allow = true;
default = true;
appservice = true;
};
};
};
sops.secrets."services/mautrix/shared_secret" = {};
services.postgresql.ensureDatabases = [
"mautrix_slack"
];
}

View file

@ -0,0 +1,153 @@
{
system,
config,
pkgs,
lib,
...
}:
with lib; let
dataDir = "/var/lib/mautrix-slack";
registrationFile = config.sops.secrets."services/mautrix/slack.yaml".path;
cfg = config.services.mautrix-slack;
settingsFormat = pkgs.formats.yaml {};
settingsFileUnsubstituted = settingsFormat.generate "mautrix-slack-config-unsubstituted.yaml" cfg.settings;
settingsFile = "${dataDir}/config.yaml";
inherit (pkgs) mautrix-slack;
in {
options = {
services.mautrix-slack = {
enable = mkEnableOption "Mautrix-Whatsapp, a Matrix-Whatsapp hybrid puppeting/relaybot bridge";
settings = mkOption rec {
apply = recursiveUpdate default;
inherit (settingsFormat) type;
default = {
appservice = {
address = "http://mautrix-slack.int.chir.rs:29320";
hostname = "0.0.0.0";
port = 29320;
database = {
type = "sqlite";
uri = "sqlite:///${dataDir}/mautrix-telegram.db";
};
as_token = "$AS_TOKEN";
hs_token = "$HS_TOKEN";
};
logging = {
file_name_format = null;
};
};
};
environmentFile = mkOption {
type = types.nullOr types.path;
default = null;
description = ''
File containing environment variables to be passed to the mautrix-telegram service,
in which secret tokens can be specified securely by defining values for
<literal>MAUTRIX_TELEGRAM_APPSERVICE_AS_TOKEN</literal>,
<literal>MAUTRIX_TELEGRAM_APPSERVICE_HS_TOKEN</literal>,
<literal>MAUTRIX_TELEGRAM_TELEGRAM_API_ID</literal>,
<literal>MAUTRIX_TELEGRAM_TELEGRAM_API_HASH</literal> and optionally
<literal>MAUTRIX_TELEGRAM_TELEGRAM_BOT_TOKEN</literal>.
'';
};
};
};
config = mkIf cfg.enable {
systemd.services.mautrix-slack-genregistration = {
description = "Mautrix-slack Registration";
script = ''
# Not all secrets can be passed as environment variable (yet)
# https://github.com/tulir/mautrix-telegram/issues/584
[ -f ${settingsFile} ] && rm -f ${settingsFile}
export AS_TOKEN=$(${pkgs.yq}/bin/yq -r '.as_token' ${registrationFile})
export HS_TOKEN=$(${pkgs.yq}/bin/yq -r '.hs_token' ${registrationFile})
umask 0177
${pkgs.envsubst}/bin/envsubst \
-o ${settingsFile} \
-i ${settingsFileUnsubstituted}
'';
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ReadWritePaths = baseNameOf dataDir;
NoNewPrivileges = true;
MemoryDenyWriteExecute = true;
PrivateDevices = true;
PrivateTmp = true;
ProtectHome = true;
ProtectSystem = "strict";
ProtectControlGroups = true;
RestrictSUIDSGID = true;
RestrictRealtime = true;
LockPersonality = true;
ProtectKernelLogs = true;
ProtectKernelTunables = true;
ProtectHostname = true;
ProtectKernelModules = true;
ProtectClock = true;
SystemCallArchitectures = "native";
SystemCallErrorNumber = "EPERM";
SystemCallFilter = "@system-service";
WorkingDirectory = dataDir;
StateDirectory = baseNameOf dataDir;
UMask = 0117;
User = "mautrix-slack";
Group = "mautrix-slack";
EnvironmentFile = cfg.environmentFile;
};
restartTriggers = [settingsFileUnsubstituted cfg.environmentFile];
};
systemd.services.mautrix-slack = {
description = "Mautrix-slack";
path = with pkgs; [ffmpeg lottieconverter];
wantedBy = ["multi-user.target"];
wants = ["mautrix-slack-genregistration.service"];
after = ["mautrix-slack-genregistration.service"];
serviceConfig = {
Type = "simple";
Restart = "always";
ReadWritePaths = baseNameOf dataDir;
NoNewPrivileges = true;
MemoryDenyWriteExecute = true;
PrivateDevices = true;
PrivateTmp = true;
ProtectHome = true;
ProtectSystem = "strict";
ProtectControlGroups = true;
RestrictSUIDSGID = true;
RestrictRealtime = true;
LockPersonality = true;
ProtectKernelLogs = true;
ProtectKernelTunables = true;
ProtectHostname = true;
ProtectKernelModules = true;
ProtectClock = true;
SystemCallArchitectures = "native";
SystemCallErrorNumber = "EPERM";
SystemCallFilter = "@system-service";
WorkingDirectory = dataDir;
StateDirectory = baseNameOf dataDir;
UMask = 0117;
User = "mautrix-slack";
Group = "mautrix-slack";
EnvironmentFile = cfg.environmentFile;
ExecStart = ''
${mautrix-slack}/bin/mautrix-slack \
--config='${settingsFile}'
'';
};
restartTriggers = [cfg.environmentFile];
};
users.users.mautrix-slack = {
description = "Mautrix Whatsapp bridge";
home = "${dataDir}";
useDefaultShell = true;
group = "mautrix-slack";
isSystemUser = true;
};
users.groups.mautrix-slack = {};
sops.secrets."services/mautrix/slack.yaml".owner = "mautrix-slack";
};
}

View file

@ -11,7 +11,8 @@ services:
signal.yaml: ENC[AES256_GCM,data:8/cn9tIIBhfOLbIHOWKr2I+UG8PcnsYozTuIuyFgkcTCuGemid4hw29KWXahQ/ILtu7e9gVVOYu6fi/bionXKAdyk2bDr7ZC+b4MGaAsLbvKvyZ03Q9aIK8t9JEFTrY9VlhfP3/84ohAoS5P7hnaoO06LFtrApG+0WOoS2TLydlS5e7xuqQxbJkutEi1kmITVTYT21HLdz9Shgmo7s9ZxLQ51kTWVhZBH8ixj4t1BwX7oql+4HCmtEltGUmY31PsINmm3GjKi/D0nuf2oWTpWRCjFkX7wjboP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LqK6ceLFGahlw/eVjaz1GGNG/a+WdbkxSQ=,iv:V4ShNH3jNdMLgHU9xKJ33FUqAG5H9s3hQCFXQznOQx8=,tag:EtoUPsLilcZtG/O+Ai4SkA==,type:str]
doublepuppet.yaml: ENC[AES256_GCM,data:L7WUNSgIoTT+7vYdx34z7+TWBMalPzIHzEA5njYwaJaqpLaPMR5Jx3oFv+TUDzYvs2UKP1DfIJBI1zkm+aMRNE5QOTeMDtZj1AZ07v3ENiPSNCuDaUgSLAdsBPtDIA5rCy+SUxLfeVjfCFs929yrlYyPKbzMcmXhk+otofghGDDDDb9CmwJcvamM4+xqS7pEms5CKy2zkyPD0g5PlMSqGzcYtjRL+qRs/MauKtxSpTBYWPv4lUXEr2iN4guGIJu2kkuKWisM01qYN2SLArAL8WAjHzdPx0LU9Qv9oXdCBTVeNNR5+tK4EQ==,iv:AcQGkdbGc4E14g8xQtDd2PZJR7sIkabelLnx2zOJyO4=,tag:TAg/Lx49l51O0y6IltHICg==,type:str]
hydra:
cache-key: ENC[AES256_GCM,data:CLCu9BTtbIFQ3epWbJYwnj+q7Gnxe/Gs8a53pxiEFObVp9EKMMArNHsvGBIBnuBG4vU6muRw/3EhF3LwDgT/YqVaI7KFKYn0myiTviSQ1hBcWHvTdWnbrlrB0kplBcv4oQ==,iv:kw2me7DIkeq4p+vmgl/bH6yvs6Bn2ifJDh56UT5XkaM=,tag:0ZQITx1NyQ67nyuTM6anCw==,type:str]
gitea_token: ENC[AES256_GCM,data:dEXglNtESY30IOKEmTamv8Ce5w63D5T4AJWJBO4XNC2iv9/me5zOuw==,iv:DYjWgu0oQMmMmTFiULcn2ZTV8bKVGR8bouItsNYL9/4=,tag:+/G9dzBaQ130r66PQYVxzA==,type:str]
@ -61,8 +62,8 @@ sops:
Kytvc1lyRHRrRXRjaEV0V3ZDcUgzVVkKkqr0FcWUCkTYLIXJKuY5/LJX1odVaF4s
P2BLyjXj81078QjKwTyXskFV36uWM70LoVfkxBRTMZO/4O+BCwRpkg==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2024-09-04T19:00:05Z"
mac: ENC[AES256_GCM,data:HHqjMF4qdoGS74XZbXeVqQBzkI18Mz8K0qvZpv0K4cWbRrwsZKkZvwdtYJSzAbv4MX1ZVg1sRavekae3WUEjTkktrZQb0jJ+0xLdBz6kO9uwN28EhzH2mXF/cyTuzuAblhWGmN7PzOHaGd+bRsmD5ylRQn+Lgwag2oykxAM2bcs=,iv:ng5KCTJ/kuLYEXM5B3sNzIj+Y87QjhDnimIfIzoJ0wc=,tag:hWKPfWkfrfO+obyc2POUXw==,type:str]
lastmodified: "2024-09-23T18:25:52Z"
mac: ENC[AES256_GCM,data:x3n8Ldl1PNBRP0PDM0kJRQNRqrDxW6YSLi7RQkuYfnIUYlZjxCzZGMpo0U2VeZVuVwnTsfrz/lzxAgXa/wCDaW1QqazKvifpXHBGmxPvhlTnAMWX9vCuzvlqiHILPp5CfhpFr0koy2gnnV///eCK+83DEiMbFSpEoXrmJv1uJGU=,iv:Fv8mblYlathiDAZaN38XbJGtj8IFQrP4eivkr31O8j4=,tag://xL98HDX4bCfQlUvmGsWw==,type:str]
pgp: []
unencrypted_suffix: _unencrypted
version: 3.9.0