at 17.09-beta 2.0 kB view raw
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" { } '' 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 = mkOption { 45 default = false; 46 description = '' 47 Whether to run the prayer webmail http server. 48 ''; 49 }; 50 51 port = mkOption { 52 default = "2080"; 53 description = '' 54 Port the prayer http server is listening to. 55 ''; 56 }; 57 58 extraConfig = mkOption { 59 type = types.lines; 60 default = "" ; 61 description = '' 62 Extra configuration. Contents will be added verbatim to the configuration file. 63 ''; 64 }; 65 }; 66 67 }; 68 69 70 ###### implementation 71 72 config = mkIf config.services.prayer.enable { 73 environment.systemPackages = [ prayer ]; 74 75 users.extraUsers = singleton 76 { name = prayerUser; 77 uid = config.ids.uids.prayer; 78 description = "Prayer daemon user"; 79 home = stateDir; 80 }; 81 82 users.extraGroups = singleton 83 { name = prayerGroup; 84 gid = config.ids.gids.prayer; 85 }; 86 87 systemd.services.prayer = { 88 wantedBy = [ "multi-user.target" ]; 89 serviceConfig.Type = "forking"; 90 preStart = '' 91 mkdir -m 0755 -p ${stateDir} 92 chown ${prayerUser}.${prayerGroup} ${stateDir} 93 ''; 94 script = "${prayer}/sbin/prayer --config-file=${prayerCfg}"; 95 }; 96 }; 97}