X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fwebapps%2Fmastodon.nix;h=eed9e3f60d46760286adddace29cb791e4850f77;hb=6a8252b11bb02f3e67857d5a9d733b1affa6a625;hp=ad6d0c3aa625cdb15408dda1940a6554fed38212;hpb=613aea5685ad4c698386c374474d8853bb736503;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/webapps/mastodon.nix b/modules/webapps/mastodon.nix index ad6d0c3..eed9e3f 100644 --- a/modules/webapps/mastodon.nix +++ b/modules/webapps/mastodon.nix @@ -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; @@ -140,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 ''; @@ -147,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; @@ -155,6 +182,39 @@ in TimeoutSec = 60; Type = "simple"; WorkingDirectory = cfg.workdir; + StateDirectory = cfg.systemdStateDirectory; + RuntimeDirectory = cfg.systemdRuntimeDirectory; + RuntimeDirectoryPreserve = "yes"; + }; + + 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; @@ -184,18 +244,13 @@ in TimeoutSec = 15; Type = "simple"; WorkingDirectory = cfg.workdir; + StateDirectory = cfg.systemdStateDirectory; + RuntimeDirectory = cfg.systemdRuntimeDirectory; + RuntimeDirectoryPreserve = "yes"; }; unitConfig.RequiresMountsFor = cfg.dataDir; }; - 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 - ''; - }; - }; }