1 { config, lib, pkgs, ... }:
4 type = with lib.types; attrsOf (oneOf [ bool int str ]);
5 generate = name: attrs:
6 pkgs.writeText name (lib.strings.concatStringsSep "\n"
7 (lib.attrsets.mapAttrsToList
8 (key: value: "${key}=${builtins.toJSON value}") attrs));
13 services.uhub = lib.mkOption {
15 description = "Uhub ADC hub instances";
16 type = lib.types.attrsOf (lib.types.submodule {
19 enable = lib.mkEnableOption "hub instance" // { default = true; };
21 enableTLS = lib.mkOption {
22 type = lib.types.bool;
24 description = "Whether to enable TLS support.";
27 settings = lib.mkOption {
28 inherit (settingsFormat) type;
30 Configuration of uhub.
31 See https://www.uhub.org/doc/config.php for a list of options.
35 server_bind_addr = "any";
37 hub_name = "My Public Hub";
38 hub_description = "Yet another ADC hub";
43 plugins = lib.mkOption {
44 description = "Uhub plugin configuration.";
45 type = with lib.types;
48 plugin = lib.mkOption {
50 example = lib.literalExpression
51 "$${pkgs.uhub}/plugins/mod_auth_sqlite.so";
52 description = "Path to plugin file.";
54 settings = lib.mkOption {
55 description = "Settings specific to this plugin.";
56 type = with types; attrsOf str;
57 example = { file = "/etc/uhub/users.db"; };
71 hubs = lib.attrsets.filterAttrs (_: cfg: cfg.enable) config.services.uhub;
74 environment.etc = lib.attrsets.mapAttrs' (name: cfg:
76 settings' = cfg.settings // {
77 tls_enable = cfg.enableTLS;
78 file_plugins = pkgs.writeText "uhub-plugins.conf"
79 (lib.strings.concatStringsSep "\n" (map ({ plugin, settings }:
83 (lib.attrsets.mapAttrsToList (key: value: "${key}=${value}")
88 name = "uhub/${name}.conf";
89 value.source = settingsFormat.generate "uhub-${name}.conf" settings';
92 systemd.services = lib.attrsets.mapAttrs' (name: cfg: {
93 name = "uhub-${name}";
94 value = let pkg = pkgs.uhub.override { tlsSupport = cfg.enableTLS; };
96 description = "high performance peer-to-peer hub for the ADC network";
97 after = [ "network.target" ];
98 wantedBy = [ "multi-user.target" ];
99 reloadIfChanged = true;
102 ExecStart = "${pkg}/bin/uhub -c /etc/uhub/${name}.conf -L";
103 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
106 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
107 CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";