2024-11-28 16:27:21 +01:00
|
|
|
{ config, pkgs, lib, ... }: let
|
2023-07-12 01:55:42 +02:00
|
|
|
cfg = config.services.matrix-appservice-irc;
|
|
|
|
in {
|
2024-11-28 16:27:21 +01:00
|
|
|
sops = {
|
|
|
|
secrets = {
|
|
|
|
"matrix/bridges/irc/id" = {};
|
|
|
|
"matrix/bridges/irc/hs_token" = {};
|
|
|
|
"matrix/bridges/irc/as_token" = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
templates."matrix-appservice-irc-registration.yml" = {
|
|
|
|
owner = "matrix-appservice-irc";
|
|
|
|
group = "matrix-synapse";
|
|
|
|
mode = "0440";
|
|
|
|
file = let
|
|
|
|
inherit (config.sops) placeholder;
|
|
|
|
in (pkgs.formats.yaml {}).generate "matrix-appservice-irc-registration.yml" {
|
|
|
|
id = placeholder."matrix/bridges/irc/id";
|
|
|
|
hs_token = placeholder."matrix/bridges/irc/hs_token";
|
|
|
|
as_token = placeholder."matrix/bridges/irc/as_token";
|
|
|
|
url = cfg.registrationUrl;
|
|
|
|
sender_localpart = cfg.localpart;
|
|
|
|
"de.sorunome.msc2409.push_ephemeral" = true;
|
|
|
|
protocols = [ "irc" ];
|
|
|
|
namespaces = {
|
|
|
|
aliases = [
|
|
|
|
{
|
|
|
|
exclusive = true;
|
|
|
|
regex = "#lainchanirc_.*:nani\\.wtf";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
exclusive = true;
|
|
|
|
regex = "#liberairc_.*:nani\\.wtf";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
users = [
|
|
|
|
{
|
|
|
|
exclusive = true;
|
|
|
|
regex = "@lainanon_.*:nani\\.wtf";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
exclusive = true;
|
|
|
|
regex = "@liberauser_.*:nani\\.wtf";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
rate_limited = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-22 20:09:30 +02:00
|
|
|
services.matrix-appservice-irc = {
|
|
|
|
enable = true;
|
2023-07-12 01:55:42 +02:00
|
|
|
registrationUrl = "http://localhost:${toString cfg.port}";
|
2022-06-22 20:09:30 +02:00
|
|
|
|
|
|
|
settings = {
|
2023-07-12 01:55:42 +02:00
|
|
|
homeserver = {
|
|
|
|
url = "https://matrix.nani.wtf";
|
|
|
|
domain = "nani.wtf";
|
|
|
|
enablePresence = true;
|
|
|
|
};
|
|
|
|
|
2022-06-22 20:09:30 +02:00
|
|
|
database = {
|
|
|
|
engine = "postgres";
|
2024-11-28 16:27:21 +01:00
|
|
|
# TODO: use unix socket
|
2023-10-06 18:05:38 +02:00
|
|
|
connectionString = "postgres://matrix-appservice-irc:@localhost:${toString config.services.postgresql.port}/matrix-appservice-irc?sslmode=disable";
|
2022-06-22 20:09:30 +02:00
|
|
|
};
|
2023-07-12 01:55:42 +02:00
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
ircService = {
|
|
|
|
mediaProxy.publicUrl = "https://irc-matrix.nani.wtf/media";
|
2023-07-12 01:55:42 +02:00
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
servers = {
|
|
|
|
"irc.libera.chat" = {
|
|
|
|
name = "libera";
|
|
|
|
port = 6697;
|
|
|
|
ssl = true;
|
|
|
|
networkId = "ircLiberaChat";
|
2023-07-12 01:55:42 +02:00
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
botConfig.enable = false;
|
2023-07-12 01:55:42 +02:00
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
dynamicChannels = {
|
|
|
|
enabled = true;
|
|
|
|
createAlias = true;
|
|
|
|
aliasTemplate = "#liberairc_$CHANNEL";
|
|
|
|
published = true;
|
|
|
|
useHomeserverDirectory = true;
|
|
|
|
joinRule = "public";
|
|
|
|
federate = true;
|
2023-07-12 01:55:42 +02:00
|
|
|
};
|
2024-11-28 16:27:21 +01:00
|
|
|
|
|
|
|
matrixClients = {
|
|
|
|
userTemplate = "@liberauser_$NICK";
|
2023-07-12 01:55:42 +02:00
|
|
|
};
|
2024-11-28 16:27:21 +01:00
|
|
|
|
|
|
|
ircClients = {
|
|
|
|
nickTemplate = "$LOCALPART[m]";
|
|
|
|
allowNickChanges = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
membershipLists = {
|
|
|
|
enabled = true;
|
|
|
|
global = {
|
|
|
|
ircToMatrix = {
|
|
|
|
initial = true;
|
|
|
|
incremental = true;
|
|
|
|
};
|
|
|
|
matrixToIrc = {
|
|
|
|
initial = true;
|
|
|
|
incremental = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
permissions."@h7x4:nani.wtf" = "admin";
|
|
|
|
|
|
|
|
# TODO: Port forward
|
|
|
|
ident.enable = true;
|
|
|
|
|
|
|
|
# TODO: Metrics
|
2023-07-12 01:55:42 +02:00
|
|
|
};
|
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
"irc.lainchan.org" = {
|
|
|
|
name = "lainchan";
|
|
|
|
port = 6697;
|
|
|
|
ssl = true;
|
|
|
|
networkId = "ircLainchanOrg";
|
|
|
|
|
|
|
|
botConfig.enable = false;
|
|
|
|
|
|
|
|
dynamicChannels = {
|
|
|
|
enabled = true;
|
|
|
|
createAlias = true;
|
|
|
|
aliasTemplate = "#lainchanirc_$CHANNEL";
|
|
|
|
published = true;
|
|
|
|
useHomeserverDirectory = true;
|
|
|
|
joinRule = "public";
|
|
|
|
federate = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
matrixClients = {
|
|
|
|
userTemplate = "@lainanon_$NICK";
|
|
|
|
};
|
|
|
|
|
|
|
|
ircClients = {
|
|
|
|
nickTemplate = "$LOCALPART[m]";
|
|
|
|
allowNickChanges = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
membershipLists = {
|
|
|
|
enabled = true;
|
|
|
|
global = {
|
|
|
|
ircToMatrix = {
|
|
|
|
initial = true;
|
|
|
|
incremental = true;
|
|
|
|
};
|
|
|
|
matrixToIrc = {
|
|
|
|
initial = true;
|
|
|
|
incremental = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
permissions."@h7x4:nani.wtf" = "admin";
|
2023-07-12 01:55:42 +02:00
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
# TODO: Port forward
|
|
|
|
ident.enable = true;
|
2023-07-12 01:55:42 +02:00
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
# TODO: Metrics
|
|
|
|
};
|
|
|
|
};
|
2023-07-12 01:55:42 +02:00
|
|
|
};
|
2022-06-22 20:09:30 +02:00
|
|
|
};
|
|
|
|
};
|
2023-07-12 01:55:42 +02:00
|
|
|
|
2024-11-28 16:27:21 +01:00
|
|
|
services.matrix-synapse-next.settings.app_service_config_files = [
|
|
|
|
config.sops.templates."matrix-appservice-irc-registration.yml".path
|
|
|
|
];
|
|
|
|
|
2023-07-12 01:55:42 +02:00
|
|
|
systemd.services.matrix-appservice-irc = {
|
2024-11-28 16:27:21 +01:00
|
|
|
enableStrictShellChecks = false;
|
2023-07-12 01:55:42 +02:00
|
|
|
requires = [
|
|
|
|
"matrix-synapse.service"
|
|
|
|
"postgresql.service"
|
|
|
|
];
|
2024-11-28 16:27:21 +01:00
|
|
|
|
|
|
|
serviceConfig.BindReadOnlyPaths = [
|
|
|
|
"${config.sops.templates."matrix-appservice-irc-registration.yml".path}:/var/lib/matrix-appservice-irc/registration.yml"
|
|
|
|
];
|
|
|
|
|
|
|
|
preStart = lib.mkForce ''
|
|
|
|
umask 077
|
|
|
|
# Generate key for crypting passwords
|
|
|
|
if ! [ -f "${cfg.settings.ircService.passwordEncryptionKeyPath}" ]; then
|
|
|
|
${pkgs.openssl}/bin/openssl genpkey \
|
|
|
|
-out "${cfg.settings.ircService.passwordEncryptionKeyPath}" \
|
|
|
|
-outform PEM \
|
|
|
|
-algorithm RSA \
|
|
|
|
-pkeyopt "rsa_keygen_bits:${toString cfg.passwordEncryptionKeyLength}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! [ -f "${cfg.settings.ircService.mediaProxy.signingKeyPath}"]; then
|
|
|
|
${lib.getExe pkgs.nodejs} ${pkgs.matrix-appservice-irc}/lib/generate-signing-key.js > "${cfg.settings.ircService.mediaProxy.signingKeyPath}"
|
|
|
|
fi
|
|
|
|
'';
|
2023-07-12 01:55:42 +02:00
|
|
|
};
|
2022-06-22 20:09:30 +02:00
|
|
|
}
|