nixos/murmur: Get rid of global lib expansion (#412693)

authored by Felix Bühler and committed by GitHub 02abb271 b589370d

+99 -127
+99 -127
nixos/modules/services/networking/murmur.nix
··· 5 5 ... 6 6 }: 7 7 8 - with lib; 9 - 10 8 let 11 9 cfg = config.services.murmur; 12 10 forking = cfg.logFile != null; ··· 14 12 database=${cfg.stateDir}/murmur.sqlite 15 13 dbDriver=QSQLITE 16 14 17 - autobanAttempts=${toString cfg.autobanAttempts} 18 - autobanTimeframe=${toString cfg.autobanTimeframe} 19 - autobanTime=${toString cfg.autobanTime} 15 + autobanAttempts=${lib.toString cfg.autobanAttempts} 16 + autobanTimeframe=${lib.toString cfg.autobanTimeframe} 17 + autobanTime=${lib.toString cfg.autobanTime} 20 18 21 - logfile=${optionalString (cfg.logFile != null) cfg.logFile} 22 - ${optionalString forking "pidfile=/run/murmur/murmurd.pid"} 19 + logfile=${lib.optionalString (cfg.logFile != null) cfg.logFile} 20 + ${lib.optionalString forking "pidfile=/run/murmur/murmurd.pid"} 23 21 24 22 welcometext="${cfg.welcometext}" 25 - port=${toString cfg.port} 23 + port=${lib.toString cfg.port} 26 24 27 - ${optionalString (cfg.hostName != "") "host=${cfg.hostName}"} 28 - ${optionalString (cfg.password != "") "serverpassword=${cfg.password}"} 25 + ${lib.optionalString (cfg.hostName != "") "host=${cfg.hostName}"} 26 + ${lib.optionalString (cfg.password != "") "serverpassword=${cfg.password}"} 29 27 30 - bandwidth=${toString cfg.bandwidth} 31 - users=${toString cfg.users} 28 + bandwidth=${lib.toString cfg.bandwidth} 29 + users=${lib.toString cfg.users} 32 30 33 - textmessagelength=${toString cfg.textMsgLength} 34 - imagemessagelength=${toString cfg.imgMsgLength} 35 - allowhtml=${boolToString cfg.allowHtml} 36 - logdays=${toString cfg.logDays} 37 - bonjour=${boolToString cfg.bonjour} 38 - sendversion=${boolToString cfg.sendVersion} 31 + textmessagelength=${lib.toString cfg.textMsgLength} 32 + imagemessagelength=${lib.toString cfg.imgMsgLength} 33 + allowhtml=${lib.boolToString cfg.allowHtml} 34 + logdays=${lib.toString cfg.logDays} 35 + bonjour=${lib.boolToString cfg.bonjour} 36 + sendversion=${lib.boolToString cfg.sendVersion} 39 37 40 - ${optionalString (cfg.registerName != "") "registerName=${cfg.registerName}"} 41 - ${optionalString (cfg.registerPassword != "") "registerPassword=${cfg.registerPassword}"} 42 - ${optionalString (cfg.registerUrl != "") "registerUrl=${cfg.registerUrl}"} 43 - ${optionalString (cfg.registerHostname != "") "registerHostname=${cfg.registerHostname}"} 38 + ${lib.optionalString (cfg.registerName != "") "registerName=${cfg.registerName}"} 39 + ${lib.optionalString (cfg.registerPassword != "") "registerPassword=${cfg.registerPassword}"} 40 + ${lib.optionalString (cfg.registerUrl != "") "registerUrl=${cfg.registerUrl}"} 41 + ${lib.optionalString (cfg.registerHostname != "") "registerHostname=${cfg.registerHostname}"} 44 42 45 - certrequired=${boolToString cfg.clientCertRequired} 46 - ${optionalString (cfg.sslCert != "") "sslCert=${cfg.sslCert}"} 47 - ${optionalString (cfg.sslKey != "") "sslKey=${cfg.sslKey}"} 48 - ${optionalString (cfg.sslCa != "") "sslCA=${cfg.sslCa}"} 43 + certrequired=${lib.boolToString cfg.clientCertRequired} 44 + ${lib.optionalString (cfg.sslCert != "") "sslCert=${cfg.sslCert}"} 45 + ${lib.optionalString (cfg.sslKey != "") "sslKey=${cfg.sslKey}"} 46 + ${lib.optionalString (cfg.sslCa != "") "sslCA=${cfg.sslCa}"} 49 47 50 - ${optionalString (cfg.dbus != null) "dbus=${cfg.dbus}"} 48 + ${lib.optionalString (cfg.dbus != null) "dbus=${cfg.dbus}"} 51 49 52 50 ${cfg.extraConfig} 53 51 ''; 54 52 in 55 53 { 56 - imports = [ 57 - (mkRenamedOptionModule [ "services" "murmur" "welcome" ] [ "services" "murmur" "welcometext" ]) 58 - (mkRemovedOptionModule [ "services" "murmur" "pidfile" ] "Hardcoded to /run/murmur/murmurd.pid now") 59 - ]; 60 - 61 54 options = { 62 55 services.murmur = { 63 - enable = mkOption { 64 - type = types.bool; 65 - default = false; 66 - description = "If enabled, start the Murmur Mumble server."; 67 - }; 56 + enable = lib.mkEnableOption "Mumble server"; 68 57 69 - openFirewall = mkOption { 70 - type = types.bool; 71 - default = false; 72 - description = '' 73 - Open ports in the firewall for the Murmur Mumble server. 74 - ''; 75 - }; 58 + openFirewall = lib.mkEnableOption "opening ports in the firewall for the Mumble server"; 76 59 77 - user = mkOption { 78 - type = types.str; 60 + user = lib.mkOption { 61 + type = lib.types.str; 79 62 default = "murmur"; 80 63 description = '' 81 64 The name of an existing user to use to run the service. ··· 83 66 ''; 84 67 }; 85 68 86 - group = mkOption { 87 - type = types.str; 69 + group = lib.mkOption { 70 + type = lib.types.str; 88 71 default = "murmur"; 89 72 description = '' 90 73 The name of an existing group to use to run the service. ··· 92 75 ''; 93 76 }; 94 77 95 - stateDir = mkOption { 96 - type = types.path; 78 + stateDir = lib.mkOption { 79 + type = lib.types.path; 97 80 default = "/var/lib/murmur"; 98 81 description = '' 99 82 Directory to store data for the server. 100 83 ''; 101 84 }; 102 85 103 - autobanAttempts = mkOption { 104 - type = types.int; 86 + autobanAttempts = lib.mkOption { 87 + type = lib.types.int; 105 88 default = 10; 106 89 description = '' 107 90 Number of attempts a client is allowed to make in ··· 110 93 ''; 111 94 }; 112 95 113 - autobanTimeframe = mkOption { 114 - type = types.int; 96 + autobanTimeframe = lib.mkOption { 97 + type = lib.types.int; 115 98 default = 120; 116 99 description = '' 117 100 Timeframe in which a client can connect without being banned ··· 119 102 ''; 120 103 }; 121 104 122 - autobanTime = mkOption { 123 - type = types.int; 105 + autobanTime = lib.mkOption { 106 + type = lib.types.int; 124 107 default = 300; 125 108 description = "The amount of time an IP ban lasts (in seconds)."; 126 109 }; 127 110 128 - logFile = mkOption { 129 - type = types.nullOr types.path; 111 + logFile = lib.mkOption { 112 + type = lib.types.nullOr lib.types.path; 130 113 default = null; 131 114 example = "/var/log/murmur/murmurd.log"; 132 115 description = "Path to the log file for Murmur daemon. Empty means log to journald."; 133 116 }; 134 117 135 - welcometext = mkOption { 136 - type = types.str; 118 + welcometext = lib.mkOption { 119 + type = lib.types.str; 137 120 default = ""; 138 121 description = "Welcome message for connected clients."; 139 122 }; 140 123 141 - port = mkOption { 142 - type = types.port; 124 + port = lib.mkOption { 125 + type = lib.types.port; 143 126 default = 64738; 144 127 description = "Ports to bind to (UDP and TCP)."; 145 128 }; 146 129 147 - hostName = mkOption { 148 - type = types.str; 130 + hostName = lib.mkOption { 131 + type = lib.types.str; 149 132 default = ""; 150 133 description = "Host to bind to. Defaults binding on all addresses."; 151 134 }; 152 135 153 - package = mkPackageOption pkgs "murmur" { }; 136 + package = lib.mkPackageOption pkgs "murmur" { }; 154 137 155 - password = mkOption { 156 - type = types.str; 138 + password = lib.mkOption { 139 + type = lib.types.str; 157 140 default = ""; 158 141 description = "Required password to join server, if specified."; 159 142 }; 160 143 161 - bandwidth = mkOption { 162 - type = types.int; 144 + bandwidth = lib.mkOption { 145 + type = lib.types.int; 163 146 default = 72000; 164 147 description = '' 165 148 Maximum bandwidth (in bits per second) that clients may send ··· 167 150 ''; 168 151 }; 169 152 170 - users = mkOption { 171 - type = types.int; 153 + users = lib.mkOption { 154 + type = lib.types.int; 172 155 default = 100; 173 156 description = "Maximum number of concurrent clients allowed."; 174 157 }; 175 158 176 - textMsgLength = mkOption { 177 - type = types.int; 159 + textMsgLength = lib.mkOption { 160 + type = lib.types.int; 178 161 default = 5000; 179 162 description = "Max length of text messages. Set 0 for no limit."; 180 163 }; 181 164 182 - imgMsgLength = mkOption { 183 - type = types.int; 165 + imgMsgLength = lib.mkOption { 166 + type = lib.types.int; 184 167 default = 131072; 185 168 description = "Max length of image messages. Set 0 for no limit."; 186 169 }; 187 170 188 - allowHtml = mkOption { 189 - type = types.bool; 171 + allowHtml = lib.mkOption { 172 + type = lib.types.bool; 190 173 default = true; 191 174 description = '' 192 175 Allow HTML in client messages, comments, and channel ··· 194 177 ''; 195 178 }; 196 179 197 - logDays = mkOption { 198 - type = types.int; 180 + logDays = lib.mkOption { 181 + type = lib.types.int; 199 182 default = 31; 200 183 description = '' 201 184 How long to store RPC logs for in the database. Set 0 to ··· 203 186 ''; 204 187 }; 205 188 206 - bonjour = mkOption { 207 - type = types.bool; 208 - default = false; 209 - description = '' 210 - Enable Bonjour auto-discovery, which allows clients over 211 - your LAN to automatically discover Murmur servers. 212 - ''; 213 - }; 189 + bonjour = lib.mkEnableOption "Bonjour auto-discovery, which allows clients over your LAN to automatically discover Mumble servers"; 214 190 215 - sendVersion = mkOption { 216 - type = types.bool; 191 + sendVersion = lib.mkOption { 192 + type = lib.types.bool; 217 193 default = true; 218 194 description = "Send Murmur version in UDP response."; 219 195 }; 220 196 221 - registerName = mkOption { 222 - type = types.str; 197 + registerName = lib.mkOption { 198 + type = lib.types.str; 223 199 default = ""; 224 200 description = '' 225 201 Public server registration name, and also the name of the ··· 228 204 ''; 229 205 }; 230 206 231 - registerPassword = mkOption { 232 - type = types.str; 207 + registerPassword = lib.mkOption { 208 + type = lib.types.str; 233 209 default = ""; 234 210 description = '' 235 211 Public server registry password, used authenticate your ··· 238 214 ''; 239 215 }; 240 216 241 - registerUrl = mkOption { 242 - type = types.str; 217 + registerUrl = lib.mkOption { 218 + type = lib.types.str; 243 219 default = ""; 244 220 description = "URL website for your server."; 245 221 }; 246 222 247 - registerHostname = mkOption { 248 - type = types.str; 223 + registerHostname = lib.mkOption { 224 + type = lib.types.str; 249 225 default = ""; 250 226 description = '' 251 227 DNS hostname where your server can be reached. This is only ··· 255 231 ''; 256 232 }; 257 233 258 - clientCertRequired = mkOption { 259 - type = types.bool; 260 - default = false; 261 - description = "Require clients to authenticate via certificates."; 262 - }; 234 + clientCertRequired = lib.mkEnableOption "requiring clients to authenticate via certificates"; 263 235 264 - sslCert = mkOption { 265 - type = types.str; 236 + sslCert = lib.mkOption { 237 + type = lib.types.str; 266 238 default = ""; 267 239 description = "Path to your SSL certificate."; 268 240 }; 269 241 270 - sslKey = mkOption { 271 - type = types.str; 242 + sslKey = lib.mkOption { 243 + type = lib.types.str; 272 244 default = ""; 273 245 description = "Path to your SSL key."; 274 246 }; 275 247 276 - sslCa = mkOption { 277 - type = types.str; 248 + sslCa = lib.mkOption { 249 + type = lib.types.str; 278 250 default = ""; 279 251 description = "Path to your SSL CA certificate."; 280 252 }; 281 253 282 - extraConfig = mkOption { 283 - type = types.lines; 254 + extraConfig = lib.mkOption { 255 + type = lib.types.lines; 284 256 default = ""; 285 257 description = "Extra configuration to put into murmur.ini."; 286 258 }; 287 259 288 - environmentFile = mkOption { 289 - type = types.nullOr types.path; 260 + environmentFile = lib.mkOption { 261 + type = lib.types.nullOr lib.types.path; 290 262 default = null; 291 - example = literalExpression ''"''${config.services.murmur.stateDir}/murmurd.env"''; 263 + example = lib.literalExpression ''"''${config.services.murmur.stateDir}/murmurd.env"''; 292 264 description = '' 293 265 Environment file as defined in {manpage}`systemd.exec(5)`. 294 266 ··· 311 283 ''; 312 284 }; 313 285 314 - dbus = mkOption { 315 - type = types.enum [ 286 + dbus = lib.mkOption { 287 + type = lib.types.enum [ 316 288 null 317 289 "session" 318 290 "system" ··· 323 295 }; 324 296 }; 325 297 326 - config = mkIf cfg.enable { 327 - users.users.murmur = mkIf (cfg.user == "murmur") { 298 + config = lib.mkIf cfg.enable { 299 + users.users.murmur = lib.mkIf (cfg.user == "murmur") { 328 300 description = "Murmur Service user"; 329 301 home = cfg.stateDir; 330 302 createHome = true; 331 303 uid = config.ids.uids.murmur; 332 304 group = cfg.group; 333 305 }; 334 - users.groups.murmur = mkIf (cfg.group == "murmur") { 306 + users.groups.murmur = lib.mkIf (cfg.group == "murmur") { 335 307 gid = config.ids.gids.murmur; 336 308 }; 337 309 338 - networking.firewall = mkIf cfg.openFirewall { 310 + networking.firewall = lib.mkIf cfg.openFirewall { 339 311 allowedTCPPorts = [ cfg.port ]; 340 312 allowedUDPPorts = [ cfg.port ]; 341 313 }; ··· 353 325 serviceConfig = { 354 326 # murmurd doesn't fork when logging to the console. 355 327 Type = if forking then "forking" else "simple"; 356 - PIDFile = mkIf forking "/run/murmur/murmurd.pid"; 357 - EnvironmentFile = mkIf (cfg.environmentFile != null) cfg.environmentFile; 328 + PIDFile = lib.mkIf forking "/run/murmur/murmurd.pid"; 329 + EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile; 358 330 ExecStart = "${cfg.package}/bin/mumble-server -ini /run/murmur/murmurd.ini"; 359 331 Restart = "always"; 360 332 RuntimeDirectory = "murmur"; ··· 390 362 391 363 # currently not included in upstream package, addition requested at 392 364 # https://github.com/mumble-voip/mumble/issues/6078 393 - services.dbus.packages = mkIf (cfg.dbus == "system") [ 365 + services.dbus.packages = lib.mkIf (cfg.dbus == "system") [ 394 366 (pkgs.writeTextFile { 395 367 name = "murmur-dbus-policy"; 396 368 text = '' ··· 432 404 r /run/murmur/murmurd.ini, 433 405 r ${configFile}, 434 406 '' 435 - + optionalString (cfg.logFile != null) '' 407 + + lib.optionalString (cfg.logFile != null) '' 436 408 rw ${cfg.logFile}, 437 409 '' 438 - + optionalString (cfg.sslCert != "") '' 410 + + lib.optionalString (cfg.sslCert != "") '' 439 411 r ${cfg.sslCert}, 440 412 '' 441 - + optionalString (cfg.sslKey != "") '' 413 + + lib.optionalString (cfg.sslKey != "") '' 442 414 r ${cfg.sslKey}, 443 415 '' 444 - + optionalString (cfg.sslCa != "") '' 416 + + lib.optionalString (cfg.sslCa != "") '' 445 417 r ${cfg.sslCa}, 446 418 '' 447 - + optionalString (cfg.dbus != null) '' 419 + + lib.optionalString (cfg.dbus != null) '' 448 420 dbus bus=${cfg.dbus} 449 421 '' 450 422 + ''