@@ -9,11 +9,15 @@ let
99 mkListener = l: ''{port: ${toString l.port}, bind_address: "${l.bind_address}", type: ${l.type}, tls: ${fromBool l.tls}, x_forwarded: ${fromBool l.x_forwarded}, resources: [${concatStringsSep "," (map mkResource l.resources)}]}'';
1010 fromBool = x: if x then "true" else "false";
1111 configFile = pkgs.writeText "homeserver.yaml" ''
12+${optionalString (cfg.tls_certificate_path != null) ''
1213tls_certificate_path: "${cfg.tls_certificate_path}"
14+''}
1315${optionalString (cfg.tls_private_key_path != null) ''
1416tls_private_key_path: "${cfg.tls_private_key_path}"
1517''}
18+${optionalString (cfg.tls_dh_params_path != null) ''
1619tls_dh_params_path: "${cfg.tls_dh_params_path}"
20+''}
1721no_tls: ${fromBool cfg.no_tls}
1822${optionalString (cfg.bind_port != null) ''
1923bind_port: ${toString cfg.bind_port}
@@ -146,8 +150,9 @@ in {
146150 '';
147151 };
148152 tls_certificate_path = mkOption {
149− type = types.str;
150− default = "/var/lib/matrix-synapse/homeserver.tls.crt";
153+ type = types.nullOr types.str;
154+ default = null;
155+ example = "/var/lib/matrix-synapse/homeserver.tls.crt";
151156 description = ''
152157 PEM encoded X509 certificate for TLS.
153158 You can replace the self-signed certificate that synapse
@@ -158,16 +163,17 @@ in {
158163 };
159164 tls_private_key_path = mkOption {
160165 type = types.nullOr types.str;
161− default = "/var/lib/matrix-synapse/homeserver.tls.key";
162− example = null;
166+ default = null;
167+ example = "/var/lib/matrix-synapse/homeserver.tls.key";
163168 description = ''
164169 PEM encoded private key for TLS. Specify null if synapse is not
165170 speaking TLS directly.
166171 '';
167172 };
168173 tls_dh_params_path = mkOption {
169− type = types.str;
170− default = "/var/lib/matrix-synapse/homeserver.tls.dh";
174+ type = types.nullOr types.str;
175+ default = null;
176+ example = "/var/lib/matrix-synapse/homeserver.tls.dh";
171177 description = ''
172178 PEM dh parameters for ephemeral keys
173179 '';
@@ -557,12 +563,10 @@ in {
557563 after = [ "network.target" ];
558564 wantedBy = [ "multi-user.target" ];
559565 preStart = ''
560− if ! test -e /var/lib/matrix-synapse; then
561− mkdir -p /var/lib/matrix-synapse
562− chmod 700 /var/lib/matrix-synapse
563− chown -R matrix-synapse:matrix-synapse /var/lib/matrix-synapse
564− ${cfg.package}/bin/homeserver --config-path ${configFile} --keys-directory /var/lib/matrix-synapse/ --generate-keys
565− fi
566+ ${cfg.package}/bin/homeserver \
567+ --config-path ${configFile} \
568+ --keys-directory /var/lib/matrix-synapse \
569+ --generate-keys
566570 '';
567571 serviceConfig = {
568572 Type = "simple";
@@ -570,7 +574,7 @@ in {
570574 Group = "matrix-synapse";
571575 WorkingDirectory = "/var/lib/matrix-synapse";
572576 PermissionsStartOnly = true;
573− ExecStart = "${cfg.package}/bin/homeserver --config-path ${configFile}";
577+ ExecStart = "${cfg.package}/bin/homeserver --config-path ${configFile} --keys-directory /var/lib/matrix-synapse";
574578 };
575579 };
576580 };