ctucx.git: nixfiles

ctucx' nixfiles

commit 865b41f8efc633e3aefba5f212ecd6111bb1f285
parent 620d31e509e59e1dcbeefad01ec5a72a554a221d
Author: Leah (ctucx) <git@ctu.cx>
Date: Sun, 4 Jun 2023 17:45:54 +0200

modules/linux/matrix-sliding-sync: restart always, start after postgresql.service
1 file changed, 49 insertions(+), 32 deletions(-)
M
modules/linux/matrix-sliding-sync.nix
|
81
++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------
diff --git a/modules/linux/matrix-sliding-sync.nix b/modules/linux/matrix-sliding-sync.nix
@@ -1,77 +1,94 @@
 { config, pkgs, lib, ... }:
 with lib;
+
 let
   cfg = config.services.matrix-sliding-sync-proxy;
   user = if cfg.user == null then "matrix-sliding-sync-proxy" else cfg.user;
 
 in {
-  config = mkIf cfg.enable {
-    assertions = [{
-      assertion = cfg.dbName != null;
-      message = ''
-        A Postgres database is required for matrix-sliding-sync-proxy to work.
-        See `services.matrix-sliding-sync-proxy.db` in `man configuration.nix` for details.
-      '';
-    }];
-    systemd.services.matrix-sliding-sync = {
-      script = ''
-        cd ${cfg.package}/share
-        exec ${cfg.package}/bin/syncv3
-      '';
-      after = [ "network-online.target" ];
-      wantedBy = [ "multi-user.target" ];
-      serviceConfig = { User = user; };
-      environment = {
-        SYNCV3_DB =
-          "user=${user} dbname=${cfg.dbName} sslmode=disable host=${cfg.dbHost}";
-        SYNCV3_BINDADDR = "${cfg.bind}";
-        SYNCV3_SERVER = "${cfg.server}";
-        SYNCV3_SECRET = "foobar";
-      };
-    };
 
-    users = mkIf (cfg.user == null) {
-      users.matrix-sliding-sync-proxy = {
-        isSystemUser = true;
-        group = "matrix-sliding-sync-proxy";
-      };
-      groups.matrix-sliding-sync-proxy = { };
-    };
-  };
   options = {
     services.matrix-sliding-sync-proxy = {
+
       enable = mkEnableOption "the experimental matrix sliding sync proxy";
+
       package = mkOption {
         type = types.package;
         default = pkgs.matrix-sliding-sync-proxy;
         description = "Package to use for the service.";
       };
+
       server = mkOption {
         type = types.str;
         default = "https://localhost:8448/";
         description = "Server to proxy requests for.";
       };
+
       dbName = mkOption {
         default = null;
         type = types.nullOr types.str;
         example = "syncv3";
         description = "Postgres database name to access.";
       };
+
       bind = mkOption {
         type = types.str;
         default = "localhost:8008";
         description = "Port to bind the proxy to.";
       };
+
       dbHost = mkOption {
         default = "/run/postgresql";
         type = types.str;
         description = "Path to postgresql socket.";
       };
+
       user = mkOption {
         default = null;
         description =
           "User under which the service runs. Created automatically if null.";
       };
+
     };
   };
+
+  config = mkIf cfg.enable {
+    assertions = [{
+      assertion = cfg.dbName != null;
+      message = ''
+        A Postgres database is required for matrix-sliding-sync-proxy to work.
+        See `services.matrix-sliding-sync-proxy.db` in `man configuration.nix` for details.
+      '';
+    }];
+
+    systemd.services.matrix-sliding-sync = {
+      after    = [ "network-online.target" "postgresql.service" ];
+      wantedBy = [ "multi-user.target" ];
+      script = ''
+        cd ${cfg.package}/share
+        exec ${cfg.package}/bin/syncv3
+      '';
+      serviceConfig = {
+        User       = user;
+        Restart    = "always";
+        RestartSec = 5;
+      };
+      environment = {
+        SYNCV3_DB = "user=${user} dbname=${cfg.dbName} sslmode=disable host=${cfg.dbHost}";
+        SYNCV3_BINDADDR = "${cfg.bind}";
+        SYNCV3_SERVER = "${cfg.server}";
+        SYNCV3_SECRET = "foobar";
+      };
+    };
+
+    users = mkIf (cfg.user == null) {
+      users.matrix-sliding-sync-proxy = {
+        isSystemUser = true;
+        group = "matrix-sliding-sync-proxy";
+      };
+      groups.matrix-sliding-sync-proxy = { };
+    };
+
+  };
+
 } 
\ No newline at end of file