1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 inherit (pkgs) prayer;
8
9 cfg = config.services.prayer;
10
11 stateDir = "/var/lib/prayer";
12
13 prayerUser = "prayer";
14 prayerGroup = "prayer";
15
16 prayerExtraCfg = pkgs.writeText "extraprayer.cf" ''
17 prefix = "${prayer}"
18 var_prefix = "${stateDir}"
19 prayer_user = "${prayerUser}"
20 prayer_group = "${prayerGroup}"
21 sendmail_path = "/run/wrappers/bin/sendmail"
22
23 use_http_port ${cfg.port}
24
25 ${cfg.extraConfig}
26 '';
27
28 prayerCfg = pkgs.runCommand "prayer.cf" { preferLocalBuild = true; } ''
29 # We have to remove the http_port 80, or it will start a server there
30 cat ${prayer}/etc/prayer.cf | grep -v http_port > $out
31 cat ${prayerExtraCfg} >> $out
32 '';
33
34in
35
36{
37
38 ###### interface
39
40 options = {
41
42 services.prayer = {
43
44 enable = mkEnableOption "the prayer webmail http server";
45
46 port = mkOption {
47 default = 2080;
48 type = types.port;
49 description = ''
50 Port the prayer http server is listening to.
51 '';
52 };
53
54 extraConfig = mkOption {
55 type = types.lines;
56 default = "" ;
57 description = ''
58 Extra configuration. Contents will be added verbatim to the configuration file.
59 '';
60 };
61 };
62
63 };
64
65
66 ###### implementation
67
68 config = mkIf config.services.prayer.enable {
69 environment.systemPackages = [ prayer ];
70
71 users.users.${prayerUser} =
72 { uid = config.ids.uids.prayer;
73 description = "Prayer daemon user";
74 home = stateDir;
75 };
76
77 users.groups.${prayerGroup} =
78 { gid = config.ids.gids.prayer; };
79
80 systemd.services.prayer = {
81 wantedBy = [ "multi-user.target" ];
82 serviceConfig.Type = "forking";
83 preStart = ''
84 mkdir -m 0755 -p ${stateDir}
85 chown ${prayerUser}.${prayerGroup} ${stateDir}
86 '';
87 script = "${prayer}/sbin/prayer --config-file=${prayerCfg}";
88 };
89 };
90}