add mastodon cleanup systemd timer

This commit is contained in:
Vivian 2022-10-07 10:55:53 +02:00
parent 71ea216d71
commit a0e9336337

View file

@ -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 ]; };