1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.services.mailpile;
8
9 hostname = cfg.hostname;
10 port = cfg.port;
11
12in
13
14{
15
16 ###### interface
17
18 options = {
19
20 services.mailpile = {
21 enable = mkOption {
22 default = false;
23 description = "
24 Whether to enable Mailpile the mail client.
25 ";
26 };
27 hostname = mkOption {
28 default = "localhost";
29 description = "Listen to this hostname or ip.";
30 };
31 port = mkOption {
32 default = "33411";
33 description = "Listen on this port.";
34 };
35 };
36
37 };
38
39
40 ###### implementation
41
42 config = mkIf config.services.mailpile.enable {
43
44 users.extraUsers.mailpile =
45 { uid = config.ids.uids.mailpile;
46 description = "Mailpile user";
47 createHome = true;
48 home = "/var/lib/mailpile";
49 };
50
51 users.extraGroups.mailpile =
52 { gid = config.ids.gids.mailpile;
53 };
54
55 systemd.services.mailpile =
56 {
57 description = "Mailpile server.";
58 after = [ "network.target" ];
59 wantedBy = [ "multi-user.target" ];
60 serviceConfig = {
61 User = "mailpile";
62 ExecStart = "${pkgs.mailpile}/bin/mailpile --www ${hostname}:${port} --wait";
63 # mixed - first send SIGINT to main process,
64 # then after 2min send SIGKILL to whole group if neccessary
65 KillMode = "mixed";
66 KillSignal = "SIGINT"; # like Ctrl+C - safe mailpile shutdown
67 TimeoutSec = 120; # wait 2min untill SIGKILL
68 };
69 environment.MAILPILE_HOME = "/var/lib/mailpile/.local/share/Mailpile";
70 };
71
72 environment.systemPackages = [ pkgs.mailpile ];
73
74 };
75
76}