1
2
mirror of https://github.com/dali99/nixos-matrix-modules.git synced 2026-01-18 21:48:21 +01:00

10 Commits

Author SHA1 Message Date
f5c6d3f72c disable the wait-for-script temporarily
https://github.com/NixOS/nixpkgs/pull/241973/files#diff-ad0db3f4b3d5cdddf08d7a7d16c7fc1502c54b9ce56b09077879a4c157cd6374R1065
2023-09-12 21:38:35 +02:00
66ff528912 Update README.MD 2023-09-11 00:04:19 +02:00
8199f88a5a Update README.MD 2023-09-11 00:03:44 +02:00
lon
bf997073d9 fix: don't force enableACME to allow useACMEHost 2023-07-27 22:10:46 +02:00
c158a35ea2 emergency handling of deprecations 2023-07-13 04:16:00 +02:00
362496f4aa move matrix-lib to let block
Else it has to be called with { } which modules cant do
2023-02-17 23:59:59 +01:00
cf89fa8eb9 load matrix-lib directly inside module
To enable use with non-flakes
2023-02-17 23:44:47 +01:00
59e39d551d Add a license
Co-authored-by: h7x4 <h7x4@nani.wtf>
2023-02-17 01:16:02 +01:00
07e95170e8 introduce matrix-lib 2023-01-20 08:11:33 +01:00
5ef8873997 simplify mainReplicationListener stuff 2023-01-20 08:11:33 +01:00
8 changed files with 113 additions and 54 deletions

21
COPYING Normal file
View File

@@ -0,0 +1,21 @@
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,6 +9,10 @@ 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;
@@ -31,4 +35,4 @@ With matrix.YOURDOMAIN pointing at the server:
}
```
is ~enough to get a functional matrix-server running one federation sender and one federation receiver
is ~enough to get a functional matrix-server running with some workers

26
flake.lock generated Normal file
View File

@@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgs-lib": {
"locked": {
"lastModified": 1673743903,
"narHash": "sha256-sloY6KYyVOozJ1CkbgJPpZ99TKIjIvM+04V48C04sMQ=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "7555e2dfcbac1533f047021f1744ac8871150f9f",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
}
}
},
"root": "root",
"version": 7
}

View File

@@ -1,9 +1,14 @@
{
description = "NixOS modules for matrix related services";
outputs = { self }: {
inputs = {
nixpkgs-lib.url = github:nix-community/nixpkgs.lib;
};
outputs = { self, nixpkgs-lib }: {
nixosModules = {
synapse = import ./synapse-module;
};
lib = import ./lib.nix { lib = nixpkgs-lib.lib; };
};
}

20
lib.nix Normal file
View File

@@ -0,0 +1,20 @@
{ lib }:
rec {
# checks if given listener configuration has type as a resource
isListenerType = type: l: lib.any (r: lib.any (n: n == type) r.names) l.resources;
# Get the first listener that includes the given resource from worker
firstListenerOfType = type: ls: lib.lists.findFirst (isListenerType type)
(lib.throw "No listener with resource: ${type} configured")
ls;
# Get an attrset of the host and port from a listener
connectionInfo = l: {
host = lib.head l.bind_addresses;
port = l.port;
};
# Get an attrset of the host and port from a worker given a type
workerConnectionResource = r: w: let
l = firstListenerOfType r w.settings.worker_listeners;
in connectionInfo l;
}

View File

@@ -1,5 +1,7 @@
{ pkgs, lib, config, ... }:
let
let
matrix-lib = (import ../lib.nix { inherit lib; });
cfg = config.services.matrix-synapse-next;
wcfg = cfg.workers;
@@ -31,7 +33,7 @@ in
imports = [
./nginx.nix
(import ./workers.nix {
inherit throw' format matrix-synapse-common-config pluginsEnv;
inherit matrix-lib throw' format matrix-synapse-common-config pluginsEnv;
})
];

View File

@@ -198,7 +198,7 @@ in
};
services.nginx.virtualHosts."${cfg.public_baseurl}" = {
enableACME = true;
enableACME = lib.mkDefault true;
forceSSL = true;
locations."/_matrix" = {
proxyPass = "http://$synapse_backend";

View File

@@ -1,4 +1,5 @@
{ matrix-synapse-common-config,
matrix-lib,
pluginsEnv,
throw',
format
@@ -22,17 +23,7 @@
genAttrs' = items: f: g: builtins.listToAttrs (map (i: lib.nameValuePair (f i) (g i)) items);
isReplicationListener =
l: lib.any (r: lib.any (n: n == "replication") r.names) l.resources;
mainReplicationListener = lib.lists.findFirst isReplicationListener
(throw' "No replication listener configured!")
cfg.settings.listeners;
mainReplicationListenerHost =
if mainReplicationListener.bind_addresses == []
then throw' "Replication listener had no addresses"
else builtins.head mainReplicationListener.bind_addresses;
mainReplicationListenerPort = mainReplicationListener.port;
mainReplicationListener = matrix-lib.firstListenerOfType "replication" cfg.settings.listeners;
in {
# See https://github.com/matrix-org/synapse/blob/develop/docs/workers.md for more info
options.services.matrix-synapse-next.workers = let
@@ -78,20 +69,6 @@ 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";
@@ -185,17 +162,20 @@ in {
in {
mainReplicationHost = mkOption {
type = types.str;
default =
if builtins.elem mainReplicationListenerHost [ "0.0.0.0" "::" ]
default = let
host = (matrix-lib.connectionInfo mainReplicationListener).host;
in
# To avoid connecting to 0.0.0.0 and so on
if builtins.elem host [ "0.0.0.0" "::" ]
then "127.0.0.1"
else mainReplicationListenerHost;
else host;
# TODO: add defaultText
description = "Host of the main synapse instance's replication listener";
};
mainReplicationPort = mkOption {
type = types.port;
default = mainReplicationListenerPort;
default = mainReplicationListener.port;
# TODO: add defaultText
description = "Port for the main synapse instance's replication listener";
};
@@ -257,19 +237,18 @@ in {
federation_sender_instances =
lib.genList (i: "auto-fed-sender${toString (i + 1)}") wcfg.federationSenders;
instance_map = genAttrs' (lib.lists.range 1 wcfg.eventPersisters)
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)
(i: "auto-event-persist${toString i}")
(i: let
wRL = lib.lists.findFirst isReplicationListener
(throw' "No replication listener configured!")
wcfg.instances."auto-event-persist${toString i}".settings.worker_listeners;
wRH = lib.findFirst (x: true) (throw' "Replication listener had no addresses")
wRL.bind_addresses;
wRP = wRL.port;
in {
host = wRH;
port = wRP;
});
wRL = matrix-lib.firstListenerOfType "replication" wcfg.instances."auto-event-persist${toString i}".settings.worker_listeners;
in matrix-lib.connectionInfo wRL)));
stream_writers.events =
mkIf (wcfg.eventPersisters > 0)
@@ -354,21 +333,23 @@ 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;