about summary refs log tree commit diff
path: root/nixos/modules/services/web-apps/alps.nix
blob: b171729fd0a356267e6f8be1ad9c481e785e0d70 (plain) (blame)
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
89
90
91
92
93
94
95
96
{ lib, pkgs, config, ... }:

with lib;

let
  cfg = config.services.alps;
in {
  options.services.alps = {
    enable = mkEnableOption (lib.mdDoc "alps");

    port = mkOption {
      type = types.port;
      default = 1323;
      description = lib.mdDoc ''
        TCP port the service should listen on.
      '';
    };

    bindIP = mkOption {
      default = "[::]";
      type = types.str;
      description = lib.mdDoc ''
        The IP the service should listen on.
      '';
    };

    theme = mkOption {
      type = types.enum [ "alps" "sourcehut" ];
      default = "sourcehut";
      description = lib.mdDoc ''
        The frontend's theme to use.
      '';
    };

    imaps = {
      port = mkOption {
        type = types.port;
        default = 993;
        description = lib.mdDoc ''
          The IMAPS server port.
        '';
      };

      host = mkOption {
        type = types.str;
        default = "[::1]";
        example = "mail.example.org";
        description = lib.mdDoc ''
          The IMAPS server address.
        '';
      };
    };

    smtps = {
      port = mkOption {
        type = types.port;
        default = 445;
        description = lib.mdDoc ''
          The SMTPS server port.
        '';
      };

      host = mkOption {
        type = types.str;
        default = cfg.imaps.host;
        defaultText = "services.alps.imaps.host";
        example = "mail.example.org";
        description = lib.mdDoc ''
          The SMTPS server address.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.alps = {
      description = "alps is a simple and extensible webmail.";
      documentation = [ "https://git.sr.ht/~migadu/alps" ];
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" "network-online.target" ];

      serviceConfig = {
        ExecStart = ''
          ${pkgs.alps}/bin/alps \
            -addr ${cfg.bindIP}:${toString cfg.port} \
            -theme ${cfg.theme} \
            imaps://${cfg.imaps.host}:${toString cfg.imaps.port} \
            smpts://${cfg.smtps.host}:${toString cfg.smtps.port}
        '';
        StateDirectory = "alps";
        WorkingDirectory = "/var/lib/alps";
        DynamicUser = true;
      };
    };
  };
}