Nix configurations for my homelab
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

ejabberd: modify config for running without a reverse proxy

yemou 62b2743e 181b90ef

+137 -181
+1 -70
modules/services/caddy/xmpp.nix
··· 1 - { config, ... }: 1 + { ... }: 2 2 { 3 - networking.firewall.allowedTCPPorts = [ 4 - 5222 5 - 5223 6 - 5269 7 - 5270 8 - 5443 9 - 7777 10 - ]; 11 - 12 - garden.caddy.layer4 = '' 13 - [::]:5222 { 14 - route { 15 - proxy { 16 - proxy_protocol v2 17 - upstream ${config.garden.info.network.lily.netbird-ip}:5222 18 - } 19 - } 20 - } 21 - [::]:5223 { 22 - route { 23 - tls { 24 - connection_policy { 25 - alpn xmpp-client 26 - default_sni butwho.org 27 - } 28 - } 29 - proxy { 30 - proxy_protocol v2 31 - upstream ${config.garden.info.network.lily.netbird-ip}:5223 32 - } 33 - } 34 - } 35 - [::]:5269 { 36 - route { 37 - proxy { 38 - proxy_protocol v2 39 - upstream ${config.garden.info.network.lily.netbird-ip}:5269 40 - } 41 - } 42 - } 43 - [::]:5270 { 44 - route { 45 - tls { 46 - connection_policy { 47 - alpn xmpp-server 48 - default_sni butwho.org 49 - } 50 - } 51 - proxy { 52 - proxy_protocol v2 53 - upstream ${config.garden.info.network.lily.netbird-ip}:5270 54 - } 55 - } 56 - } 57 - [::]:7777 { 58 - route { 59 - proxy ${config.garden.info.network.lily.netbird-ip}:7777 60 - } 61 - } 62 - ''; 63 - 64 3 services.caddy.virtualHosts = { 65 - # TODO: I may need to use the proxy protocol (For http connections) in order for ejabberd's logs to show the 66 - # correct IP address. 67 - # It may not actually matter, it seems like ejabberd supports X-Forwarded-For which caddy sends, its just 68 - # that the logs don't reflect this. 69 - "butwho.org:5443".extraConfig = '' 70 - encode 71 - reverse_proxy ${config.garden.info.network.lily.netbird-ip}:5280 72 - ''; 73 4 "butwho.org".extraConfig = '' 74 5 header /.well-known/host-meta Access-Control-Allow-Origin * 75 6 header /.well-known/host-meta Content-Type text/xml
+136 -111
modules/services/ejabberd.nix
··· 16 16 } 17 17 ]; 18 18 19 - sops = { 20 - secrets."eturnal/secret".sopsFile = ../../secrets/dali.yaml; 21 - templates.ejabberd-mod_stun_disco = { 22 - owner = "ejabberd"; 23 - group = "ejabberd"; 24 - content = lib.generators.toYAML { } { 25 - modules = { 26 - mod_stun_disco = { 27 - secret = config.sops.placeholder."eturnal/secret"; 28 - services = [ 29 - { 30 - host = config.garden.info.network.dandelion.ipv4; 31 - port = 3478; 32 - type = "stun"; 33 - transport = "udp"; 34 - restricted = false; 35 - } 36 - { 37 - host = config.garden.info.network.dandelion.ipv4; 38 - port = 3478; 39 - type = "turn"; 40 - transport = "udp"; 41 - restricted = true; 42 - } 43 - { 44 - host = config.garden.info.network.dandelion.ipv6; 45 - port = 3478; 46 - type = "stun"; 47 - transport = "udp"; 48 - restricted = false; 49 - } 50 - { 51 - host = config.garden.info.network.dandelion.ipv6; 52 - port = 3478; 53 - type = "turn"; 54 - transport = "udp"; 55 - restricted = true; 56 - } 57 - { 58 - host = config.garden.info.network.dandelion.ipv4; 59 - port = 3478; 60 - type = "stun"; 61 - transport = "tcp"; 62 - restricted = false; 63 - } 64 - { 65 - host = config.garden.info.network.dandelion.ipv4; 66 - port = 3478; 67 - type = "turn"; 68 - transport = "tcp"; 69 - restricted = true; 70 - } 71 - { 72 - host = config.garden.info.network.dandelion.ipv6; 73 - port = 3478; 74 - type = "stun"; 75 - transport = "tcp"; 76 - restricted = false; 77 - } 78 - { 79 - host = config.garden.info.network.dandelion.ipv6; 80 - port = 3478; 81 - type = "turn"; 82 - transport = "tcp"; 83 - restricted = true; 84 - } 85 - { 86 - host = "butwho.org"; 87 - port = 5349; 88 - type = "stuns"; 89 - transport = "tcp"; 90 - restricted = false; 91 - } 92 - { 93 - host = "butwho.org"; 94 - port = 5349; 95 - type = "turns"; 96 - transport = "tcp"; 97 - restricted = true; 98 - } 99 - ]; 100 - }; 101 - }; 102 - }; 103 - }; 19 + networking.firewall = { 20 + allowedTCPPorts = [ 21 + # 1883 # MQTT 22 + 5222 # Jabberd/XMPP client connections 23 + 5223 # Jabberd client SSL 24 + 5269 # Jabber/XMPP incoming server connections 25 + 5270 # Jabberd server SSL 26 + # 5280 # HTTP for Web Admin 27 + # NOTE: ejabberd doesn't support either HTTP/2 or HTTP/3, consider running caddy infront of ejabberd 28 + 5349 # STUN/TURN 29 + 5443 # HTTPS for Web Admin and File Upload 30 + 7777 # mod_proxy65 31 + ]; 32 + allowedUDPPorts = [ 33 + 3478 # STUN/TURN 34 + ]; 35 + allowedUDPPortRanges = [ 36 + { 37 + from = 49152; 38 + to = 65535; 39 + } 40 + ]; 104 41 }; 105 42 106 - networking.firewall.interfaces.${config.services.netbird.clients.homelab.interface}.allowedTCPPorts = [ 107 - # 1883 # MQTT 108 - 5222 # Jabberd/XMPP client connections 109 - 5223 # Jabberd client SSL 110 - 5269 # Jabber/XMPP incoming server connections 111 - 5270 # Jabberd server SSL 112 - 5280 # HTTP for Web Admin 113 - # 5443 # HTTPS for Web Admin and File Upload (terminated by caddy) 114 - 7777 # mod_proxy65 115 - ]; 116 - 117 43 services.postgresql = { 118 44 ensureDatabases = [ "ejabberd" ]; 119 45 ensureUsers = [ ··· 135 61 lib.generators.toYAML { } { 136 62 hosts = [ "butwho.org" ]; 137 63 include_config_file = [ 138 - config.sops.templates.ejabberd-mod_stun_disco.path 139 64 # NOTE: When using the yaml generators provided by nixos, the numeric keys are strings (nix doesn't support 140 65 # numeric keys). ejabberd doesn't attempt to convert the string to an integer so it doesn't recognize the 141 66 # numeric key causing a configuration error. ··· 158 83 acme.auto = false; 159 84 certfiles = [ 160 85 # butwho.org 161 - "/mnt/certs/butwho.org/butwho.org.crt" 162 - "/mnt/certs/butwho.org/butwho.org.key" 86 + "/var/ssl/butwho.org/butwho.org.crt" 87 + "/var/ssl/butwho.org/butwho.org.key" 163 88 164 89 # muc.butwho.org 165 - "/mnt/certs/muc.butwho.org/muc.butwho.org.crt" 166 - "/mnt/certs/muc.butwho.org/muc.butwho.org.key" 90 + "/var/ssl/muc.butwho.org/muc.butwho.org.crt" 91 + "/var/ssl/muc.butwho.org/muc.butwho.org.key" 167 92 168 93 # proxy.butwho.org 169 - "/mnt/certs/proxy.butwho.org/proxy.butwho.org.crt" 170 - "/mnt/certs/proxy.butwho.org/proxy.butwho.org.key" 94 + "/var/ssl/proxy.butwho.org/proxy.butwho.org.crt" 95 + "/var/ssl/proxy.butwho.org/proxy.butwho.org.key" 171 96 172 97 # pubsub.butwho.org 173 - "/mnt/certs/pubsub.butwho.org/pubsub.butwho.org.crt" 174 - "/mnt/certs/pubsub.butwho.org/pubsub.butwho.org.key" 98 + "/var/ssl/pubsub.butwho.org/pubsub.butwho.org.crt" 99 + "/var/ssl/pubsub.butwho.org/pubsub.butwho.org.key" 175 100 176 101 # upload.butwho.org 177 - "/mnt/certs/upload.butwho.org/upload.butwho.org.crt" 178 - "/mnt/certs/upload.butwho.org/upload.butwho.org.key" 102 + "/var/ssl/upload.butwho.org/upload.butwho.org.crt" 103 + "/var/ssl/upload.butwho.org/upload.butwho.org.key" 179 104 ]; 180 105 trusted_proxies = [ config.garden.info.network.dandelion.netbird-ip ]; 181 106 listen = [ ··· 187 112 shaper = "c2s_shaper"; 188 113 access = "c2s"; 189 114 starttls_required = true; 190 - use_proxy_protocol = true; 191 115 } 192 116 { 193 117 port = 5223; ··· 197 121 shaper = "c2s_shaper"; 198 122 access = "c2s"; 199 123 allow_unencrypted_sasl2 = true; 200 - use_proxy_protocol = true; 201 124 } 202 125 { 203 126 port = 5269; ··· 205 128 module = "ejabberd_s2s_in"; 206 129 max_stanza_size = 524288; 207 130 shaper = "s2s_shaper"; 208 - use_proxy_protocol = true; 209 131 } 210 132 { 211 133 port = 5270; ··· 213 135 module = "ejabberd_s2s_in"; 214 136 max_stanza_size = 524288; 215 137 shaper = "s2s_shaper"; 216 - use_proxy_protocol = true; 217 138 } 218 139 { 219 140 port = 5280; 220 141 ip = "::"; 221 142 module = "ejabberd_http"; 143 + request_handlers = { 144 + "/admin" = "ejabberd_web_admin"; 145 + }; 146 + } 147 + { 148 + port = 5443; 149 + ip = "::"; 150 + module = "ejabberd_http"; 151 + tls = true; 222 152 request_handlers = { 223 153 "/admin" = "ejabberd_web_admin"; 224 154 "/api" = "mod_http_api"; ··· 227 157 "/upload" = "mod_http_upload"; 228 158 "/ws" = "ejabberd_http_ws"; 229 159 }; 160 + } 161 + { 162 + port = 3478; 163 + transport = "udp"; 164 + module = "ejabberd_stun"; 165 + use_turn = true; 166 + turn_min_port = 49152; 167 + turn_max_port = 65535; 168 + turn_ipv4_address = config.garden.info.network.lily.ipv4; 169 + turn_ipv6_address = config.garden.info.network.lily.ipv6; 170 + } 171 + { 172 + port = 5349; 173 + transport = "tcp"; 174 + module = "ejabberd_stun"; 175 + use_turn = true; 176 + tls = true; 177 + turn_min_port = 49152; 178 + turn_max_port = 65535; 179 + turn_ipv4_address = config.garden.info.network.lily.ipv4; 180 + turn_ipv6_address = config.garden.info.network.lily.ipv6; 230 181 } 231 182 # NOTE: This (mqtt) may be more useful when I do more IoT stuff but it doesn't seem to have much use for 232 183 # internet messaging at the moment ··· 477 428 # NOTE: I cannot setup mod_sip since it doesn't support SCRAM passwords 478 429 # mod_sip = { }; 479 430 mod_stream_mgmt.resend_on_timeout = "if_offline"; 431 + mod_stun_disco = { 432 + services = [ 433 + { 434 + host = config.garden.info.network.lily.ipv4; 435 + port = 3478; 436 + type = "stun"; 437 + transport = "udp"; 438 + restricted = false; 439 + } 440 + { 441 + host = config.garden.info.network.lily.ipv4; 442 + port = 3478; 443 + type = "turn"; 444 + transport = "udp"; 445 + restricted = true; 446 + } 447 + { 448 + host = config.garden.info.network.lily.ipv6; 449 + port = 3478; 450 + type = "stun"; 451 + transport = "udp"; 452 + restricted = false; 453 + } 454 + { 455 + host = config.garden.info.network.lily.ipv6; 456 + port = 3478; 457 + type = "turn"; 458 + transport = "udp"; 459 + restricted = true; 460 + } 461 + { 462 + host = config.garden.info.network.lily.ipv4; 463 + port = 3478; 464 + type = "stun"; 465 + transport = "tcp"; 466 + restricted = false; 467 + } 468 + { 469 + host = config.garden.info.network.lily.ipv4; 470 + port = 3478; 471 + type = "turn"; 472 + transport = "tcp"; 473 + restricted = true; 474 + } 475 + { 476 + host = config.garden.info.network.lily.ipv6; 477 + port = 3478; 478 + type = "stun"; 479 + transport = "tcp"; 480 + restricted = false; 481 + } 482 + { 483 + host = config.garden.info.network.lily.ipv6; 484 + port = 3478; 485 + type = "turn"; 486 + transport = "tcp"; 487 + restricted = true; 488 + } 489 + { 490 + host = "butwho.org"; 491 + port = 5349; 492 + type = "stuns"; 493 + transport = "tcp"; 494 + restricted = false; 495 + } 496 + { 497 + host = "butwho.org"; 498 + port = 5349; 499 + type = "turns"; 500 + transport = "tcp"; 501 + restricted = true; 502 + } 503 + ]; 504 + }; 480 505 mod_time = { }; 481 506 mod_vcard = { }; 482 507 mod_vcard_xupdate = { };