|
15 | 15 | usePostgresql && (!(args ? host) || (elem args.host [ "localhost" "127.0.0.1" "::1" ]));
|
16 | 16 | hasWorkers = cfg.workers != { };
|
17 | 17 |
|
| 18 | + listenerSupportsResource = resource: listener: |
| 19 | + lib.any ({ names, ... }: builtins.elem resource names) listener.resources; |
| 20 | + |
| 21 | + clientListener = findFirst |
| 22 | + (listenerSupportsResource "client") |
| 23 | + null |
| 24 | + (cfg.settings.listeners |
| 25 | + ++ concatMap ({ worker_listeners, ... }: worker_listeners) (attrValues cfg.workers)); |
| 26 | + |
18 | 27 | registerNewMatrixUser =
|
19 | 28 | let
|
20 |
| - isIpv6 = x: lib.length (lib.splitString ":" x) > 1; |
21 |
| - listener = |
22 |
| - lib.findFirst ( |
23 |
| - listener: lib.any ( |
24 |
| - resource: lib.any ( |
25 |
| - name: name == "client" |
26 |
| - ) resource.names |
27 |
| - ) listener.resources |
28 |
| - ) (lib.last cfg.settings.listeners) cfg.settings.listeners; |
29 |
| - # FIXME: Handle cases with missing client listener properly, |
30 |
| - # don't rely on lib.last, this will not work. |
| 29 | + isIpv6 = hasInfix ":"; |
31 | 30 |
|
32 | 31 | # add a tail, so that without any bind_addresses we still have a useable address
|
33 |
| - bindAddress = head (listener.bind_addresses ++ [ "127.0.0.1" ]); |
34 |
| - listenerProtocol = if listener.tls |
| 32 | + bindAddress = head (clientListener.bind_addresses ++ [ "127.0.0.1" ]); |
| 33 | + listenerProtocol = if clientListener.tls |
35 | 34 | then "https"
|
36 | 35 | else "http";
|
37 | 36 | in
|
| 37 | + assert assertMsg (clientListener != null) "No client listener found in synapse or one of its workers"; |
38 | 38 | pkgs.writeShellScriptBin "matrix-synapse-register_new_matrix_user" ''
|
39 | 39 | exec ${cfg.package}/bin/register_new_matrix_user \
|
40 | 40 | $@ \
|
|
44 | 44 | "[${bindAddress}]"
|
45 | 45 | else
|
46 | 46 | "${bindAddress}"
|
47 |
| - }:${builtins.toString listener.port}/" |
| 47 | + }:${builtins.toString clientListener.port}/" |
48 | 48 | '';
|
49 | 49 |
|
50 | 50 | defaultExtras = [
|
@@ -937,6 +937,13 @@ in {
|
937 | 937 |
|
938 | 938 | config = mkIf cfg.enable {
|
939 | 939 | assertions = [
|
| 940 | + { |
| 941 | + assertion = clientListener != null; |
| 942 | + message = '' |
| 943 | + At least one listener which serves the `client` resource via HTTP is required |
| 944 | + by synapse in `services.matrix-synapse.settings.listeners` or in one of the workers! |
| 945 | + ''; |
| 946 | + } |
940 | 947 | {
|
941 | 948 | assertion = hasLocalPostgresDB -> config.services.postgresql.enable;
|
942 | 949 | message = ''
|
@@ -969,13 +976,13 @@ in {
|
969 | 976 | (
|
970 | 977 | listener:
|
971 | 978 | listener.port == main.port
|
972 |
| - && (lib.any (resource: builtins.elem "replication" resource.names) listener.resources) |
| 979 | + && listenerSupportsResource "replication" listener |
973 | 980 | && (lib.any (bind: bind == main.host || bind == "0.0.0.0" || bind == "::") listener.bind_addresses)
|
974 | 981 | )
|
975 | 982 | null
|
976 | 983 | cfg.settings.listeners;
|
977 | 984 | in
|
978 |
| - hasWorkers -> (listener != null); |
| 985 | + hasWorkers -> (cfg.settings.instance_map ? main && listener != null); |
979 | 986 | message = ''
|
980 | 987 | Workers for matrix-synapse require setting `services.matrix-synapse.settings.instance_map.main`
|
981 | 988 | to any listener configured in `services.matrix-synapse.settings.listeners` with a `"replication"`
|
|
0 commit comments