about summary refs log tree commit diff
path: root/modules/services/misskey/default.nix
blob: 355e91fcaa53abb733537a12fca870acb1a6b8ea (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{ config, lib, pkgs, ... }:

with lib;
let
  cfg = config.modules.services.misskey;

  inherit (lib.my) wrapFile;
in
{
  options.modules.services.misskey = {
    enable = mkEnableOption "Misskey, an interplanetary microblogging platform [container]";
    domain = mkOption { type = types.str; };
    realHost = mkOption { type = types.str; };
  };

  config = mkIf cfg.enable {
    # TODO: refactor

    # Misskey sets uid/gid to 991 in container, user is created here to
    # ensure that misskey files directory is accessible by the container user.
    users = {
      users.misskey = {
        description = "Misskey user";
        group = "misskey";
        extraGroups = [ "podman" ];
        isSystemUser = true;
        uid = 991;
      };
      groups.misskey = { gid = 991; };
    };

    virtualisation.podman.extraPackages = [ pkgs.zfs ];

    # Packaging misskey is too much of a hassle, so we're using containers for now.
    virtualisation.oci-containers.containers.misskey = {
      volumes = [
        "/var/lib/misskey-files:/misskey/files"
        # TODO: manage this with nix
        "${wrapFile ".config" ./config}:/misskey/.config:ro"
      ];
      image = "misskey/misskey:13.10.3";
      ports = [ "3000:3000" ];
      extraOptions = [
        "--network=host"
      ];
    };

    environment.persistence."/persist".directories = [
      "/var/lib/containers"
      "/var/lib/misskey-files"
    ];

    systemd.tmpfiles.rules = [
      "d /var/lib/misskey-files 0755 misskey misskey -"
    ];

    services.postgresql.enable = true;
    services.postgresql.ensureDatabases = [ "misskey" ];
    services.postgresql.ensureUsers = [
      {
        name = "misskey";
        ensurePermissions."DATABASE misskey" = "ALL PRIVILEGES";
      }
    ];

    services.redis.servers.misskey = {
      enable = true;
      bind = "127.0.0.1";
      port = 16434;
    };

    services.nginx.virtualHosts.${cfg.realHost} = {
      forceSSL = true;
      useACMEHost = cfg.domain;
      locations."/" = {
        proxyPass = "http://127.0.0.1:3000";
        proxyWebsockets = true;
      };

      extraConfig = ''
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
      '';
    };
  };
}