summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.nix6
-rw-r--r--hosts/kay/modules/matrix-sliding-sync.nix (renamed from hosts/kay/modules/matrix_sliding_sync.nix)2
-rw-r--r--hosts/kay/modules/www.nix4
-rw-r--r--modules/matrix-sliding-sync.nix109
4 files changed, 117 insertions, 4 deletions
diff --git a/common.nix b/common.nix
index 4e52b04..9245d3e 100644
--- a/common.nix
+++ b/common.nix
@@ -8,11 +8,15 @@ let
host = config.networking.hostName;
in
{
- disabledModules = [ "services/networking/pppd.nix" ];
+ disabledModules = [
+ "services/networking/pppd.nix"
+ "services/matrix/matrix-sliding-sync.nix"
+ ];
imports = [
./modules/userdata.nix
./modules/dev.nix
./modules/pppd.nix
+ ./modules/matrix-sliding-sync.nix
];
# boot
diff --git a/hosts/kay/modules/matrix_sliding_sync.nix b/hosts/kay/modules/matrix-sliding-sync.nix
index f18ef10..526734b 100644
--- a/hosts/kay/modules/matrix_sliding_sync.nix
+++ b/hosts/kay/modules/matrix-sliding-sync.nix
@@ -6,7 +6,7 @@ in
{
sops.secrets."matrix-${domain}/sliding_sync" = {};
- services.matrix-synapse.sliding-sync = {
+ services.matrix-sliding-sync = {
enable = true;
environmentFile = config.sops.secrets."matrix-${domain}/sliding_sync".path;
settings.SYNCV3_SERVER = "https://${domain}";
diff --git a/hosts/kay/modules/www.nix b/hosts/kay/modules/www.nix
index 4ffa141..aec5d5a 100644
--- a/hosts/kay/modules/www.nix
+++ b/hosts/kay/modules/www.nix
@@ -9,7 +9,7 @@ in
{
imports = [
./dendrite.nix
- ./matrix_sliding_sync.nix
+ ./matrix-sliding-sync.nix
./cgit.nix
];
@@ -53,7 +53,7 @@ in
}}'
'';
locations."/_matrix/client/unstable/org.matrix.msc3575/sync" = let
- addr = "${config.services.matrix-synapse.sliding-sync.settings.SYNCV3_BINDADDR}";
+ addr = "${config.services.matrix-sliding-sync.settings.SYNCV3_BINDADDR}";
in {
proxyPass = "http://${addr}";
};
diff --git a/modules/matrix-sliding-sync.nix b/modules/matrix-sliding-sync.nix
new file mode 100644
index 0000000..3785515
--- /dev/null
+++ b/modules/matrix-sliding-sync.nix
@@ -0,0 +1,109 @@
+{ config, lib, pkgs, ... }:
+
+let
+ cfg = config.services.matrix-sliding-sync;
+in
+{
+ imports = [
+ (lib.mkRenamedOptionModule
+ [ "services" "matrix-synapse" "sliding-sync" ]
+ [ "services" "matrix-sliding-sync" ]
+ )
+ ];
+
+ options.services.matrix-sliding-sync = {
+ enable = lib.mkEnableOption (lib.mdDoc "sliding sync");
+
+ package = lib.mkPackageOption pkgs "matrix-sliding-sync" { };
+
+ settings = lib.mkOption {
+ type = lib.types.submodule {
+ freeformType = with lib.types; attrsOf str;
+ options = {
+ SYNCV3_SERVER = lib.mkOption {
+ type = lib.types.str;
+ description = lib.mdDoc ''
+ The destination homeserver to talk to not including `/_matrix/` e.g `https://matrix.example.org`.
+ '';
+ };
+
+ SYNCV3_DB = lib.mkOption {
+ type = lib.types.str;
+ default = "postgresql:///matrix-sliding-sync?host=/run/postgresql";
+ description = lib.mdDoc ''
+ The postgres connection string.
+ Refer to <https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING>.
+ '';
+ };
+
+ SYNCV3_BINDADDR = lib.mkOption {
+ type = lib.types.str;
+ default = "127.0.0.1:8009";
+ example = "[::]:8008";
+ description = lib.mdDoc "The interface and port to listen on.";
+ };
+
+ SYNCV3_LOG_LEVEL = lib.mkOption {
+ type = lib.types.enum [ "trace" "debug" "info" "warn" "error" "fatal" ];
+ default = "info";
+ description = lib.mdDoc "The level of verbosity for messages logged.";
+ };
+ };
+ };
+ default = { };
+ description = lib.mdDoc ''
+ Freeform environment variables passed to the sliding sync proxy.
+ Refer to <https://github.com/matrix-org/sliding-sync#setup> for all supported values.
+ '';
+ };
+
+ createDatabase = lib.mkOption {
+ type = lib.types.bool;
+ default = true;
+ description = lib.mdDoc ''
+ Whether to enable and configure `services.postgres` to ensure that the database user `matrix-sliding-sync`
+ and the database `matrix-sliding-sync` exist.
+ '';
+ };
+
+ environmentFile = lib.mkOption {
+ type = lib.types.str;
+ description = lib.mdDoc ''
+ Environment file as defined in {manpage}`systemd.exec(5)`.
+
+ This must contain the {env}`SYNCV3_SECRET` variable which should
+ be generated with {command}`openssl rand -hex 32`.
+ '';
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ services.postgresql = lib.optionalAttrs cfg.createDatabase {
+ enable = true;
+ ensureDatabases = [ "matrix-sliding-sync" ];
+ ensureUsers = [ {
+ name = "matrix-sliding-sync";
+ ensureDBOwnership = true;
+ } ];
+ };
+
+ systemd.services.matrix-sliding-sync = rec {
+ after =
+ lib.optional cfg.createDatabase "postgresql.service"
+ ++ lib.optional config.services.dendrite.enable "dendrite.service"
+ ++ lib.optional config.services.matrix-synapse.enable config.services.matrix-synapse.serviceUnit;
+ wants = after;
+ wantedBy = [ "multi-user.target" ];
+ environment = cfg.settings;
+ serviceConfig = {
+ DynamicUser = true;
+ EnvironmentFile = cfg.environmentFile;
+ ExecStart = lib.getExe cfg.package;
+ StateDirectory = "matrix-sliding-sync";
+ WorkingDirectory = "%S/matrix-sliding-sync";
+ Restart = "on-failure";
+ RestartSec = "1s";
+ };
+ };
+ };
+}