2023-08-31 01:55:45 +03:00
|
|
|
{ cluster, config, lib, pkgs, depot, ... }:
|
2022-09-18 23:13:06 +03:00
|
|
|
|
|
|
|
let
|
2023-08-31 01:55:45 +03:00
|
|
|
inherit (depot.lib.meta) adminEmail;
|
2022-09-18 23:13:06 +03:00
|
|
|
inherit (cluster) vars;
|
2023-08-31 01:55:45 +03:00
|
|
|
inherit (config.networking) hostName;
|
2022-09-18 23:13:06 +03:00
|
|
|
|
2022-10-22 15:12:37 +03:00
|
|
|
linkGlobalSecure = cluster.config.links.ircSecure;
|
2023-08-31 01:55:45 +03:00
|
|
|
link = cluster.config.hostLinks.${hostName}.irc;
|
|
|
|
linkSecure = cluster.config.hostLinks.${hostName}.ircSecure;
|
|
|
|
otherServers = map mkServer (cluster.config.services.irc.otherNodes.host hostName);
|
2022-09-18 23:13:06 +03:00
|
|
|
otherServerFiles = map (builtins.toFile "ngircd-peer.conf") otherServers;
|
2022-10-22 15:13:59 +03:00
|
|
|
opers = map mkOper vars.ircOpers;
|
2022-09-18 23:13:06 +03:00
|
|
|
|
2022-10-22 15:12:37 +03:00
|
|
|
mkServer = name: let
|
|
|
|
peerLink = cluster.config.hostLinks.${name}.ircSecure;
|
|
|
|
in ''
|
2022-09-18 23:13:06 +03:00
|
|
|
[Server]
|
2023-06-02 22:13:20 +03:00
|
|
|
Name = ${peerLink.hostname}
|
2022-10-22 15:12:37 +03:00
|
|
|
Host = ${peerLink.ipv4}
|
|
|
|
Port = ${peerLink.portStr}
|
2022-09-18 23:13:06 +03:00
|
|
|
MyPassword = @PEER_PASSWORD@
|
|
|
|
PeerPassword = @PEER_PASSWORD@
|
|
|
|
SSLConnect = yes
|
|
|
|
Passive = no
|
|
|
|
'';
|
2022-09-19 00:37:50 +03:00
|
|
|
|
|
|
|
# oper password is irrelevant, mask ensures security thanks to PAM
|
|
|
|
mkOper = name: ''
|
|
|
|
[Operator]
|
|
|
|
Name = ${name}
|
|
|
|
Password = please
|
|
|
|
Mask = *!${name}@*
|
|
|
|
'';
|
2022-09-18 23:13:06 +03:00
|
|
|
|
2023-06-02 22:13:20 +03:00
|
|
|
serverName = linkSecure.hostname;
|
2022-09-18 23:13:06 +03:00
|
|
|
cert = config.security.acme.certs."${serverName}";
|
|
|
|
dh = config.security.dhparams.params.ngircd;
|
|
|
|
in {
|
|
|
|
services.ngircd = {
|
|
|
|
enable = true;
|
|
|
|
config = ''
|
|
|
|
[Global]
|
|
|
|
Name = ${serverName}
|
2023-08-31 01:55:45 +03:00
|
|
|
Info = Private Void IRC - ${hostName}
|
2022-09-18 23:13:06 +03:00
|
|
|
Network = PrivateVoidIRC
|
|
|
|
AdminInfo1 = Private Void Administrators
|
|
|
|
AdminInfo2 = Contact for help
|
|
|
|
AdminEmail = ${adminEmail}
|
|
|
|
Listen = 0.0.0.0
|
|
|
|
Ports = ${link.portStr}
|
|
|
|
|
|
|
|
[SSL]
|
|
|
|
CertFile = ${cert.directory}/fullchain.pem
|
|
|
|
KeyFile = ${cert.directory}/key.pem
|
|
|
|
DHFile = ${dh.path}
|
|
|
|
Ports = ${linkSecure.portStr}
|
|
|
|
|
|
|
|
[Options]
|
|
|
|
IncludeDir = /run/ngircd/secrets
|
|
|
|
AllowedChannelTypes = #
|
|
|
|
CloakHost = %x.cloak.void
|
|
|
|
MorePrivacy = yes
|
|
|
|
PAM = yes
|
|
|
|
PAMIsOptional = yes
|
2022-09-19 00:37:50 +03:00
|
|
|
OperCanUseMode = yes
|
|
|
|
OperChanPAutoOp = yes
|
|
|
|
|
2022-09-19 00:39:37 +03:00
|
|
|
[Channel]
|
|
|
|
Name = #general
|
|
|
|
Topic = General discussions
|
|
|
|
|
2022-09-19 00:37:50 +03:00
|
|
|
${builtins.concatStringsSep "\n" opers}
|
2022-09-18 23:13:06 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
link.port
|
|
|
|
linkSecure.port
|
|
|
|
];
|
|
|
|
security.dhparams = {
|
|
|
|
enable = true;
|
|
|
|
params.ngircd.bits = 2048;
|
|
|
|
};
|
|
|
|
security.acme.certs."${serverName}" = {
|
2023-12-04 20:31:03 +02:00
|
|
|
dnsProvider = "exec";
|
2022-09-18 23:13:06 +03:00
|
|
|
group = "ngircd";
|
|
|
|
reloadServices = [ "ngircd" ];
|
2022-10-22 15:12:37 +03:00
|
|
|
extraDomainNames = [ linkGlobalSecure.ipv4 ];
|
2022-09-18 23:13:06 +03:00
|
|
|
};
|
2022-09-19 00:05:03 +03:00
|
|
|
security.pam.services.ngircd = {
|
|
|
|
text = ''
|
2023-06-11 18:29:04 +03:00
|
|
|
# verify IRC users via IDM
|
|
|
|
auth required ${pkgs.kanidm}/lib/pam_kanidm.so
|
2022-09-19 00:05:03 +03:00
|
|
|
'';
|
|
|
|
};
|
2022-09-18 23:13:06 +03:00
|
|
|
systemd.services.ngircd = {
|
|
|
|
after = [ "acme-finished-${serverName}.target" "dhparams-gen-ngircd.service" ];
|
|
|
|
wants = [ "acme-finished-${serverName}.target" "dhparams-gen-ngircd.service" ];
|
|
|
|
serviceConfig.RuntimeDirectory = "ngircd";
|
|
|
|
preStart = ''
|
|
|
|
install -d -m700 /run/ngircd/secrets
|
|
|
|
for cfg in ${builtins.concatStringsSep " " otherServerFiles}; do
|
|
|
|
install -m600 $cfg /run/ngircd/secrets/
|
2024-07-08 19:53:06 +03:00
|
|
|
${pkgs.replace-secret}/bin/replace-secret '@PEER_PASSWORD@' '${cluster.config.services.irc.secrets.peerKey.path}' /run/ngircd/secrets/$(basename $cfg)
|
2022-09-18 23:13:06 +03:00
|
|
|
done
|
|
|
|
'';
|
|
|
|
};
|
2023-03-06 01:12:00 +02:00
|
|
|
|
|
|
|
consul.services.ngircd = {
|
2023-03-06 17:42:14 +02:00
|
|
|
definition = {
|
2023-03-06 01:12:00 +02:00
|
|
|
name = "irc";
|
|
|
|
address = linkSecure.ipv4;
|
|
|
|
port = linkSecure.port;
|
|
|
|
checks = lib.singleton {
|
|
|
|
interval = "60s";
|
2023-06-02 22:13:20 +03:00
|
|
|
tcp = "${linkSecure.ipv4}:${linkSecure.portStr}";
|
2023-03-06 01:12:00 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-09-18 23:13:06 +03:00
|
|
|
}
|