summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-07-01 18:32:45 +0200
committerRory& <root@rory.gay>2024-07-04 14:45:02 +0200
commitf5d72806b561c041f2dcccfd27aa6691462be32a (patch)
treeec7389c302bda59344bcb5474ae7e960f2ee22ba
parentSplit up synapse config (diff)
downloadRory-Open-Architecture-f5d72806b561c041f2dcccfd27aa6691462be32a.tar.xz
Synapse changes for testing
-rwxr-xr-xhost/Rory-nginx/configuration.nix2
-rwxr-xr-xhost/Rory-nginx/services/containers/matrixunittests-conduit/root.nix1
-rwxr-xr-xhost/Rory-nginx/services/containers/matrixunittests/root.nix1
-rwxr-xr-xhost/Rory-nginx/services/containers/pluralcontactbotpoc/root.nix1
-rw-r--r--host/Rory-nginx/services/matrix/sliding-sync.nix12
-rwxr-xr-xhost/Rory-nginx/services/matrix/synapse/synapse-main.nix72
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/appservice.nix25
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix28
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/module.nix79
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/pusher.nix29
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/stream-writers/_.nix50
-rw-r--r--host/Rory-nginx/services/matrix/synapse/workers/stream-writers/module.nix72
-rwxr-xr-xmodules/users/Rory.nix3
13 files changed, 336 insertions, 39 deletions
diff --git a/host/Rory-nginx/configuration.nix b/host/Rory-nginx/configuration.nix
index df9936b..822e11d 100755
--- a/host/Rory-nginx/configuration.nix
+++ b/host/Rory-nginx/configuration.nix
@@ -37,6 +37,8 @@
 #      '';
   };
 
+  environment.memoryAllocator.provider = "jemalloc";
+
   containers."pluralcontactbotpoc" = import ./services/containers/pluralcontactbotpoc/container.nix {
     inherit pkgs lib;
     conduit = grapevine;
diff --git a/host/Rory-nginx/services/containers/matrixunittests-conduit/root.nix b/host/Rory-nginx/services/containers/matrixunittests-conduit/root.nix
index b42a38a..c248559 100755
--- a/host/Rory-nginx/services/containers/matrixunittests-conduit/root.nix
+++ b/host/Rory-nginx/services/containers/matrixunittests-conduit/root.nix
@@ -27,5 +27,4 @@
     dig
     cloud-utils
   ];
-
 }
\ No newline at end of file
diff --git a/host/Rory-nginx/services/containers/matrixunittests/root.nix b/host/Rory-nginx/services/containers/matrixunittests/root.nix
index b42a38a..c248559 100755
--- a/host/Rory-nginx/services/containers/matrixunittests/root.nix
+++ b/host/Rory-nginx/services/containers/matrixunittests/root.nix
@@ -27,5 +27,4 @@
     dig
     cloud-utils
   ];
-
 }
\ No newline at end of file
diff --git a/host/Rory-nginx/services/containers/pluralcontactbotpoc/root.nix b/host/Rory-nginx/services/containers/pluralcontactbotpoc/root.nix
index b42a38a..c248559 100755
--- a/host/Rory-nginx/services/containers/pluralcontactbotpoc/root.nix
+++ b/host/Rory-nginx/services/containers/pluralcontactbotpoc/root.nix
@@ -27,5 +27,4 @@
     dig
     cloud-utils
   ];
-
 }
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/sliding-sync.nix b/host/Rory-nginx/services/matrix/sliding-sync.nix
new file mode 100644
index 0000000..bb028bd
--- /dev/null
+++ b/host/Rory-nginx/services/matrix/sliding-sync.nix
@@ -0,0 +1,12 @@
+{ config }:
+{
+    services.matrix-sliding-sync = {
+      enable = true;
+      settings = {
+        "SYNCV3_SERVER" = "http://localhost:8008";
+        "SYNCV3_DB" = "postgresql://%2Frun%2Fpostgresql/syncv3";
+        "SYNCV3_BINDADDR" = "0.0.0.0:8100";
+      };
+      environmentFile = "/etc/sliding-sync.env";
+    };
+]
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/synapse/synapse-main.nix b/host/Rory-nginx/services/matrix/synapse/synapse-main.nix
index f6b8077..6e5c439 100755
--- a/host/Rory-nginx/services/matrix/synapse/synapse-main.nix
+++ b/host/Rory-nginx/services/matrix/synapse/synapse-main.nix
@@ -1,26 +1,29 @@
 { config, pkgs, lib, ... }:
 
 let
-  federationSenders = lib.range 0 31;
-  federationReceivers = lib.range 10000 10000;
-  initialSyncWorkers = lib.range 10100 10100;
-  syncWorkers = lib.range 10150 10150;
-  streamWriters = lib.range 10200 10200;
+  #federationSenders = lib.range 0 31;
+  #federationReceivers = lib.range 10000 10000;
+  #initialSyncWorkers = lib.range 10100 10100;
+  #syncWorkers = lib.range 10150 10150;
+  #streamWriters = lib.range 10200 10200;
 in
 {
+
+  # Worker plumbing examples: https://github.com/element-hq/synapse/blob/master/docker/configure_workers_and_start.py
+  # Documentation: https://github.com/element-hq/synapse/blob/develop/docs/workers.md
+  imports = [
+    ./workers/module.nix
+  ];
+
   services.matrix-synapse = {
     enable = true;
     withJemalloc = true;
 
-    sliding-sync = {
-      enable = true;
-      settings = {
-        "SYNCV3_SERVER" = "http://localhost:8008";
-        "SYNCV3_DB" = "postgresql://%2Frun%2Fpostgresql/syncv3";
-        "SYNCV3_BINDADDR" = "0.0.0.0:8100";
-      };
-      environmentFile = "/etc/sliding-sync.env";
-    };
+    federationSenders = 2;
+    pushers = 2;
+    enableStreamWriters = false;
+    enableAppserviceWorker = true;
+    #eventStreamWriters = 8;
 
     # https://matrix-org.github.io/synapse/latest/usage/configuration/config_documentation.html
     settings = {
@@ -142,12 +145,14 @@ in
           #port = 8009;
           path = "/run/synapse/replication-listener.sock";
         };
-      } // builtins.listToAttrs (map (port: {
-        name = "federation_sender-${toString port}";
-        value = {
-          path = "/run/synapse/federation_sender-${toString port}.sock";
-        };
-      }) federationSenders);
+      } ;
+      ### // builtins.listToAttrs (map (port: {
+      ###   name = "federation_sender-${toString port}";
+      ###   value = {
+      ###     path = "/run/synapse/federation_sender-${toString port}.sock";
+      ###   };
+      ### }) federationSenders);
+
       #} // builtins.listToAttrs (map (port: {
       #  name = "federation_receiver-${toString port}";
       #  value = {
@@ -156,9 +161,8 @@ in
       #}) federationReceivers);
 
       # by type:
-      send_federation = false;
-      federation_sender_instances = map (port: "federation_sender-${toString port}") federationSenders;
-
+      
+      #federation_sender_instances = map (port: "federation_sender-${toString port}") federationSenders;
     }
     // import ./ratelimits.nix
     // import ./caches.nix;
@@ -169,7 +173,7 @@ in
     #   bind_address: ''
     #   port: 9101
 
-    workers = 
+    #workers = 
     #builtins.listToAttrs (map (port: {
     #  name = "federation_receiver-${toString port}";
     #  value = {
@@ -186,14 +190,14 @@ in
     #    ];
     #  };
     #}) federationReceivers)
-    builtins.listToAttrs (map (port: {
-      name = "federation_sender-${toString port}";
-      value = {
-        worker_app = "synapse.app.generic_worker";
-        worker_listeners = [ ];
-        database = (import ./db.nix { workerName = "federation sender ${toString port}"; dbGroup = "small"; });
-      };
-    }) federationSenders);
+    ### builtins.listToAttrs (map (port: {
+    ###   name = "federation_sender-${toString port}";
+    ###   value = {
+    ###     worker_app = "synapse.app.generic_worker";
+    ###     worker_listeners = [ ];
+    ###     database = (import ./db.nix { workerName = "federation sender ${toString port}"; dbGroup = "small"; });
+    ###   };
+    ### }) federationSenders);
   };
 
   systemd.services.matrix-synapse-reg-token = {
@@ -228,6 +232,4 @@ in
   systemd.tmpfiles.rules = [
     "D /run/redis-matrix-synapse 0755 matrix-synapse matrix-synapse"
   ];
-
-}
-
+}
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/appservice.nix b/host/Rory-nginx/services/matrix/synapse/workers/appservice.nix
new file mode 100644
index 0000000..906bec8
--- /dev/null
+++ b/host/Rory-nginx/services/matrix/synapse/workers/appservice.nix
@@ -0,0 +1,25 @@
+{ config, pkgs, lib, ... }:
+
+let 
+  cfg = config.services.matrix-synapse;
+in
+{
+  services.matrix-synapse = lib.mkIf cfg.enableAppserviceWorker {
+    settings = {
+      instance_map = {
+        appservice = {
+          path = "/run/synapse/appservice.sock";
+        };
+      };
+
+      notify_appservices_from_worker = "appservice";
+    };
+
+    workers = {
+      appservice = {
+        worker_app = "synapse.app.generic_worker";
+        worker_listeners = [ ];
+      };
+    };
+  };
+}
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix b/host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix
new file mode 100644
index 0000000..05221de
--- /dev/null
+++ b/host/Rory-nginx/services/matrix/synapse/workers/federation-sender.nix
@@ -0,0 +1,28 @@
+{ config, pkgs, lib, ... }:
+let 
+  cfg = config.services.matrix-synapse;
+  federationSenders = lib.range 0 (cfg.federationSenders - 1);
+in
+{
+  services.matrix-synapse = lib.mkIf (cfg.federationSenders > 0) {
+    settings = {
+      instance_map = lib.listToAttrs (lib.map (index: {
+        name = "federation_sender-${toString index}";
+        value = {
+          path = "/run/synapse/federation_sender-${toString index}.sock";
+        };
+      }) federationSenders);
+
+      send_federation = false;
+      federation_sender_instances = lib.map (index: "federation_sender-${toString index}") federationSenders;
+    };
+
+    workers = lib.listToAttrs (lib.map (index: {
+      name = "federation_sender-${toString index}";
+      value = {
+        worker_app = "synapse.app.generic_worker";
+        worker_listeners = [ ];
+      };
+    }) federationSenders);
+  };
+}
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/module.nix b/host/Rory-nginx/services/matrix/synapse/workers/module.nix
new file mode 100644
index 0000000..074ccb8
--- /dev/null
+++ b/host/Rory-nginx/services/matrix/synapse/workers/module.nix
@@ -0,0 +1,79 @@
+{ config, pkgs, lib, ... }:
+let
+  cfg = config.services.matrix-synapse;
+  #eventWriters = lib.range 0 (count - 1);
+  #typingWriters = lib.range 0 (count - 1);
+  #deviceWriters = lib.range 0 (count - 1);
+  #accountDataWriters = lib.range 0 (count - 1);
+  #receiptsWriters = lib.range 0 (count - 1);
+  #presenceWriters = lib.range 0 (count - 1);
+  #pusherWriters = lib.range 0 (count - 1);
+in
+{
+  imports = [
+    ./federation-sender.nix
+    ./appservice.nix
+    ./pusher.nix
+  ];
+  options.services.matrix-synapse = lib.listToAttrs (lib.map (option: {
+        name = "${option}StreamWriters";
+        value = lib.mkOption {
+          type = lib.types.int;
+          default = 0;
+          description = "Number of writers for ${option} streams";
+        };
+      }) [
+        "event"
+        "typing"
+        "toDevice"
+        "accountData"
+        "receipts"
+        "presence"
+        "pushRule"
+      ]) // {
+        enableStreamWriters = lib.mkEnableOption "Enable stream writers";
+        enableAppserviceWorker = lib.mkEnableOption "Enable dedicated appservice worker";
+
+        federationSenders = lib.mkOption {
+          type = lib.types.int;
+          default = 0;
+          description = "Number of federation senders";
+        };
+        pushers = lib.mkOption {
+          type = lib.types.int;
+          default = 0;
+          description = "Number of pushers";
+        };
+      };
+
+  config = lib.mkIf cfg.enableStreamWriters {
+    #services.matrix-synapse = {
+    #  settings = {
+    #    instance_map = lib.listToAttrs (lib.map (index: {
+    #      name = "stream-writer-${toString index}";
+    #      value = {
+    #        path = "/run/synapse/stream-writer-${toString index}.sock";
+    #      };
+    #    }) federationSenders);
+#
+    #    stream_writers = {
+    #      events = lib.map (index: "stream-writer-events-${toString index}") federationSenders;
+    #      typing = lib.map (index: "stream-writer-typing-${toString index}") typingWriters;
+    #      to_device = lib.map (index: "stream-writer-to_device-${toString index}") deviceWriters;
+    #      account_data = lib.map (index: "stream-writer-account_data-${toString index}") accountDataWriters;
+    #      receipts = lib.map (index: "stream-writer-receipts-${toString index}") receiptsWriters;
+    #      presence = lib.map (index: "stream-writer-presence-${toString index}") presenceWriters;
+    #      push_rules = lib.map (index: "stream-writer-push_rules-${toString index}") pusherWriters;
+    #    };
+    #  };
+#
+    #  workers = lib.listToAttrs (lib.map (index: {
+    #    name = "stream-writerr-${toString index}";
+    #    value = {
+    #      worker_app = "synapse.app.generic_worker";
+    #      worker_listeners = [ ];
+    #    };
+    #  }) federationSenders);
+    #};
+  };
+}
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix b/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix
new file mode 100644
index 0000000..559d42c
--- /dev/null
+++ b/host/Rory-nginx/services/matrix/synapse/workers/pusher.nix
@@ -0,0 +1,29 @@
+{ config, pkgs, lib, ... }:
+let
+  cfg = config.services.matrix-synapse;
+  pushers = lib.range 0 (cfg.pushers - 1);
+in
+{
+  config = lib.mkIf (cfg.pushers > 0) {
+    services.matrix-synapse = {
+      settings = {
+        instance_map = lib.listToAttrs (lib.map (index: {
+          name = "pusher-${toString index}";
+          value = {
+            path = "/run/synapse/pusher-${toString index}.sock";
+          };
+        }) pushers);
+
+        pusher_instances = lib.map (index: "pusher-${toString index}") pushers;
+      };
+
+      workers = lib.listToAttrs (lib.map (index: {
+        name = "pusher-${toString index}";
+        value = {
+          worker_app = "synapse.app.generic_worker";
+          worker_listeners = [ ];
+        };
+      }) pushers);
+    };
+  };
+}
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/_.nix b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/_.nix
new file mode 100644
index 0000000..8fae885
--- /dev/null
+++ b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/_.nix
@@ -0,0 +1,50 @@
+{ 
+  count,
+  separateEventWriters ? 1,
+  separateTypingWriters ? 1, 
+  separateToDeviceWriters ? 1, 
+  separateAccountDataWriters ? 1,
+  separateReceiptsWriters ? 1,
+  separatePresenceWriters ? 1,
+  separatePusherWriters ? 1,
+}:
+{ config, pkgs, lib, ... }:
+let 
+  eventWriters = lib.range 0 (count - 1);
+  typingWriters = lib.range 0 (count - 1);
+  deviceWriters = lib.range 0 (count - 1);
+  accountDataWriters = lib.range 0 (count - 1);
+  receiptsWriters = lib.range 0 (count - 1);
+  presenceWriters = lib.range 0 (count - 1);
+  pusherWriters = lib.range 0 (count - 1);
+in
+{
+  services.matrix-synapse = {
+    settings = {
+      instance_map = lib.listToAttrs (lib.map (port: {
+        name = "stream-writer-${toString port}";
+        value = {
+          path = "/run/synapse/stream-writer-${toString port}.sock";
+        };
+      }) federationSenders);
+
+      stream_writers = {
+        events = lib.map (port: "stream-writer-events-${toString port}") federationSenders;
+        typing = lib.map (port: "stream-writer-typing-${toString port}") typingWriters;
+        to_device = lib.map (port: "stream-writer-to_device-${toString port}") deviceWriters;
+        account_data = lib.map (port: "stream-writer-account_data-${toString port}") accountDataWriters;
+        receipts = lib.map (port: "stream-writer-receipts-${toString port}") receiptsWriters;
+        presence = lib.map (port: "stream-writer-presence-${toString port}") presenceWriters;
+        push_rules = lib.map (port: "stream-writer-push_rules-${toString port}") pusherWriters;
+      };
+    };
+
+    workers = lib.listToAttrs (lib.map (port: {
+      name = "stream-writerr-${toString port}";
+      value = {
+        worker_app = "synapse.app.generic_worker";
+        worker_listeners = [ ];
+      };
+    }) federationSenders);
+  };
+}
\ No newline at end of file
diff --git a/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/module.nix b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/module.nix
new file mode 100644
index 0000000..4f661b9
--- /dev/null
+++ b/host/Rory-nginx/services/matrix/synapse/workers/stream-writers/module.nix
@@ -0,0 +1,72 @@
+{ config, pkgs, lib, ... }:
+let
+  cfg = config.services.matrix-synapse;
+  #eventWriters = lib.range 0 (count - 1);
+  #typingWriters = lib.range 0 (count - 1);
+  #deviceWriters = lib.range 0 (count - 1);
+  #accountDataWriters = lib.range 0 (count - 1);
+  #receiptsWriters = lib.range 0 (count - 1);
+  #presenceWriters = lib.range 0 (count - 1);
+  #pusherWriters = lib.range 0 (count - 1);
+in
+{
+  options.services.matrix-synapse = lib.listToAttrs (lib.map (option: {
+        name = "${option}StreamWriters";
+        value = lib.mkOption {
+          type = lib.types.int;
+          default = 1;
+          description = "Number of writers for ${option} streams";
+        };
+      }) [
+        "event"
+        "typing"
+        "toDevice"
+        "accountData"
+        "receipts"
+        "presence"
+        "pushRule"
+      ]) // {
+        enableStreamWriters = lib.mkEnableOption "Enable stream writers";
+        federationSenders = lib.mkOption {
+          type = lib.types.int;
+          default = 1;
+          description = "Number of federation senders";
+        };
+        pushers = lib.mkOption {
+          type = lib.types.int;
+          default = 1;
+          description = "Number of pushers";
+        };
+      };
+
+  config = lib.mkIf cfg.enableStreamWriters {
+    services.matrix-synapse = {
+      settings = {
+        instance_map = lib.listToAttrs (lib.map (port: {
+          name = "stream-writer-${toString port}";
+          value = {
+            path = "/run/synapse/stream-writer-${toString port}.sock";
+          };
+        }) federationSenders);
+
+        stream_writers = {
+          events = lib.map (port: "stream-writer-events-${toString port}") federationSenders;
+          typing = lib.map (port: "stream-writer-typing-${toString port}") typingWriters;
+          to_device = lib.map (port: "stream-writer-to_device-${toString port}") deviceWriters;
+          account_data = lib.map (port: "stream-writer-account_data-${toString port}") accountDataWriters;
+          receipts = lib.map (port: "stream-writer-receipts-${toString port}") receiptsWriters;
+          presence = lib.map (port: "stream-writer-presence-${toString port}") presenceWriters;
+          push_rules = lib.map (port: "stream-writer-push_rules-${toString port}") pusherWriters;
+        };
+      };
+
+      workers = lib.listToAttrs (lib.map (port: {
+        name = "stream-writerr-${toString port}";
+        value = {
+          worker_app = "synapse.app.generic_worker";
+          worker_listeners = [ ];
+        };
+      }) federationSenders);
+    };
+  };
+}
\ No newline at end of file
diff --git a/modules/users/Rory.nix b/modules/users/Rory.nix
index 5bba267..861bf68 100755
--- a/modules/users/Rory.nix
+++ b/modules/users/Rory.nix
@@ -24,12 +24,13 @@
       zsh-you-should-use
       zsh-syntax-highlighting
       zsh-completions
+
+      wireguard-tools
     ];
     openssh.authorizedKeys.keys = [
       #"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICT+53Hy3wbIlNVIomK2RroaimMWrTlUkndjHt1dFuyh root@pfSense-arcane-home.localdomain"
       "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILF2IuNu//0DP/wKMuDvBgVT3YBS2uULsipbdrhJCTM7 thearcanebrony@tab-linux-desktop"
       "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN/kNkY/E5b6rvCQLMaSbpLQ/xoyywIwVVu9uo2j/B6p Rory@RoryNix"
-      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJPRTuz83dVThuDVXhDz3w3uYBGJ+JPzdZFT6wvhQXQ3 Rory@Rory-wsl" # work laptop
     ];
     useDefaultShell = true;
     shell = pkgs.zsh;