at 21.11-pre 1.6 kB view raw
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 = mkEnableOption "Mailpile the mail client"; 22 23 hostname = mkOption { 24 type = types.str; 25 default = "localhost"; 26 description = "Listen to this hostname or ip."; 27 }; 28 port = mkOption { 29 type = types.port; 30 default = 33411; 31 description = "Listen on this port."; 32 }; 33 }; 34 35 }; 36 37 38 ###### implementation 39 40 config = mkIf config.services.mailpile.enable { 41 42 users.users.mailpile = 43 { uid = config.ids.uids.mailpile; 44 description = "Mailpile user"; 45 createHome = true; 46 home = "/var/lib/mailpile"; 47 }; 48 49 users.groups.mailpile = 50 { gid = config.ids.gids.mailpile; 51 }; 52 53 systemd.services.mailpile = 54 { 55 description = "Mailpile server."; 56 after = [ "network.target" ]; 57 wantedBy = [ "multi-user.target" ]; 58 serviceConfig = { 59 User = "mailpile"; 60 ExecStart = "${pkgs.mailpile}/bin/mailpile --www ${hostname}:${port} --wait"; 61 # mixed - first send SIGINT to main process, 62 # then after 2min send SIGKILL to whole group if neccessary 63 KillMode = "mixed"; 64 KillSignal = "SIGINT"; # like Ctrl+C - safe mailpile shutdown 65 TimeoutSec = 120; # wait 2min untill SIGKILL 66 }; 67 environment.MAILPILE_HOME = "/var/lib/mailpile/.local/share/Mailpile"; 68 }; 69 70 environment.systemPackages = [ pkgs.mailpile ]; 71 72 }; 73 74}