2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2021-08-11 14:56:57 +00:00
|
|
|
settingsFormat = {
|
|
|
|
type = with lib.types; attrsOf (oneOf [ bool int str ]);
|
|
|
|
generate = name: attrs:
|
|
|
|
pkgs.writeText name (lib.strings.concatStringsSep "\n"
|
|
|
|
(lib.attrsets.mapAttrsToList
|
|
|
|
(key: value: "${key}=${builtins.toJSON value}") attrs));
|
|
|
|
};
|
|
|
|
in {
|
2020-04-24 23:36:52 +00:00
|
|
|
options = {
|
|
|
|
|
2021-08-11 14:56:57 +00:00
|
|
|
services.uhub = mkOption {
|
|
|
|
default = { };
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Uhub ADC hub instances";
|
2021-08-11 14:56:57 +00:00
|
|
|
type = types.attrsOf (types.submodule {
|
|
|
|
options = {
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "hub instance") // { default = true; };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-08-11 14:56:57 +00:00
|
|
|
enableTLS = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to enable TLS support.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-08-11 14:56:57 +00:00
|
|
|
settings = mkOption {
|
|
|
|
inherit (settingsFormat) type;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2021-08-11 14:56:57 +00:00
|
|
|
Configuration of uhub.
|
|
|
|
See https://www.uhub.org/doc/config.php for a list of options.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
2021-08-11 14:56:57 +00:00
|
|
|
default = { };
|
|
|
|
example = {
|
|
|
|
server_bind_addr = "any";
|
|
|
|
server_port = 1511;
|
|
|
|
hub_name = "My Public Hub";
|
|
|
|
hub_description = "Yet another ADC hub";
|
|
|
|
max_users = 150;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-08-11 14:56:57 +00:00
|
|
|
plugins = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Uhub plugin configuration.";
|
2021-08-11 14:56:57 +00:00
|
|
|
type = with types;
|
|
|
|
listOf (submodule {
|
|
|
|
options = {
|
|
|
|
plugin = mkOption {
|
|
|
|
type = path;
|
2021-10-06 13:57:05 +00:00
|
|
|
example = literalExpression
|
2021-08-11 14:56:57 +00:00
|
|
|
"$${pkgs.uhub}/plugins/mod_auth_sqlite.so";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Path to plugin file.";
|
2021-08-11 14:56:57 +00:00
|
|
|
};
|
|
|
|
settings = mkOption {
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Settings specific to this plugin.";
|
2021-08-11 14:56:57 +00:00
|
|
|
type = with types; attrsOf str;
|
|
|
|
example = { file = "/etc/uhub/users.db"; };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
default = [ ];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-08-11 14:56:57 +00:00
|
|
|
};
|
|
|
|
});
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-08-11 14:56:57 +00:00
|
|
|
config = let
|
|
|
|
hubs = lib.attrsets.filterAttrs (_: cfg: cfg.enable) config.services.uhub;
|
|
|
|
in {
|
|
|
|
|
|
|
|
environment.etc = lib.attrsets.mapAttrs' (name: cfg:
|
|
|
|
let
|
|
|
|
settings' = cfg.settings // {
|
|
|
|
tls_enable = cfg.enableTLS;
|
|
|
|
file_plugins = pkgs.writeText "uhub-plugins.conf"
|
|
|
|
(lib.strings.concatStringsSep "\n" (map ({ plugin, settings }:
|
2022-06-16 17:23:12 +00:00
|
|
|
''
|
|
|
|
plugin ${plugin} "${
|
|
|
|
toString
|
|
|
|
(lib.attrsets.mapAttrsToList (key: value: "${key}=${value}")
|
|
|
|
settings)
|
|
|
|
}"'') cfg.plugins));
|
2021-08-11 14:56:57 +00:00
|
|
|
};
|
|
|
|
in {
|
|
|
|
name = "uhub/${name}.conf";
|
|
|
|
value.source = settingsFormat.generate "uhub-${name}.conf" settings';
|
|
|
|
}) hubs;
|
|
|
|
|
|
|
|
systemd.services = lib.attrsets.mapAttrs' (name: cfg: {
|
|
|
|
name = "uhub-${name}";
|
|
|
|
value = let pkg = pkgs.uhub.override { tlsSupport = cfg.enableTLS; };
|
|
|
|
in {
|
|
|
|
description = "high performance peer-to-peer hub for the ADC network";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
reloadIfChanged = true;
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "notify";
|
|
|
|
ExecStart = "${pkg}/bin/uhub -c /etc/uhub/${name}.conf -L";
|
|
|
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
|
|
|
DynamicUser = true;
|
2022-06-16 17:23:12 +00:00
|
|
|
|
|
|
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
|
|
|
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
|
2021-08-11 14:56:57 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2021-08-11 14:56:57 +00:00
|
|
|
}) hubs;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|