commit 85d753886e67361471378ea3a2dc193282b2ff27
parent 36d02a6dcdae4821fa041cb33a0195be168a7dd8
Author: mtmn <miro@haravara.org>
Date: Mon, 27 Apr 2026 21:40:35 +0200
chore: update shirts and soju
Diffstat:
4 files changed, 109 insertions(+), 20 deletions(-)
diff --git a/hosts/nixaran/configuration.nix b/hosts/nixaran/configuration.nix
Binary files differ.
diff --git a/hosts/work/default.nix b/hosts/work/default.nix
Binary files differ.
diff --git a/modules/services/soju.nix b/modules/services/soju.nix
@@ -1,39 +1,138 @@
{
config,
lib,
+ pkgs,
...
}: let
cfg = config.services.haravara.soju;
+ stateDir = "/var/lib/soju";
+ runtimeDir = "/run/soju";
+
+ listen = cfg.listen ++ lib.optional cfg.adminSocket.enable "unix+admin://${runtimeDir}/admin";
+ listenCfg = lib.concatMapStringsSep "\n" (l: "listen ${l}") listen;
+ tlsCfg = lib.optionalString (
+ cfg.tlsCertificate != null
+ ) "tls ${cfg.tlsCertificate} ${cfg.tlsCertificateKey}";
+ logCfg = lib.optionalString cfg.enableMessageLogging "message-store fs ${stateDir}/logs";
+
+ configFile = pkgs.writeText "soju.conf" ''
+ ${listenCfg}
+ hostname ${cfg.hostName}
+ ${tlsCfg}
+ ${logCfg}
+ http-origin ${lib.concatStringsSep " " cfg.httpOrigins}
+ accept-proxy-ip ${lib.concatStringsSep " " cfg.acceptProxyIP}
+
+ ${cfg.extraConfig}
+ '';
+
+ sojuctl = pkgs.writeShellScriptBin "sojuctl" ''
+ exec ${lib.getExe' cfg.package "sojuctl"} --config ${configFile} "$@"
+ '';
in {
options.services.haravara.soju = {
enable = lib.mkEnableOption "soju IRC bouncer";
+
+ package = lib.mkPackageOption pkgs "soju" {};
+
domain = lib.mkOption {
type = lib.types.str;
description = "Domain for the soju WebSocket endpoint (proxied by Caddy)";
};
+
port = lib.mkOption {
type = lib.types.port;
default = 6669;
description = "Internal port for the soju WebSocket listener";
};
- httpOrigins = lib.mkOption {
- type = lib.types.listOf lib.types.str;
- default = [];
- description = "Allowed HTTP origins for WebSocket connections (e.g. gamja domain)";
- };
+
authLabel = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "The auth snippet to import in Caddy";
};
+
+ listen = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = [":6697"];
+ description = "Where soju should listen for incoming connections.";
+ };
+
+ hostName = lib.mkOption {
+ type = lib.types.str;
+ default = cfg.domain;
+ defaultText = lib.literalExpression "config.services.haravara.soju.domain";
+ description = "Server hostname.";
+ };
+
+ tlsCertificate = lib.mkOption {
+ type = lib.types.nullOr lib.types.path;
+ default = null;
+ description = "Path to server TLS certificate.";
+ };
+
+ tlsCertificateKey = lib.mkOption {
+ type = lib.types.nullOr lib.types.path;
+ default = null;
+ description = "Path to server TLS certificate key.";
+ };
+
+ enableMessageLogging = lib.mkOption {
+ type = lib.types.bool;
+ default = true;
+ description = "Whether to enable message logging.";
+ };
+
+ adminSocket.enable = lib.mkOption {
+ type = lib.types.bool;
+ default = true;
+ description = "Listen for admin connections from sojuctl at /run/soju/admin.";
+ };
+
+ httpOrigins = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = [];
+ description = "List of allowed HTTP origins for WebSocket listeners.";
+ };
+
+ acceptProxyIP = lib.mkOption {
+ type = lib.types.listOf lib.types.str;
+ default = ["localhost"];
+ description = "Allow the specified IPs to act as a proxy.";
+ };
+
+ extraConfig = lib.mkOption {
+ type = lib.types.lines;
+ default = "";
+ description = "Lines added verbatim to the generated configuration file.";
+ };
};
config = lib.mkIf cfg.enable {
- services.soju = {
- enable = true;
- listen = ["ws+insecure://127.0.0.1:${toString cfg.port}"];
- acceptProxyIP = ["localhost"];
- inherit (cfg) httpOrigins;
+ assertions = [
+ {
+ assertion = (cfg.tlsCertificate != null) == (cfg.tlsCertificateKey != null);
+ message = "services.haravara.soju.tlsCertificate and services.haravara.soju.tlsCertificateKey must both be specified to enable TLS.";
+ }
+ ];
+
+ environment.systemPackages = [sojuctl];
+
+ systemd.services.soju = {
+ description = "soju IRC bouncer";
+ wantedBy = ["multi-user.target"];
+ wants = ["network-online.target"];
+ after = ["network-online.target"];
+ documentation = ["man:soju(1)"];
+ serviceConfig = {
+ DynamicUser = true;
+ Restart = "always";
+ ExecStart = "${lib.getExe' cfg.package "soju"} -config ${configFile}";
+ ExecReload = "${lib.getExe' pkgs.coreutils "kill"} -HUP $MAINPID";
+ StateDirectory = "soju";
+ RuntimeDirectory = "soju";
+ WorkingDirectory = stateDir;
+ };
};
services.caddy.virtualHosts."${cfg.domain}".extraConfig = ''
diff --git a/modules/services/static.nix b/modules/services/static.nix
@@ -22,11 +22,6 @@ in {
default = false;
description = "Whether to redirect / to the base domain";
};
- hasShortener = lib.mkOption {
- type = lib.types.bool;
- default = false;
- description = "Whether to handle /s/ shortener proxy";
- };
extraConfig = lib.mkOption {
type = lib.types.lines;
default = "";
@@ -50,12 +45,7 @@ in {
services.caddy.virtualHosts =
lib.mapAttrs (domain: opt: {
extraConfig =
- lib.optionalString opt.hasShortener ''
- handle /s/* {
- reverse_proxy localhost:8721
- }
''
- + ''
handle {
root * /var/lib/haravara/static/${opt.dir}
file_server