Commit 891dfb1b authored by Manuel Bärenz's avatar Manuel Bärenz Committed by Kerstin
Browse files

nixos/mastodon: add option mediaAutoRemove

parent cfd61a25
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -961,6 +961,13 @@
          configure this behaviour.
        </para>
      </listitem>
      <listitem>
        <para>
          <literal>mastodon</literal> now automatically removes remote
          media attachments older than 30 days. This is configurable
          through <literal>services.mastodon.mediaAutoRemove</literal>.
        </para>
      </listitem>
      <listitem>
        <para>
          The Redis module now disables RDB persistence when
+3 −1
Original line number Diff line number Diff line
@@ -296,6 +296,8 @@ Available as [services.patroni](options.html#opt-services.patroni.enable).

- ZFS module will not allow hibernation by default, this is a safety measure to prevent data loss cases like the ones described at [OpenZFS/260](https://github.com/openzfs/zfs/issues/260) and [OpenZFS/12842](https://github.com/openzfs/zfs/issues/12842). Use the `boot.zfs.allowHibernation` option to configure this behaviour.

- `mastodon` now automatically removes remote media attachments older than 30 days. This is configurable through `services.mastodon.mediaAutoRemove`.

- The Redis module now disables RDB persistence when `services.redis.servers.<name>.save = []` instead of using the Redis default.

- Neo4j was updated from version 3 to version 4. See this [migration guide](https://neo4j.com/docs/upgrade-migration-guide/current/) on how to migrate your Neo4j instance.
+49 −0
Original line number Diff line number Diff line
@@ -425,6 +425,39 @@ in {
          Do automatic database migrations.
        '';
      };

      mediaAutoRemove = {
        enable = lib.mkOption {
          type = lib.types.bool;
          default = true;
          example = false;
          description = lib.mdDoc ''
            Automatically remove remote media attachments and preview cards older than the configured amount of days.

            Recommended in https://docs.joinmastodon.org/admin/setup/.
          '';
        };

        startAt = lib.mkOption {
          type = lib.types.str;
          default = "daily";
          example = "hourly";
          description = lib.mdDoc ''
            How often to remove remote media.

            The format is described in {manpage}`systemd.time(7)`.
          '';
        };

        olderThanDays = lib.mkOption {
          type = lib.types.int;
          default = 30;
          example = 14;
          description = lib.mdDoc ''
            How old remote media needs to be in order to be removed.
          '';
        };
      };
    };
  };

@@ -585,6 +618,22 @@ in {
      path = with pkgs; [ file imagemagick ffmpeg ];
    };

    systemd.services.mastodon-media-auto-remove = lib.mkIf cfg.mediaAutoRemove.enable {
      description = "Mastodon media auto remove";
      environment = env;
      serviceConfig = {
        Type = "oneshot";
        script = let
          olderThanDays = toString cfg.mediaAutoRemove.olderThanDays;
        in ''
          ${cfg.package}/bin/tootctl media remove --days=${olderThanDays}
          ${cfg.package}/bin/tootctl preview_cards remove --days=${olderThanDays}
        '';
        EnvironmentFile = "/var/lib/mastodon/.secrets_env";
        startAt = cfg.mediaAutoRemove.startAt;
      } // cfgService;
    };

    services.nginx = lib.mkIf cfg.configureNginx {
      enable = true;
      recommendedProxySettings = true; # required for redirections to work