aboutsummaryrefslogtreecommitdiff
path: root/modules/services/fediverse/default.nix
blob: 3fb4e59e38f53cd1ea856d61a899f62cc96877e4 (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
60
61
62
63
64
65
# modules/services/fediverse/default.nix
#
# A portmanteau of "federation" and "universe". A lightweight instance for
# participating in decentralized social media.

{
  config,
  lib,
  pkgs,
  ...
}:
with lib;
let
  cfg = config.modules.services.fediverse;
in
{
  options.modules.services.fediverse = {
    enable = mkEnableOption "fediverse";
    package = mkPackageOption pkgs "gotosocial" { };
    port = mkOption {
      default = 8080;
      type = types.int;
    };
    url = mkOption {
      type = types.str;
    };
    landingPageUser = mkOption {
      default = "";
      type = types.str;
    };
  };

  config = mkIf cfg.enable {
    networking.firewall.allowedTCPPorts = [
      80
      443
    ];

    services.caddy = {
      enable = true;
      virtualHosts = {
        ${cfg.url}.extraConfig = ''
          encode zstd gzip
          reverse_proxy http://localhost:${builtins.toString cfg.port}
        '';
      };
    };

    services.gotosocial = {
      enable = true;
      package = cfg.package;
      settings = {
        application-name = "gotosocial";
        bind-address = "localhost";
        port = cfg.port;
        host = cfg.url;
        protocol = "https";
        db-type = "sqlite";
        db-address = "/var/lib/gotosocial/database.sqlite";
        storage-local-base-path = "/var/lib/gotosocial/storage";
        landing-page-user = cfg.landingPageUser;
      };
    };
  };
}