Skip to content

Commit 23139ff

Browse files
committed
nixos/doc/matrix-synapse: refactor
* Linkify all service options used in the code-examples. * Demonstrated the use of `riot-web.override {}`. * Moved the example how to configure a postgresql-database for `matrix-synapse` to this document from the 20.03 release-notes. (cherry picked from commit 849e168)
1 parent ba6271a commit 23139ff

4 files changed

Lines changed: 66 additions & 55 deletions

File tree

nixos/doc/manual/configuration/configuration.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
<xi:include href="xfce.xml" />
2222
<xi:include href="networking.xml" />
2323
<xi:include href="linux-kernel.xml" />
24-
<xi:include href="matrix.xml" />
2524
<xi:include href="../generated/modules.xml" xpointer="xpointer(//section[@id='modules']/*)" />
2625
<xi:include href="profiles.xml" />
2726
<xi:include href="kubernetes.xml" />

nixos/doc/manual/release-notes/rl-2003.xml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,21 +1004,10 @@ auth required pam_succeed_if.so uid >= 1000 quiet
10041004
}</programlisting>
10051005
</para></listitem>
10061006
<listitem><para>If you deploy a fresh <package>matrix-synapse</package>, you need to configure
1007-
the database yourself. An example for this can be found in <literal>&lt;nixpkgs/nixos/tests/matrix-synapse.nix&gt;</literal>:
1008-
<programlisting>{ ... }: {
1009-
services.matrix-synapse = {
1010-
<link linkend="opt-services.matrix-synapse.enable">enable</link> = true;
1011-
/* and all the other config you've defined here */
1012-
};
1013-
<link linkend="opt-services.postgresql.enable">services.postgresql.enable</link> = true;
1014-
<link linkend="opt-services.postgresql.initialScript">services.postgresql.initialScript</link> = ''
1015-
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';
1016-
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"
1017-
TEMPLATE template0
1018-
LC_COLLATE = "C"
1019-
LC_CTYPE = "C";
1020-
'';
1021-
}</programlisting>
1007+
the database yourself (e.g. by using the
1008+
<link linkend="opt-services.postgresql.initialScript">services.postgresql.initialScript</link>
1009+
option). An example for this can be found in the
1010+
<link linkend="module-services-matrix">documentation of the Matrix module</link>.
10221011
</para></listitem>
10231012
<listitem><para>If you initially deployed your <package>matrix-synapse</package> on
10241013
<literal>nixos-unstable</literal> <emphasis>after</emphasis> the <literal>19.09</literal>-release,

nixos/modules/services/misc/matrix-synapse.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ ${cfg.extraConfig}
113113
'';
114114

115115
hasLocalPostgresDB = let args = cfg.database_args; in
116-
usePostgresql && (!(args ? host) || (elem args.host [ "localhost" "127.0.0.1" ]));
116+
usePostgresql && (!(args ? host) || (elem args.host [ "localhost" "127.0.0.1" "::1" ]));
117117
in {
118118
options = {
119119
services.matrix-synapse = {
@@ -721,4 +721,6 @@ in {
721721
'')
722722
];
723723

724+
meta.doc = ./matrix-synapse.xml;
725+
724726
}

nixos/doc/manual/configuration/matrix.xml renamed to nixos/modules/services/misc/matrix-synapse.xml

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,35 @@ let
4040
in join config.networking.hostName config.networking.domain;
4141
in {
4242
networking = {
43-
hostName = "myhostname";
44-
domain = "example.org";
43+
<link linkend="opt-networking.hostName">hostName</link> = "myhostname";
44+
<link linkend="opt-networking.domain">domain</link> = "example.org";
4545
};
46-
networking.firewall.allowedTCPPorts = [ 80 443 ];
46+
<link linkend="opt-networking.firewall.allowedTCPPorts">networking.firewall.allowedTCPPorts</link> = [ 80 443 ];
47+
48+
<link linkend="opt-services.postgresql.enable">services.postgresql.enable</link> = true;
49+
<link linkend="opt-services.postgresql.initialScript">services.postgresql.initialScript</link> = ''
50+
CREATE ROLE "matrix-synapse" WITH LOGIN PASSWORD 'synapse';
51+
CREATE DATABASE "matrix-synapse" WITH OWNER "matrix-synapse"
52+
TEMPLATE template0
53+
LC_COLLATE = "C"
54+
LC_CTYPE = "C";
55+
'';
4756

4857
services.nginx = {
49-
enable = true;
58+
<link linkend="opt-services.nginx.enable">enable</link> = true;
5059
# only recommendedProxySettings and recommendedGzipSettings are strictly required,
5160
# but the rest make sense as well
52-
recommendedTlsSettings = true;
53-
recommendedOptimisation = true;
54-
recommendedGzipSettings = true;
55-
recommendedProxySettings = true;
61+
<link linkend="opt-services.nginx.recommendedTlsSettings">recommendedTlsSettings</link> = true;
62+
<link linkend="opt-services.nginx.recommendedOptimisation">recommendedOptimisation</link> = true;
63+
<link linkend="opt-services.nginx.recommendedGzipSettings">recommendedGzipSettings</link> = true;
64+
<link linkend="opt-services.nginx.recommendedProxySettings">recommendedProxySettings</link> = true;
5665

57-
virtualHosts = {
66+
<link linkend="opt-services.nginx.virtualHosts">virtualHosts</link> = {
5867
# This host section can be placed on a different host than the rest,
5968
# i.e. to delegate from the host being accessible as ${config.networking.domain}
6069
# to another host actually running the Matrix homeserver.
6170
"${config.networking.domain}" = {
62-
locations."= /.well-known/matrix/server".extraConfig =
71+
<link linkend="opt-services.nginx.virtualHosts._name_.locations._name_.extraConfig">locations."= /.well-known/matrix/server".extraConfig</link> =
6372
let
6473
# use 443 instead of the default 8448 port to unite
6574
# the client-server and server-server port for simplicity
@@ -68,7 +77,7 @@ in {
6877
add_header Content-Type application/json;
6978
return 200 '${builtins.toJSON server}';
7079
'';
71-
locations."= /.well-known/matrix/client".extraConfig =
80+
<link linkend="opt-services.nginx.virtualHosts._name_.locations._name_.extraConfig">locations."= /.well-known/matrix/client".extraConfig</link> =
7281
let
7382
client = {
7483
"m.homeserver" = { "base_url" = "https://${fqdn}"; };
@@ -84,34 +93,37 @@ in {
8493

8594
# Reverse proxy for Matrix client-server and server-server communication
8695
${fqdn} = {
87-
enableACME = true;
88-
forceSSL = true;
96+
<link linkend="opt-services.nginx.virtualHosts._name_.enableACME">enableACME</link> = true;
97+
<link linkend="opt-services.nginx.virtualHosts._name_.forceSSL">forceSSL</link> = true;
8998

9099
# Or do a redirect instead of the 404, or whatever is appropriate for you.
91100
# But do not put a Matrix Web client here! See the Riot Web section below.
92-
locations."/".extraConfig = ''
101+
<link linkend="opt-services.nginx.virtualHosts._name_.locations._name_.extraConfig">locations."/".extraConfig</link> = ''
93102
return 404;
94103
'';
95104

96105
# forward all Matrix API calls to the synapse Matrix homeserver
97106
locations."/_matrix" = {
98-
proxyPass = "http://[::1]:8008"; # without a trailing /
107+
<link linkend="opt-services.nginx.virtualHosts._name_.locations._name_.proxyPass">proxyPass</link> = "http://[::1]:8008"; # without a trailing /
99108
};
100109
};
101110
};
102111
};
103112
services.matrix-synapse = {
104-
enable = true;
105-
server_name = config.networking.domain;
106-
listeners = [
113+
<link linkend="opt-services.matrix-synapse.enable">enable</link> = true;
114+
<link linkend="opt-services.matrix-synapse.server_name">server_name</link> = config.networking.domain;
115+
<link linkend="opt-services.matrix-synapse.listeners">listeners</link> = [
107116
{
108-
port = 8008;
109-
bind_address = "::1";
110-
type = "http";
111-
tls = false;
112-
x_forwarded = true;
113-
resources = [
114-
{ names = [ "client" "federation" ]; compress = false; }
117+
<link linkend="opt-services.matrix-synapse.listeners._.port">port</link> = 8008;
118+
<link linkend="opt-services.matrix-synapse.listeners._.bind_address">bind_address</link> = "::1";
119+
<link linkend="opt-services.matrix-synapse.listeners._.type">type</link> = "http";
120+
<link linkend="opt-services.matrix-synapse.listeners._.tls">tls</link> = false;
121+
<link linkend="opt-services.matrix-synapse.listeners._.x_forwarded">x_forwarded</link> = true;
122+
<link linkend="opt-services.matrix-synapse.listeners._.resources">resources</link> = [
123+
{
124+
<link linkend="opt-services.matrix-synapse.listeners._.resources._.names">names</link> = [ "client" "federation" ];
125+
<link linkend="opt-services.matrix-synapse.listeners._.resources._.compress">compress</link> = false;
126+
}
115127
];
116128
}
117129
];
@@ -135,10 +147,10 @@ in {
135147

136148
<para>
137149
If you want to run a server with public registration by anybody, you can
138-
then enable <option>services.matrix-synapse.enable_registration =
139-
true;</option>. Otherwise, or you can generate a registration secret with
150+
then enable <literal><link linkend="opt-services.matrix-synapse.enable_registration">services.matrix-synapse.enable_registration</link> =
151+
true;</literal>. Otherwise, or you can generate a registration secret with
140152
<command>pwgen -s 64 1</command> and set it with
141-
<option>services.matrix-synapse.registration_shared_secret</option>. To
153+
<option><link linkend="opt-services.matrix-synapse.registration_shared_secret">services.matrix-synapse.registration_shared_secret</link></option>. To
142154
create a new user or admin, run the following after you have set the secret
143155
and have rebuilt NixOS:
144156
<screen>
@@ -154,8 +166,8 @@ Success!
154166
<literal>@your-username:example.org</literal>. Note that the registration
155167
secret ends up in the nix store and therefore is world-readable by any user
156168
on your machine, so it makes sense to only temporarily activate the
157-
<option>registration_shared_secret</option> option until a better solution
158-
for NixOS is in place.
169+
<link linkend="opt-services.matrix-synapse.registration_shared_secret">registration_shared_secret</link>
170+
option until a better solution for NixOS is in place.
159171
</para>
160172
</section>
161173
<section xml:id="module-services-matrix-riot-web">
@@ -177,15 +189,24 @@ Success!
177189
Matrix Now!</link> for a list of existing clients and their supported
178190
featureset.
179191
<programlisting>
180-
services.nginx.virtualHosts."riot.${fqdn}" = {
181-
enableACME = true;
182-
forceSSL = true;
183-
serverAliases = [
184-
"riot.${config.networking.domain}"
185-
];
192+
{
193+
services.nginx.virtualHosts."riot.${fqdn}" = {
194+
<link linkend="opt-services.nginx.virtualHosts._name_.enableACME">enableACME</link> = true;
195+
<link linkend="opt-services.nginx.virtualHosts._name_.forceSSL">forceSSL</link> = true;
196+
<link linkend="opt-services.nginx.virtualHosts._name_.serverAliases">serverAliases</link> = [
197+
"riot.${config.networking.domain}"
198+
];
186199

187-
root = pkgs.riot-web;
188-
};
200+
<link linkend="opt-services.nginx.virtualHosts._name_.root">root</link> = pkgs.riot-web.override {
201+
conf = {
202+
default_server_config."m.homeserver" = {
203+
"base_url" = "${config.networking.domain}";
204+
"server_name" = "${fqdn}";
205+
};
206+
};
207+
};
208+
};
209+
}
189210
</programlisting>
190211
</para>
191212

0 commit comments

Comments
 (0)