at 17.09-beta 5.5 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.uhub; 8 9 uhubPkg = pkgs.uhub.override { tlsSupport = cfg.enableTLS; }; 10 11 pluginConfig = "" 12 + optionalString cfg.plugins.authSqlite.enable '' 13 plugin ${uhubPkg.mod_auth_sqlite}/mod_auth_sqlite.so "file=${cfg.plugins.authSqlite.file}" 14 '' 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}"} 17 '' 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}" 20 '' 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}" 23 ''; 24 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"} 31 ${cfg.hubConfig} 32 ''; 33 34in 35 36{ 37 options = { 38 39 services.uhub = { 40 41 enable = mkOption { 42 type = types.bool; 43 default = false; 44 description = "Whether to enable the uhub ADC hub."; 45 }; 46 47 port = mkOption { 48 type = types.int; 49 default = 1511; 50 description = "TCP port to bind the hub to."; 51 }; 52 53 address = mkOption { 54 type = types.string; 55 default = "any"; 56 description = "Address to bind the hub to."; 57 }; 58 59 enableTLS = mkOption { 60 type = types.bool; 61 default = false; 62 description = "Whether to enable TLS support."; 63 }; 64 65 hubConfig = mkOption { 66 type = types.lines; 67 default = ""; 68 description = "Contents of uhub configuration file."; 69 }; 70 71 aclConfig = mkOption { 72 type = types.lines; 73 default = ""; 74 description = "Contents of user ACL configuration file."; 75 }; 76 77 plugins = { 78 79 authSqlite = { 80 enable = mkOption { 81 type = types.bool; 82 default = false; 83 description = "Whether to enable the Sqlite authentication database plugin"; 84 }; 85 file = mkOption { 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."; 89 }; 90 }; 91 92 logging = { 93 enable = mkOption { 94 type = types.bool; 95 default = false; 96 description = "Whether to enable the logging plugin."; 97 }; 98 file = mkOption { 99 type = types.string; 100 default = ""; 101 description = "Path of log file."; 102 }; 103 syslog = mkOption { 104 type = types.bool; 105 default = false; 106 description = "If true then the system log is used instead of writing to file."; 107 }; 108 }; 109 110 welcome = { 111 enable = mkOption { 112 type = types.bool; 113 default = false; 114 description = "Whether to enable the welcome plugin."; 115 }; 116 motd = mkOption { 117 default = ""; 118 type = types.lines; 119 description = '' 120 Welcome message displayed to clients after connecting 121 and with the <literal>!motd</literal> command. 122 ''; 123 }; 124 rules = mkOption { 125 default = ""; 126 type = types.lines; 127 description = '' 128 Rules message, displayed to clients with the <literal>!rules</literal> command. 129 ''; 130 }; 131 }; 132 133 history = { 134 enable = mkOption { 135 type = types.bool; 136 default = false; 137 description = "Whether to enable the history plugin."; 138 }; 139 max = mkOption { 140 type = types.int; 141 default = 200; 142 description = "The maximum number of messages to keep in history"; 143 }; 144 default = mkOption { 145 type = types.int; 146 default = 10; 147 description = "When !history is provided without arguments, then this default number of messages are returned."; 148 }; 149 connect = mkOption { 150 type = types.int; 151 default = 5; 152 description = "The number of chat history messages to send when users connect (0 = do not send any history)."; 153 }; 154 }; 155 156 }; 157 }; 158 159 }; 160 161 config = mkIf cfg.enable { 162 163 users = { 164 extraUsers = singleton { 165 name = "uhub"; 166 uid = config.ids.uids.uhub; 167 }; 168 extraGroups = singleton { 169 name = "uhub"; 170 gid = config.ids.gids.uhub; 171 }; 172 }; 173 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" ]; 178 serviceConfig = { 179 Type = "notify"; 180 ExecStart = "${uhubPkg}/bin/uhub -c ${uhubConfigFile} -u uhub -g uhub -L"; 181 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID"; 182 }; 183 }; 184 }; 185 186}