summaryrefslogtreecommitdiffstats
path: root/krebs/2configs/mastodon.nix
blob: 3c72051674c21871706e6af80adf627e043fa2f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{ config, lib, pkgs, ... }:
let
  mastodon-clear-cache = pkgs.writers.writeDashBin "mastodon-clear-cache" ''
    /run/current-system/sw/bin/mastodon-tootctl media remove --prune-profiles --days=14 --concurrency=30
    /run/current-system/sw/bin/mastodon-tootctl media remove-orphans
    /run/current-system/sw/bin/mastodon-tootctl preview_cards remove --days=14
    /run/current-system/sw/bin/mastodon-tootctl accounts prune
    /run/current-system/sw/bin/mastodon-tootctl statuses remove --days 4
    /run/current-system/sw/bin/mastodon-tootctl media remove --days 4
  '';
in
{
  services.postgresql = {
    enable = true;
    dataDir = "/var/state/postgresql/${config.services.postgresql.package.psqlSchema}";
    package = pkgs.postgresql_16;
  };
  systemd.tmpfiles.rules = [
    "d /var/state/postgresql 0700 postgres postgres -"
  ];

  services.mastodon = {
    enable = true;
    localDomain = "social.krebsco.de";
    configureNginx = true;
    streamingProcesses = 3;
    smtp.createLocally = false;
    smtp.fromAddress = "derp";
  };

  security.acme.certs."social.krebsco.de".server = "https://acme-staging-v02.api.letsencrypt.org/directory";

  networking.firewall.allowedTCPPorts = [
    80
    443
  ];

  systemd.services.mastodon-clear-cache = {
    description = "Mastodon Clear Cache";
    wantedBy = [ "timers.target" ];
    startAt = "daily";
    serviceConfig = {
      Type = "oneshot";
      ExecStart = "${mastodon-clear-cache}/bin/mastodon-clear-cache";
      User = "mastodon";
      WorkingDirectory = "/var/lib/mastodon";
    };
  };

  environment.systemPackages = [
    mastodon-clear-cache
    (pkgs.writers.writeDashBin "create-mastodon-user" ''
      set -efu
      nick=$1
      /run/current-system/sw/bin/tootctl accounts create "$nick" --email "$nick"@krebsco.de --confirmed
      /run/current-system/sw/bin/tootctl accounts approve "$nick"
    '')
  ];
}