2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2011-11-09 20:48:12 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2011-11-09 20:48:12 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (pkgs) prayer;
|
|
|
|
|
2011-11-09 21:08:50 +00:00
|
|
|
cfg = config.services.prayer;
|
|
|
|
|
2011-11-09 20:48:12 +00:00
|
|
|
stateDir = "/var/lib/prayer";
|
|
|
|
|
|
|
|
prayerUser = "prayer";
|
|
|
|
prayerGroup = "prayer";
|
|
|
|
|
|
|
|
prayerExtraCfg = pkgs.writeText "extraprayer.cf" ''
|
|
|
|
prefix = "${prayer}"
|
|
|
|
var_prefix = "${stateDir}"
|
|
|
|
prayer_user = "${prayerUser}"
|
|
|
|
prayer_group = "${prayerGroup}"
|
|
|
|
sendmail_path = "/var/setuid-wrappers/sendmail"
|
|
|
|
|
2011-11-09 21:08:50 +00:00
|
|
|
use_http_port ${cfg.port}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
2011-11-09 20:48:12 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
prayerCfg = pkgs.runCommand "prayer.cf" { } ''
|
2012-06-10 15:51:43 +01:00
|
|
|
# We have to remove the http_port 80, or it will start a server there
|
|
|
|
cat ${prayer}/etc/prayer.cf | grep -v http_port > $out
|
|
|
|
cat ${prayerExtraCfg} >> $out
|
2011-11-09 20:48:12 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.prayer = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2011-11-09 21:08:50 +00:00
|
|
|
Whether to run the prayer webmail http server.
|
2011-11-09 20:48:12 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2011-11-09 21:08:50 +00:00
|
|
|
port = mkOption {
|
|
|
|
default = "2080";
|
2011-11-09 20:48:12 +00:00
|
|
|
description = ''
|
2011-11-09 21:08:50 +00:00
|
|
|
Port the prayer http server is listening to.
|
2011-11-09 20:48:12 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "" ;
|
|
|
|
description = ''
|
|
|
|
Extra configuration. Contents will be added verbatim to the configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.prayer.enable {
|
|
|
|
environment.systemPackages = [ prayer ];
|
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = prayerUser;
|
|
|
|
uid = config.ids.uids.prayer;
|
2012-03-22 10:11:15 +00:00
|
|
|
description = "Prayer daemon user";
|
2011-11-09 20:48:12 +00:00
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups = singleton
|
|
|
|
{ name = prayerGroup;
|
|
|
|
gid = config.ids.gids.prayer;
|
|
|
|
};
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.prayer = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${prayerUser}.${prayerGroup} ${stateDir}
|
|
|
|
'';
|
|
|
|
script = "${prayer}/sbin/prayer --config-file=${prayerCfg}";
|
|
|
|
};
|
2011-11-09 20:48:12 +00:00
|
|
|
};
|
|
|
|
}
|