1 { config, lib, pkgs, ... }:
7 type = with lib.types; attrsOf (oneOf [ bool int str ]);
8 generate = name: attrs:
9 pkgs.writeText name (lib.strings.concatStringsSep "\n"
10 (lib.attrsets.mapAttrsToList
11 (key: value: "${key}=${builtins.toJSON value}") attrs));
16 services.uhub = mkOption {
18 description = lib.mdDoc "Uhub ADC hub instances";
19 type = types.attrsOf (types.submodule {
22 enable = mkEnableOption (lib.mdDoc "hub instance") // { default = true; };
24 enableTLS = mkOption {
27 description = lib.mdDoc "Whether to enable TLS support.";
31 inherit (settingsFormat) type;
32 description = lib.mdDoc ''
33 Configuration of uhub.
34 See https://www.uhub.org/doc/config.php for a list of options.
38 server_bind_addr = "any";
40 hub_name = "My Public Hub";
41 hub_description = "Yet another ADC hub";
47 description = lib.mdDoc "Uhub plugin configuration.";
53 example = literalExpression
54 "$${pkgs.uhub}/plugins/mod_auth_sqlite.so";
55 description = lib.mdDoc "Path to plugin file.";
58 description = lib.mdDoc "Settings specific to this plugin.";
59 type = with types; attrsOf str;
60 example = { file = "/etc/uhub/users.db"; };
74 hubs = lib.attrsets.filterAttrs (_: cfg: cfg.enable) config.services.uhub;
77 environment.etc = lib.attrsets.mapAttrs' (name: cfg:
79 settings' = cfg.settings // {
80 tls_enable = cfg.enableTLS;
81 file_plugins = pkgs.writeText "uhub-plugins.conf"
82 (lib.strings.concatStringsSep "\n" (map ({ plugin, settings }:
86 (lib.attrsets.mapAttrsToList (key: value: "${key}=${value}")
91 name = "uhub/${name}.conf";
92 value.source = settingsFormat.generate "uhub-${name}.conf" settings';
95 systemd.services = lib.attrsets.mapAttrs' (name: cfg: {
96 name = "uhub-${name}";
97 value = let pkg = pkgs.uhub.override { tlsSupport = cfg.enableTLS; };
99 description = "high performance peer-to-peer hub for the ADC network";
100 after = [ "network.target" ];
101 wantedBy = [ "multi-user.target" ];
102 reloadIfChanged = true;
105 ExecStart = "${pkg}/bin/uhub -c /etc/uhub/${name}.conf -L";
106 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
109 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
110 CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";