···
1
+
{ config, lib, pkgs, ... }:
7
+
cfg = config.services.uhub;
9
+
uhubPkg = pkgs.uhub.override { tlsSupport = cfg.enableTLS; };
12
+
+ optionalString cfg.plugins.authSqlite.enable ''
13
+
plugin ${uhubPkg.mod_auth_sqlite}/mod_auth_sqlite.so "file=${cfg.plugins.authSqlite.file}"
15
+
+ optionalString cfg.plugins.logging.enable ''
16
+
plugin ${uhubPkg.mod_logging}/mod_logging.so ${if cfg.plugins.logging.syslog then "syslog=true" else "file=${cfg.plugins.logging.file}"}
18
+
+ optionalString cfg.plugins.welcome.enable ''
19
+
plugin ${uhubPkg.mod_welcome}/mod_welcome.so "motd=${pkgs.writeText "motd.txt" cfg.plugins.welcome.motd} rules=${pkgs.writeText "rules.txt" cfg.plugins.welcome.rules}"
21
+
+ optionalString cfg.plugins.history.enable ''
22
+
plugin ${uhubPkg.mod_chat_history}/mod_chat_history.so "history_max=${toString cfg.plugins.history.max} history_default=${toString cfg.plugins.history.default} history_connect=${toString cfg.plugins.history.connect}"
25
+
uhubConfigFile = pkgs.writeText "uhub.conf" ''
26
+
file_acl=${pkgs.writeText "users.conf" cfg.aclConfig}
27
+
file_plugins=${pkgs.writeText "plugins.conf" pluginConfig}
28
+
server_bind_addr=${cfg.address}
29
+
server_port=${toString cfg.port}
30
+
${lib.optionalString cfg.enableTLS "tls_enable=yes"}
44
+
description = "Whether to enable the uhub ADC hub.";
50
+
description = "TCP port to bind the hub to.";
53
+
address = mkOption {
54
+
type = types.string;
56
+
description = "Address to bind the hub to.";
59
+
enableTLS = mkOption {
62
+
description = "Whether to enable TLS support.";
65
+
hubConfig = mkOption {
68
+
description = "Contents of uhub configuration file.";
71
+
aclConfig = mkOption {
74
+
description = "Contents of user ACL configuration file.";
83
+
description = "Whether to enable the Sqlite authentication database plugin";
86
+
type = types.string;
87
+
example = "/var/db/uhub-users";
88
+
description = "Path to user database. Use the uhub-passwd utility to create the database and add/remove users.";
96
+
description = "Whether to enable the logging plugin.";
99
+
type = types.string;
101
+
description = "Path of log file.";
103
+
syslog = mkOption {
106
+
description = "If true then the system log is used instead of writing to file.";
111
+
enable = mkOption {
114
+
description = "Whether to enable the welcome plugin.";
118
+
type = types.lines;
120
+
Welcome message displayed to clients after connecting
121
+
and with the <literal>!motd</literal> command.
126
+
type = types.lines;
128
+
Rules message, displayed to clients with the <literal>!rules</literal> command.
134
+
enable = mkOption {
137
+
description = "Whether to enable the history plugin.";
142
+
description = "The maximum number of messages to keep in history";
144
+
default = mkOption {
147
+
description = "When !history is provided without arguments, then this default number of messages are returned.";
149
+
connect = mkOption {
152
+
description = "The number of chat history messages to send when users connect (0 = do not send any history).";
161
+
config = mkIf cfg.enable {
164
+
extraUsers = singleton {
166
+
uid = config.ids.uids.uhub;
168
+
extraGroups = singleton {
170
+
gid = config.ids.gids.uhub;
174
+
systemd.services.uhub = {
175
+
description = "high performance peer-to-peer hub for the ADC network";
176
+
after = [ "network.target" ];
177
+
wantedBy = [ "multi-user.target" ];
180
+
ExecStart = "${uhubPkg}/bin/uhub -c ${uhubConfigFile} -u uhub -g uhub -L";
181
+
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";