1
2
mirror of https://github.com/dali99/nixos-matrix-modules.git synced 2026-01-20 14:38:22 +01:00

1 Commits

Author SHA1 Message Date
9c7cdcead1 presence stream writer 2023-02-02 21:04:07 +01:00
6 changed files with 45 additions and 51 deletions

21
COPYING
View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2020, 2022-2023 Daniel Løvbrøtte Olsen and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -9,10 +9,6 @@ With matrix.YOURDOMAIN pointing at the server:
workers.federationSenders = 1;
workers.federationReceivers = 1;
workers.initialSyncers = 1;
workers.normalSyncers = 1;
workers.eventPersisters = 2;
workers.useUserDirectoryWorker = true;
enableNginx = true;
@@ -35,4 +31,4 @@ With matrix.YOURDOMAIN pointing at the server:
}
```
is ~enough to get a functional matrix-server running with some workers
is ~enough to get a functional matrix-server running one federation sender and one federation receiver

View File

@@ -7,7 +7,7 @@
outputs = { self, nixpkgs-lib }: {
nixosModules = {
synapse = import ./synapse-module;
synapse = import ./synapse-module { matrix-lib = self.lib; };
};
lib = import ./lib.nix { lib = nixpkgs-lib.lib; };
};

View File

@@ -1,7 +1,6 @@
{ matrix-lib }:
{ pkgs, lib, config, ... }:
let
matrix-lib = (import ../lib.nix { inherit lib; });
let
cfg = config.services.matrix-synapse-next;
wcfg = cfg.workers;

View File

@@ -117,6 +117,7 @@ in
synapse_federation_transaction synapse_worker_federation;
synapse_client_user-dir synapse_worker_user-dir;
synapse_client_presence synapse_worker_stream-presence;
}
# from https://github.com/tswfi/synapse/commit/b3704b936663cc692241e978dce4ac623276b1a6
@@ -187,6 +188,14 @@ in
'';
};
services.nginx.upstreams.synapse_worker_stream-presence = {
servers = let
workers = getWorkersOfType "stream-presence";
socketAddresses = generateSocketAddresses "client" workers;
in if workers != { } then
lib.genAttrs socketAddresses (_: { })
else config.services.nginx.upstreams.synapse_master.servers;
};
services.nginx.upstreams.synapse_worker_user-dir = {
servers = let
@@ -198,7 +207,7 @@ in
};
services.nginx.virtualHosts."${cfg.public_baseurl}" = {
enableACME = lib.mkDefault true;
enableACME = true;
forceSSL = true;
locations."/_matrix" = {
proxyPass = "http://$synapse_backend";

View File

@@ -69,6 +69,20 @@ in {
default = "synapse.app.generic_worker";
};
worker_replication_host = mkOption {
type = types.str;
default = wcfg.mainReplicationHost;
defaultText = literalExpression "${wcfgText}.mainReplicationHost";
description = "The replication listeners IP on the main synapse process";
};
worker_replication_http_port = mkOption {
type = types.port;
default = wcfg.mainReplicationPort;
defaultText = literalExpression "${wcfgText}.mainReplicationPort";
description = "The replication listeners port on the main synapse process";
};
worker_listeners = mkOption {
type = types.listOf (workerListenerType instanceCfg);
description = "Listener configuration for the worker, similar to the main synapse listener";
@@ -212,6 +226,7 @@ in {
eventPersisters = mkWorkerCountOption "event-persister";
useUserDirectoryWorker = mkEnableOption "user directory worker";
usePresenceStreamWriter = mkEnableOption "prescence stream writer";
instances = mkOption {
type = types.attrsOf workerInstanceType;
@@ -237,18 +252,11 @@ in {
federation_sender_instances =
lib.genList (i: "auto-fed-sender${toString (i + 1)}") wcfg.federationSenders;
instance_map = (lib.mkIf (cfg.workers.instances != { }) ({
main = let
host = lib.head mainReplicationListener.bind_addresses;
in {
host = if builtins.elem host [ "0.0.0.0" "::"] then "127.0.0.1" else host;
port = mainReplicationListener.port;
};
} // genAttrs' (lib.lists.range 1 wcfg.eventPersisters)
instance_map = genAttrs' (lib.lists.range 1 wcfg.eventPersisters)
(i: "auto-event-persist${toString i}")
(i: let
wRL = matrix-lib.firstListenerOfType "replication" wcfg.instances."auto-event-persist${toString i}".settings.worker_listeners;
in matrix-lib.connectionInfo wRL)));
in matrix-lib.connectionInfo wRL);
stream_writers.events =
mkIf (wcfg.eventPersisters > 0)
@@ -296,6 +304,11 @@ in {
numberOfWorkers = 1;
nameFn = _: "auto-user-dir";
};
}) // (lib.optionalAttrs wcfg.usePresenceStreamWriter {
"stream-presence" = {
numberOfWorkers = 1;
nameFn = _: "auto-stream-presence";
};
});
coerceWorker = { name, value }: if builtins.isInt value then {
@@ -333,23 +346,21 @@ in {
wantedBy = [ "matrix-synapse.target" ];
after = [ "matrix-synapse.service" ];
requires = [ "matrix-synapse.service" ];
environment = {
PYTHONPATH = lib.makeSearchPathOutput "lib" cfg.package.python.sitePackages [
pluginsEnv
];
};
environment.PYTHONPATH = lib.makeSearchPathOutput "lib" cfg.package.python.sitePackages [
pluginsEnv
];
serviceConfig = {
Type = "notify";
User = "matrix-synapse";
Group = "matrix-synapse";
Slice = "system-matrix-synapse.slice";
WorkingDirectory = cfg.dataDir;
# ExecStartPre = pkgs.writers.writeBash "wait-for-synapse" ''
# # From https://md.darmstadt.ccc.de/synapse-at-work
# while ! systemctl is-active -q matrix-synapse.service; do
# sleep 1
# done
# '';
ExecStartPre = pkgs.writers.writeBash "wait-for-synapse" ''
# From https://md.darmstadt.ccc.de/synapse-at-work
while ! systemctl is-active -q matrix-synapse.service; do
sleep 1
done
'';
ExecStart = let
flags = lib.cli.toGNUCommandLineShell {} {
config-path = [ matrix-synapse-common-config (workerConfig worker) ] ++ cfg.extraConfigFiles;