2009-10-12 18:36:19 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-03-06 13:26:29 +01:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
cfg = config.services.ejabberd;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-03-06 13:26:29 +01:00
|
|
|
|
|
|
|
options = {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
services.ejabberd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable ejabberd server";
|
|
|
|
};
|
|
|
|
|
|
|
|
spoolDir = mkOption {
|
|
|
|
default = "/var/lib/ejabberd";
|
|
|
|
description = "Location of the spooldir of ejabberd";
|
|
|
|
};
|
|
|
|
|
|
|
|
logsDir = mkOption {
|
|
|
|
default = "/var/log/ejabberd";
|
|
|
|
description = "Location of the logfile directory of ejabberd";
|
|
|
|
};
|
|
|
|
|
|
|
|
confDir = mkOption {
|
|
|
|
default = "/var/ejabberd";
|
|
|
|
description = "Location of the config directory of ejabberd";
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
virtualHosts = mkOption {
|
|
|
|
default = "\"localhost\"";
|
|
|
|
description = "Virtualhosts that ejabberd should host. Hostnames are surrounded with doublequotes and separated by commas";
|
|
|
|
};
|
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
###### implementation
|
2008-02-04 14:40:01 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
config = mkIf cfg.enable {
|
2008-02-04 14:40:01 +01:00
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.ejabberd =
|
2009-10-12 18:36:19 +02:00
|
|
|
{ description = "EJabberd server";
|
2008-02-04 14:40:01 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
startOn = "network-interface/started";
|
|
|
|
stopOn = "network-interfaces/stop";
|
2009-03-06 13:26:29 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
# Initialise state data
|
|
|
|
mkdir -p ${cfg.logsDir}
|
|
|
|
|
|
|
|
if ! test -d ${cfg.spoolDir}
|
|
|
|
then
|
|
|
|
cp -av ${pkgs.ejabberd}/var/lib/ejabberd /var/lib
|
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p ${cfg.confDir}
|
|
|
|
test -f ${cfg.confDir}/ejabberd.cfg || sed -e 's|{hosts, \["localhost"\]}.|{hosts, \[${cfg.virtualHosts}\]}.|' ${pkgs.ejabberd}/etc/ejabberd/ejabberd.cfg > ${cfg.confDir}/ejabberd.cfg
|
|
|
|
'';
|
|
|
|
|
|
|
|
exec = "${pkgs.bash}/bin/sh -c 'export PATH=$PATH:${pkgs.ejabberd}/sbin:${pkgs.coreutils}/bin:${pkgs.bash}/bin; cd ~; ejabberdctl --logs ${cfg.logsDir} --spool ${cfg.spoolDir} --config ${cfg.confDir}/ejabberd.cfg start; sleep 1d'";
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
2009-03-06 13:26:29 +01:00
|
|
|
${pkgs.ejabberd}/sbin/ejabberdctl stop
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2008-02-04 14:40:01 +01:00
|
|
|
}
|