2021-05-20 19:34:20 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.soju;
|
|
|
|
stateDir = "/var/lib/soju";
|
|
|
|
listenCfg = concatMapStringsSep "\n" (l: "listen ${l}") cfg.listen;
|
|
|
|
tlsCfg = optionalString (cfg.tlsCertificate != null)
|
|
|
|
"tls ${cfg.tlsCertificate} ${cfg.tlsCertificateKey}";
|
|
|
|
logCfg = optionalString cfg.enableMessageLogging
|
|
|
|
"log fs ${stateDir}/logs";
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "soju.conf" ''
|
|
|
|
${listenCfg}
|
|
|
|
hostname ${cfg.hostName}
|
|
|
|
${tlsCfg}
|
|
|
|
db sqlite3 ${stateDir}/soju.db
|
|
|
|
${logCfg}
|
|
|
|
http-origin ${concatStringsSep " " cfg.httpOrigins}
|
|
|
|
accept-proxy-ip ${concatStringsSep " " cfg.acceptProxyIP}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options.services.soju = {
|
|
|
|
enable = mkEnableOption "soju";
|
|
|
|
|
|
|
|
listen = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ":6697" ];
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-05-20 19:34:20 +02:00
|
|
|
Where soju should listen for incoming connections. See the
|
2022-08-05 19:39:00 +02:00
|
|
|
`listen` directive in
|
|
|
|
{manpage}`soju(1)`.
|
2021-05-20 19:34:20 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
hostName = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = config.networking.hostName;
|
2021-11-26 01:16:05 +01:00
|
|
|
defaultText = literalExpression "config.networking.hostName";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Server hostname.";
|
2021-05-20 19:34:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
tlsCertificate = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
2022-08-02 17:22:06 +02:00
|
|
|
default = null;
|
2021-05-20 19:34:20 +02:00
|
|
|
example = "/var/host.cert";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Path to server TLS certificate.";
|
2021-05-20 19:34:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
tlsCertificateKey = mkOption {
|
|
|
|
type = types.nullOr types.path;
|
2022-08-02 17:22:06 +02:00
|
|
|
default = null;
|
2021-05-20 19:34:20 +02:00
|
|
|
example = "/var/host.key";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Path to server TLS certificate key.";
|
2021-05-20 19:34:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enableMessageLogging = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Whether to enable message logging.";
|
2021-05-20 19:34:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
httpOrigins = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-05-20 19:34:20 +02:00
|
|
|
List of allowed HTTP origins for WebSocket listeners. The parameters are
|
|
|
|
interpreted as shell patterns, see
|
2022-08-05 19:39:00 +02:00
|
|
|
{manpage}`glob(7)`.
|
2021-05-20 19:34:20 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
acceptProxyIP = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
Allow the specified IPs to act as a proxy. Proxys have the ability to
|
|
|
|
overwrite the remote and local connection addresses (via the X-Forwarded-\*
|
|
|
|
HTTP header fields). The special name "localhost" accepts the loopback
|
|
|
|
addresses 127.0.0.0/8 and ::1/128. By default, all IPs are rejected.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Lines added verbatim to the configuration file.";
|
2021-05-20 19:34:20 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-08-02 17:22:06 +02:00
|
|
|
assertions = [
|
|
|
|
{
|
|
|
|
assertion = (cfg.tlsCertificate != null) == (cfg.tlsCertificateKey != null);
|
|
|
|
message = ''
|
|
|
|
services.soju.tlsCertificate and services.soju.tlsCertificateKey
|
|
|
|
must both be specified to enable TLS.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-05-20 19:34:20 +02:00
|
|
|
systemd.services.soju = {
|
|
|
|
description = "soju IRC bouncer";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
DynamicUser = true;
|
|
|
|
Restart = "always";
|
|
|
|
ExecStart = "${pkgs.soju}/bin/soju -config ${configFile}";
|
|
|
|
StateDirectory = "soju";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ malvo ];
|
|
|
|
}
|