mirror of
https://github.com/dali99/nixos-matrix-modules.git
synced 2026-01-18 21:48:21 +01:00
Compare commits
10 Commits
v0.4.0
...
time-to-br
| Author | SHA1 | Date | |
|---|---|---|---|
| f5c6d3f72c | |||
| 66ff528912 | |||
| 8199f88a5a | |||
|
|
bf997073d9 | ||
| c158a35ea2 | |||
| 362496f4aa | |||
| cf89fa8eb9 | |||
| 59e39d551d | |||
| 07e95170e8 | |||
| 5ef8873997 |
21
COPYING
Normal file
21
COPYING
Normal 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.
|
||||
@@ -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
26
flake.lock
generated
Normal 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
|
||||
}
|
||||
@@ -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
20
lib.nix
Normal 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;
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
})
|
||||
];
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user