nixos/matrix-synapse: expose final matrix-synapse package via package-option

When extending this module, it might be necessary to run something
from the package that's used in `matrix-synapse.service` (e.g. for
workers).

Now this can be trivially done by using
`config.services.matrix-synapse.package`. Previously it was necessary to
reuse the `PYTHONPATH` from the environment of `matrix-synapse.service`,
but that one doesn't exist anymore.
This commit is contained in:
Maximilian Bosch 2023-07-31 18:01:18 +02:00
parent 549bc4bc66
commit 5a3870c212
No known key found for this signature in database
GPG key ID: 9A6EEA275CA5BE0A

View file

@ -65,7 +65,6 @@ let
++ lib.optional (cfg.settings.database.name == "psycopg2") "postgres"; ++ lib.optional (cfg.settings.database.name == "psycopg2") "postgres";
wrapped = pkgs.matrix-synapse.override { wrapped = pkgs.matrix-synapse.override {
matrix-synapse-unwrapped = cfg.package.unwrapped;
extras = wantedExtras; extras = wantedExtras;
inherit (cfg) plugins; inherit (cfg) plugins;
}; };
@ -170,18 +169,27 @@ in {
package = mkOption { package = mkOption {
type = types.package; type = types.package;
default = pkgs.matrix-synapse;
defaultText = literalExpression "pkgs.matrix-synapse";
readOnly = true; readOnly = true;
description = lib.mdDoc '' description = lib.mdDoc ''
Wrapper package that gets configured through the module. Reference to the `matrix-synapse` wrapper with all extras
(e.g. for `oidc` or `saml2`) added to the `PYTHONPATH` of all executables.
If you want to override the unwrapped package use an overlay. This option is useful to reference the "final" `matrix-synapse` package that's
actually used by `matrix-synapse.service`. For instance, when using
workers, it's possible to run
`''${config.services.matrix-synapse.package}/bin/synapse_worker` and
no additional PYTHONPATH needs to be specified for extras or plugins configured
via `services.matrix-synapse`.
However, this means that this option is supposed to be only declared
by the `services.matrix-synapse` module itself and is thus read-only.
In order to modify `matrix-synapse` itself, use an overlay to override
`pkgs.matrix-synapse-unwrapped`.
''; '';
}; };
extras = mkOption { extras = mkOption {
type = types.listOf (types.enum (lib.attrNames cfg.package.unwrapped.optional-dependencies)); type = types.listOf (types.enum (lib.attrNames pkgs.matrix-synapse-unwrapped.optional-dependencies));
default = defaultExtras; default = defaultExtras;
example = literalExpression '' example = literalExpression ''
[ [
@ -242,7 +250,7 @@ in {
default = {}; default = {};
description = mdDoc '' description = mdDoc ''
The primary synapse configuration. See the The primary synapse configuration. See the
[sample configuration](https://github.com/matrix-org/synapse/blob/v${cfg.package.unwrapped.version}/docs/sample_config.yaml) [sample configuration](https://github.com/matrix-org/synapse/blob/v${pkgs.matrix-synapse-unwrapped.version}/docs/sample_config.yaml)
for possible values. for possible values.
Secrets should be passed in by using the `extraConfigFiles` option. Secrets should be passed in by using the `extraConfigFiles` option.
@ -755,6 +763,7 @@ in {
]; ];
services.matrix-synapse.configFile = configFile; services.matrix-synapse.configFile = configFile;
services.matrix-synapse.package = wrapped;
# default them, so they are additive # default them, so they are additive
services.matrix-synapse.settings.extras = defaultExtras; services.matrix-synapse.settings.extras = defaultExtras;
@ -776,7 +785,7 @@ in {
after = [ "network.target" ] ++ optional hasLocalPostgresDB "postgresql.service"; after = [ "network.target" ] ++ optional hasLocalPostgresDB "postgresql.service";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
preStart = '' preStart = ''
${wrapped}/bin/synapse_homeserver \ ${cfg.package}/bin/synapse_homeserver \
--config-path ${configFile} \ --config-path ${configFile} \
--keys-directory ${cfg.dataDir} \ --keys-directory ${cfg.dataDir} \
--generate-keys --generate-keys
@ -794,7 +803,7 @@ in {
chmod 0600 ${cfg.settings.signing_key_path} chmod 0600 ${cfg.settings.signing_key_path}
'')) ]; '')) ];
ExecStart = '' ExecStart = ''
${wrapped}/bin/synapse_homeserver \ ${cfg.package}/bin/synapse_homeserver \
${ concatMapStringsSep "\n " (x: "--config-path ${x} \\") ([ configFile ] ++ cfg.extraConfigFiles) } ${ concatMapStringsSep "\n " (x: "--config-path ${x} \\") ([ configFile ] ++ cfg.extraConfigFiles) }
--keys-directory ${cfg.dataDir} --keys-directory ${cfg.dataDir}
''; '';