nixpkgs/nixos/modules/services/networking/soju.nix
Jade Lovelace 6c5ab28fce nixos: fix a bunch of services missing dep on network-online.target
This was done by generating a truly hilarious configuration:

rg 'services\.[^.]+\.enable\t' opts-tags | cut -f1 > allonconfig.nix

The following were not tested due to other evaluation errors. They
should probably be manually audited.
services.amule
services.castopod
services.ceph
services.chatgpt-retrieval-plugin
services.clamsmtp
services.clight
services.dante
services.dex
services.discourse
services.dwm-status
services.engelsystem
services.foundationdb
services.frigate
services.frp
services.grocy
services.guacamole-client
services.hedgedoc
services.home-assistant
services.honk
services.imaginary
services.jitsi-meet
services.kerberos_server
services.limesurvey
services.mastodon
services.mediawiki
services.mobilizon
services.moodle
services.mosquitto
services.nextcloud
services.nullmailer
services.patroni
services.pfix-srsd
services.pgpkeyserver-lite
services.postfixadmin
services.roundcube
services.schleuder
services.self-deploy
services.slskd
services.spacecookie
services.statsd
services.step-ca
services.sympa
services.tsmBackup
services.vdirsyncer
services.vikunja
services.yandex-disk
services.zabbixWeb
2024-01-19 00:11:34 -08:00

126 lines
3.4 KiB
Nix

{ 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 (lib.mdDoc "soju");
listen = mkOption {
type = types.listOf types.str;
default = [ ":6697" ];
description = lib.mdDoc ''
Where soju should listen for incoming connections. See the
`listen` directive in
{manpage}`soju(1)`.
'';
};
hostName = mkOption {
type = types.str;
default = config.networking.hostName;
defaultText = literalExpression "config.networking.hostName";
description = lib.mdDoc "Server hostname.";
};
tlsCertificate = mkOption {
type = types.nullOr types.path;
default = null;
example = "/var/host.cert";
description = lib.mdDoc "Path to server TLS certificate.";
};
tlsCertificateKey = mkOption {
type = types.nullOr types.path;
default = null;
example = "/var/host.key";
description = lib.mdDoc "Path to server TLS certificate key.";
};
enableMessageLogging = mkOption {
type = types.bool;
default = true;
description = lib.mdDoc "Whether to enable message logging.";
};
httpOrigins = mkOption {
type = types.listOf types.str;
default = [];
description = lib.mdDoc ''
List of allowed HTTP origins for WebSocket listeners. The parameters are
interpreted as shell patterns, see
{manpage}`glob(7)`.
'';
};
acceptProxyIP = mkOption {
type = types.listOf types.str;
default = [];
description = lib.mdDoc ''
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 = "";
description = lib.mdDoc "Lines added verbatim to the configuration file.";
};
};
###### implementation
config = mkIf cfg.enable {
assertions = [
{
assertion = (cfg.tlsCertificate != null) == (cfg.tlsCertificateKey != null);
message = ''
services.soju.tlsCertificate and services.soju.tlsCertificateKey
must both be specified to enable TLS.
'';
}
];
systemd.services.soju = {
description = "soju IRC bouncer";
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
serviceConfig = {
DynamicUser = true;
Restart = "always";
ExecStart = "${pkgs.soju}/bin/soju -config ${configFile}";
StateDirectory = "soju";
};
};
};
meta.maintainers = with maintainers; [ malte-v ];
}