]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/webapps/mastodon.nix
Add backup module
[perso/Immae/Config/Nix.git] / modules / webapps / mastodon.nix
index f8fbcbaf4e2bec0045297d25a25d2b8c870168cd..eed9e3f60d46760286adddace29cb791e4850f77 100644 (file)
@@ -163,6 +163,7 @@ in
       path = [ cfg.workdir.gems cfg.workdir.gems.ruby pkgs.file ];
 
       preStart = ''
+        install -m 0755 -d ${cfg.dataDir}/tmp/cache
         ./bin/bundle exec rails db:migrate
       '';
 
@@ -170,6 +171,9 @@ in
         exec ./bin/bundle exec puma -C config/puma.rb
       '';
 
+      postStart = ''
+        exec ./bin/tootctl cache clear
+        '';
       serviceConfig = {
         User = cfg.user;
         EnvironmentFile = cfg.configFile;
@@ -186,6 +190,36 @@ in
       unitConfig.RequiresMountsFor = cfg.dataDir;
     };
 
+    systemd.services.mastodon-cleanup = {
+      description = "Cleanup mastodon";
+      startAt = "daily";
+      restartIfChanged = false;
+
+      environment.RAILS_ENV = "production";
+      environment.BUNDLE_PATH = "${cfg.workdir.gems}/${cfg.workdir.gems.ruby.gemPath}";
+      environment.BUNDLE_GEMFILE = "${cfg.workdir.gems.confFiles}/Gemfile";
+      environment.SOCKET = cfg.sockets.rails;
+
+      path = [ cfg.workdir.gems cfg.workdir.gems.ruby pkgs.file ];
+
+      script = ''
+        exec ./bin/tootctl media remove --days 30
+      '';
+
+      serviceConfig = {
+        User = cfg.user;
+        EnvironmentFile = cfg.configFile;
+        PrivateTmp = true;
+        Type = "oneshot";
+        WorkingDirectory = cfg.workdir;
+        StateDirectory = cfg.systemdStateDirectory;
+        RuntimeDirectory = cfg.systemdRuntimeDirectory;
+        RuntimeDirectoryPreserve = "yes";
+      };
+
+      unitConfig.RequiresMountsFor = cfg.dataDir;
+    };
+
     systemd.services.mastodon-sidekiq = {
       description = "Mastodon Sidekiq";
       wantedBy = [ "multi-user.target" ];
@@ -218,12 +252,5 @@ in
       unitConfig.RequiresMountsFor = cfg.dataDir;
     };
 
-    system.activationScripts.mastodon = {
-      deps = [ "users" ];
-      text = ''
-      install -m 0755 -o ${cfg.user} -g ${cfg.group} -d ${cfg.dataDir}/tmp/cache
-      '';
-    };
-
   };
 }