nixpkgs/nixos/modules/services/misc/uhub.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

144 lines
3.9 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
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
{
options = {
services.uhub = lib.mkOption {
default = { };
description = "Uhub ADC hub instances";
type = lib.types.attrsOf (
lib.types.submodule {
options = {
enable = lib.mkEnableOption "hub instance" // {
default = true;
};
enableTLS = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to enable TLS support.";
};
settings = lib.mkOption {
inherit (settingsFormat) type;
description = ''
Configuration of uhub.
See https://www.uhub.org/doc/config.php for a list of options.
'';
default = { };
example = {
server_bind_addr = "any";
server_port = 1511;
hub_name = "My Public Hub";
hub_description = "Yet another ADC hub";
max_users = 150;
};
};
plugins = lib.mkOption {
description = "Uhub plugin configuration.";
type =
with lib.types;
listOf (submodule {
options = {
plugin = lib.mkOption {
type = path;
example = lib.literalExpression "$${pkgs.uhub}/plugins/mod_auth_sqlite.so";
description = "Path to plugin file.";
};
settings = lib.mkOption {
description = "Settings specific to this plugin.";
type = with types; attrsOf str;
example = {
file = "/etc/uhub/users.db";
};
};
};
});
default = [ ];
};
};
}
);
};
};
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 }:
''plugin ${plugin} "${
toString (lib.attrsets.mapAttrsToList (key: value: "${key}=${value}") settings)
}"''
) cfg.plugins
)
);
};
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;
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
};
};
}) hubs;
};
}