]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/webapps/mastodon.nix
Use systemd RuntimeDirectory and StateDirectory entries to ensure runtime directory...
[perso/Immae/Config/Nix.git] / modules / webapps / mastodon.nix
index ad6d0c3aa625cdb15408dda1940a6554fed38212..f8fbcbaf4e2bec0045297d25a25d2b8c870168cd 100644 (file)
@@ -62,6 +62,26 @@ in
       '';
       readOnly = true;
     };
+    systemdStateDirectory = lib.mkOption {
+      type = lib.types.str;
+      # Use ReadWritePaths= instead if varDir is outside of /var/lib
+      default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
+        lib.strings.removePrefix "/var/lib/" cfg.dataDir;
+      description = ''
+      Adjusted Mastodon data directory for systemd
+      '';
+      readOnly = true;
+    };
+    systemdRuntimeDirectory = lib.mkOption {
+      type = lib.types.str;
+      # Use ReadWritePaths= instead if socketsDir is outside of /run
+      default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
+        lib.strings.removePrefix "/run/" cfg.socketsDir;
+      description = ''
+      Adjusted Mastodon sockets directory for systemd
+      '';
+      readOnly = true;
+    };
     sockets = lib.mkOption {
       type = lib.types.attrsOf lib.types.path;
       default = {
@@ -122,6 +142,9 @@ in
         TimeoutSec = 15;
         Type = "simple";
         WorkingDirectory = cfg.workdir;
+        StateDirectory = cfg.systemdStateDirectory;
+        RuntimeDirectory = cfg.systemdRuntimeDirectory;
+        RuntimeDirectoryPreserve = "yes";
       };
 
       unitConfig.RequiresMountsFor = cfg.dataDir;
@@ -155,6 +178,9 @@ in
         TimeoutSec = 60;
         Type = "simple";
         WorkingDirectory = cfg.workdir;
+        StateDirectory = cfg.systemdStateDirectory;
+        RuntimeDirectory = cfg.systemdRuntimeDirectory;
+        RuntimeDirectoryPreserve = "yes";
       };
 
       unitConfig.RequiresMountsFor = cfg.dataDir;
@@ -184,6 +210,9 @@ in
         TimeoutSec = 15;
         Type = "simple";
         WorkingDirectory = cfg.workdir;
+        StateDirectory = cfg.systemdStateDirectory;
+        RuntimeDirectory = cfg.systemdRuntimeDirectory;
+        RuntimeDirectoryPreserve = "yes";
       };
 
       unitConfig.RequiresMountsFor = cfg.dataDir;
@@ -192,8 +221,7 @@ in
     system.activationScripts.mastodon = {
       deps = [ "users" ];
       text = ''
-      install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.socketsDir}
-      install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir} ${cfg.dataDir}/tmp/cache
+      install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}/tmp/cache
       '';
     };