From a0e9336337f8a5b586b295e29d7d13576ba884f7 Mon Sep 17 00:00:00 2001 From: Victor Date: Fri, 7 Oct 2022 10:55:53 +0200 Subject: [PATCH] add mastodon cleanup systemd timer --- nixos/hosts/hades/mastodon/configuration.nix | 31 +++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/nixos/hosts/hades/mastodon/configuration.nix b/nixos/hosts/hades/mastodon/configuration.nix index f352b05..77840da 100644 --- a/nixos/hosts/hades/mastodon/configuration.nix +++ b/nixos/hosts/hades/mastodon/configuration.nix @@ -18,7 +18,7 @@ in }; vault-secrets.secrets.mastodon = { - services = [ "mastodon-init-dirs" "mastodon" ]; + services = [ "mastodon-init-dirs" "mastodon" "mastodon-media-prune" ]; user = cfg.user; group = cfg.group; }; @@ -92,6 +92,35 @@ in }; }; + # https://github.com/NixOS/nixpkgs/issues/116418#issuecomment-799517120 + systemd.services.mastodon-media-prune = + let + cfg = config.services.mastodon; + in + { + description = "Mastodon media prune"; + environment = lib.filterAttrs (n: _: n != "PATH") config.systemd.services.mastodon-web.environment; + serviceConfig = { + Type = "oneshot"; + # Remove remote media attachments older than one month. + ExecStart = "${cfg.package}/bin/tootctl media remove --days=30"; + User = cfg.user; + Group = cfg.group; + EnvironmentFile = "/var/lib/mastodon/.secrets_env"; + PrivateTmp = true; + }; + }; + + systemd.timers.mastodon-media-prune = { + description = "Mastodon media prune"; + wantedBy = [ "timers.target" ]; + timerConfig = { + OnCalendar = "*-*-* 00:00:00"; # every day + Unit = "mastodon-media-prune.service"; + AccuracySec = "60s"; + }; + }; + networking.firewall = let cfg = config.services.mastodon; in { allowedTCPPorts = [ cfg.streamingPort cfg.webPort ]; };