2020-08-08 01:01:01 +00:00
|
|
|
|
{ config, lib, pkgs, options, ... }:
|
|
|
|
|
let
|
|
|
|
|
cfg = config.services.biboumi;
|
|
|
|
|
inherit (config.environment) etc;
|
|
|
|
|
rootDir = "/run/biboumi/mnt-root";
|
|
|
|
|
stateDir = "/var/lib/biboumi";
|
|
|
|
|
settingsFile = pkgs.writeText "biboumi.cfg" (
|
2024-08-28 19:19:02 +00:00
|
|
|
|
lib.generators.toKeyValue {
|
2020-08-08 01:01:01 +00:00
|
|
|
|
mkKeyValue = k: v:
|
2024-08-28 19:19:02 +00:00
|
|
|
|
lib.optionalString (v != null) (lib.generators.mkKeyValueDefault {} "=" k v);
|
2020-08-08 01:01:01 +00:00
|
|
|
|
} cfg.settings);
|
|
|
|
|
need_CAP_NET_BIND_SERVICE = cfg.settings.identd_port != 0 && cfg.settings.identd_port < 1024;
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
services.biboumi = {
|
2024-08-28 19:19:02 +00:00
|
|
|
|
enable = lib.mkEnableOption "the Biboumi XMPP gateway to IRC";
|
2020-08-08 01:01:01 +00:00
|
|
|
|
|
2024-08-28 19:19:02 +00:00
|
|
|
|
settings = lib.mkOption {
|
2020-08-08 01:01:01 +00:00
|
|
|
|
description = ''
|
|
|
|
|
See [biboumi 8.5](https://lab.louiz.org/louiz/biboumi/blob/8.5/doc/biboumi.1.rst)
|
|
|
|
|
for documentation.
|
|
|
|
|
'';
|
|
|
|
|
default = {};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
type = lib.types.submodule {
|
|
|
|
|
freeformType = with lib.types;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
(attrsOf (nullOr (oneOf [str int bool]))) // {
|
|
|
|
|
description = "settings option";
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.admin = lib.mkOption {
|
|
|
|
|
type = with lib.types; listOf str;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = [];
|
|
|
|
|
example = ["admin@example.org"];
|
2024-08-28 19:19:02 +00:00
|
|
|
|
apply = lib.concatStringsSep ":";
|
2020-08-08 01:01:01 +00:00
|
|
|
|
description = ''
|
|
|
|
|
The bare JID of the gateway administrator. This JID will have more
|
|
|
|
|
privileges than other standard users, for example some administration
|
|
|
|
|
ad-hoc commands will only be available to that JID.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.ca_file = lib.mkOption {
|
|
|
|
|
type = lib.types.path;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = "/etc/ssl/certs/ca-certificates.crt";
|
|
|
|
|
description = ''
|
|
|
|
|
Specifies which file should be used as the list of trusted CA
|
2022-12-18 00:31:14 +00:00
|
|
|
|
when negotiating a TLS session.
|
2020-08-08 01:01:01 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.db_name = lib.mkOption {
|
|
|
|
|
type = with lib.types; either path str;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = "${stateDir}/biboumi.sqlite";
|
|
|
|
|
description = ''
|
|
|
|
|
The name of the database to use.
|
|
|
|
|
'';
|
|
|
|
|
example = "postgresql://user:secret@localhost";
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.hostname = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
example = "biboumi.example.org";
|
|
|
|
|
description = ''
|
|
|
|
|
The hostname served by the XMPP gateway.
|
|
|
|
|
This domain must be configured in the XMPP server
|
|
|
|
|
as an external component.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.identd_port = lib.mkOption {
|
|
|
|
|
type = lib.types.port;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = 113;
|
|
|
|
|
example = 0;
|
|
|
|
|
description = ''
|
|
|
|
|
The TCP port on which to listen for identd queries.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.log_level = lib.mkOption {
|
|
|
|
|
type = lib.types.ints.between 0 3;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = 1;
|
|
|
|
|
description = ''
|
|
|
|
|
Indicate what type of log messages to write in the logs.
|
|
|
|
|
0 is debug, 1 is info, 2 is warning, 3 is error.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.password = lib.mkOption {
|
|
|
|
|
type = with lib.types; nullOr str;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
description = ''
|
|
|
|
|
The password used to authenticate the XMPP component to your XMPP server.
|
|
|
|
|
This password must be configured in the XMPP server,
|
|
|
|
|
associated with the external component on
|
|
|
|
|
[hostname](#opt-services.biboumi.settings.hostname).
|
|
|
|
|
|
|
|
|
|
Set it to null and use [credentialsFile](#opt-services.biboumi.credentialsFile)
|
|
|
|
|
if you do not want this password to go into the Nix store.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.persistent_by_default = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether all rooms will be persistent by default:
|
|
|
|
|
the value of the “persistent” option in the global configuration of each
|
|
|
|
|
user will be “true”, but the value of each individual room will still
|
|
|
|
|
default to false. This means that a user just needs to change the global
|
|
|
|
|
“persistent” configuration option to false in order to override this.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.policy_directory = lib.mkOption {
|
|
|
|
|
type = lib.types.path;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = "${pkgs.biboumi}/etc/biboumi";
|
2024-08-28 19:19:02 +00:00
|
|
|
|
defaultText = lib.literalExpression ''"''${pkgs.biboumi}/etc/biboumi"'';
|
2020-08-08 01:01:01 +00:00
|
|
|
|
description = ''
|
|
|
|
|
A directory that should contain the policy files,
|
|
|
|
|
used to customize Botan’s behaviour
|
2022-12-18 00:31:14 +00:00
|
|
|
|
when negotiating the TLS connections with the IRC servers.
|
2020-08-08 01:01:01 +00:00
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.port = lib.mkOption {
|
|
|
|
|
type = lib.types.port;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = 5347;
|
|
|
|
|
description = ''
|
|
|
|
|
The TCP port to use to connect to the local XMPP component.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.realname_customization = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = true;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether the users will be able to use
|
|
|
|
|
the ad-hoc commands that lets them configure
|
|
|
|
|
their realname and username.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.realname_from_jid = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = false;
|
|
|
|
|
description = ''
|
|
|
|
|
Whether the realname and username of each biboumi
|
|
|
|
|
user will be extracted from their JID.
|
|
|
|
|
Otherwise they will be set to the nick
|
|
|
|
|
they used to connect to the IRC server.
|
|
|
|
|
'';
|
|
|
|
|
};
|
2024-08-28 19:19:02 +00:00
|
|
|
|
options.xmpp_server_ip = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
default = "127.0.0.1";
|
|
|
|
|
description = ''
|
|
|
|
|
The IP address to connect to the XMPP server on.
|
|
|
|
|
The connection to the XMPP server is unencrypted,
|
|
|
|
|
so the biboumi instance and the server should
|
|
|
|
|
normally be on the same host.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-28 19:19:02 +00:00
|
|
|
|
credentialsFile = lib.mkOption {
|
|
|
|
|
type = lib.types.path;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
description = ''
|
|
|
|
|
Path to a configuration file to be merged with the settings.
|
|
|
|
|
Beware not to surround "=" with spaces when setting biboumi's options in this file.
|
|
|
|
|
Useful to merge a file which is better kept out of the Nix store
|
|
|
|
|
because it contains sensible data like
|
|
|
|
|
[password](#opt-services.biboumi.settings.password).
|
|
|
|
|
'';
|
|
|
|
|
default = "/dev/null";
|
|
|
|
|
example = "/run/keys/biboumi.cfg";
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-28 19:19:02 +00:00
|
|
|
|
openFirewall = lib.mkEnableOption "opening of the identd port in the firewall";
|
2020-08-08 01:01:01 +00:00
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-28 19:19:02 +00:00
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
|
networking.firewall = lib.mkIf (cfg.openFirewall && cfg.settings.identd_port != 0)
|
2020-08-08 01:01:01 +00:00
|
|
|
|
{ allowedTCPPorts = [ cfg.settings.identd_port ]; };
|
|
|
|
|
|
|
|
|
|
systemd.services.biboumi = {
|
|
|
|
|
description = "Biboumi, XMPP to IRC gateway";
|
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "notify";
|
|
|
|
|
# Biboumi supports systemd's watchdog.
|
|
|
|
|
WatchdogSec = 20;
|
|
|
|
|
Restart = "always";
|
|
|
|
|
# Use "+" because credentialsFile may not be accessible to User= or Group=.
|
|
|
|
|
ExecStartPre = [("+" + pkgs.writeShellScript "biboumi-prestart" ''
|
|
|
|
|
set -eux
|
|
|
|
|
cat ${settingsFile} '${cfg.credentialsFile}' |
|
|
|
|
|
install -m 644 /dev/stdin /run/biboumi/biboumi.cfg
|
|
|
|
|
'')];
|
|
|
|
|
ExecStart = "${pkgs.biboumi}/bin/biboumi /run/biboumi/biboumi.cfg";
|
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -USR1 $MAINPID";
|
|
|
|
|
# Firewalls needing opening for output connections can still do that
|
|
|
|
|
# selectively for biboumi with:
|
|
|
|
|
# users.users.biboumi.isSystemUser = true;
|
|
|
|
|
# and, for example:
|
|
|
|
|
# networking.nftables.ruleset = ''
|
|
|
|
|
# add rule inet filter output meta skuid biboumi tcp accept
|
|
|
|
|
# '';
|
|
|
|
|
DynamicUser = true;
|
|
|
|
|
RootDirectory = rootDir;
|
|
|
|
|
RootDirectoryStartOnly = true;
|
|
|
|
|
InaccessiblePaths = [ "-+${rootDir}" ];
|
2024-08-28 19:19:02 +00:00
|
|
|
|
RuntimeDirectory = [ "biboumi" (lib.removePrefix "/run/" rootDir) ];
|
2020-08-08 01:01:01 +00:00
|
|
|
|
RuntimeDirectoryMode = "700";
|
|
|
|
|
StateDirectory = "biboumi";
|
|
|
|
|
StateDirectoryMode = "700";
|
|
|
|
|
MountAPIVFS = true;
|
|
|
|
|
UMask = "0066";
|
|
|
|
|
BindPaths = [
|
|
|
|
|
stateDir
|
|
|
|
|
# This is for Type="notify"
|
|
|
|
|
# See https://github.com/systemd/systemd/issues/3544
|
|
|
|
|
"/run/systemd/notify"
|
|
|
|
|
"/run/systemd/journal/socket"
|
|
|
|
|
];
|
|
|
|
|
BindReadOnlyPaths = [
|
|
|
|
|
builtins.storeDir
|
|
|
|
|
"/etc"
|
|
|
|
|
];
|
|
|
|
|
# The following options are only for optimizing:
|
|
|
|
|
# systemd-analyze security biboumi
|
2024-08-28 19:19:02 +00:00
|
|
|
|
AmbientCapabilities = [ (lib.optionalString need_CAP_NET_BIND_SERVICE "CAP_NET_BIND_SERVICE") ];
|
|
|
|
|
CapabilityBoundingSet = [ (lib.optionalString need_CAP_NET_BIND_SERVICE "CAP_NET_BIND_SERVICE") ];
|
2020-08-08 01:01:01 +00:00
|
|
|
|
# ProtectClock= adds DeviceAllow=char-rtc r
|
|
|
|
|
DeviceAllow = "";
|
|
|
|
|
LockPersonality = true;
|
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
|
PrivateDevices = true;
|
|
|
|
|
PrivateMounts = true;
|
2024-08-28 19:19:02 +00:00
|
|
|
|
PrivateNetwork = lib.mkDefault false;
|
2020-08-08 01:01:01 +00:00
|
|
|
|
PrivateTmp = true;
|
|
|
|
|
# PrivateUsers=true breaks AmbientCapabilities=CAP_NET_BIND_SERVICE
|
|
|
|
|
# See https://bugs.archlinux.org/task/65921
|
|
|
|
|
PrivateUsers = !need_CAP_NET_BIND_SERVICE;
|
|
|
|
|
ProtectClock = true;
|
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
|
ProtectHome = true;
|
|
|
|
|
ProtectHostname = true;
|
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
|
RemoveIPC = true;
|
|
|
|
|
# AF_UNIX is for /run/systemd/notify
|
|
|
|
|
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
|
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
|
RestrictRealtime = true;
|
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
|
SystemCallFilter = [
|
|
|
|
|
"@system-service"
|
|
|
|
|
# Groups in @system-service which do not contain a syscall
|
|
|
|
|
# listed by perf stat -e 'syscalls:sys_enter_*' biboumi biboumi.cfg
|
|
|
|
|
# in tests, and seem likely not necessary for biboumi.
|
|
|
|
|
# To run such a perf in ExecStart=, you have to:
|
|
|
|
|
# - AmbientCapabilities="CAP_SYS_ADMIN"
|
|
|
|
|
# - mount -o remount,mode=755 /sys/kernel/debug/{,tracing}
|
|
|
|
|
"~@aio" "~@chown" "~@ipc" "~@keyring" "~@resources" "~@setuid" "~@timer"
|
|
|
|
|
];
|
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2024-08-28 19:19:02 +00:00
|
|
|
|
meta.maintainers = with lib.maintainers; [ julm ];
|
2020-08-08 01:01:01 +00:00
|
|
|
|
}
|