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 = {
|
2011-02-16 22:03:14 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
services.ejabberd = {
|
2011-02-16 22:03:14 +01:00
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
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-11-19 16:12:05 +01:00
|
|
|
loadDumps = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "Configuration dump that should be loaded on the first startup";
|
2011-02-16 22:03:14 +01:00
|
|
|
example = [ ./myejabberd.dump ];
|
2009-11-19 16:12:05 +01:00
|
|
|
};
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2011-02-16 22:03:14 +01:00
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2011-02-16 22:03:14 +01: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 {
|
2009-11-02 13:13:09 +01:00
|
|
|
environment.systemPackages = [ pkgs.ejabberd ];
|
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-11-23 14:29:47 +01:00
|
|
|
startOn = "started network-interfaces";
|
2009-11-06 23:19:17 +01:00
|
|
|
stopOn = "stopping network-interfaces";
|
2011-02-16 22:03:14 +01:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
PATH = "$PATH:${pkgs.ejabberd}/sbin:${pkgs.ejabberd}/bin:${pkgs.coreutils}/bin:${pkgs.bash}/bin:${pkgs.gnused}/bin";
|
|
|
|
};
|
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
|
2011-02-16 22:03:14 +01:00
|
|
|
initialize=1
|
2009-10-12 18:36:19 +02:00
|
|
|
cp -av ${pkgs.ejabberd}/var/lib/ejabberd /var/lib
|
|
|
|
fi
|
2011-02-16 22:03:14 +01:00
|
|
|
|
2009-11-02 13:13:09 +01:00
|
|
|
if ! test -d ${cfg.confDir}
|
2011-02-16 22:03:14 +01:00
|
|
|
then
|
|
|
|
mkdir -p ${cfg.confDir}
|
|
|
|
cp ${pkgs.ejabberd}/etc/ejabberd/* ${cfg.confDir}
|
|
|
|
sed -e 's|{hosts, \["localhost"\]}.|{hosts, \[${cfg.virtualHosts}\]}.|' ${pkgs.ejabberd}/etc/ejabberd/ejabberd.cfg > ${cfg.confDir}/ejabberd.cfg
|
|
|
|
fi
|
|
|
|
|
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} start
|
|
|
|
|
|
|
|
${if cfg.loadDumps == [] then "" else
|
|
|
|
''
|
|
|
|
if [ "$initialize" = "1" ]
|
|
|
|
then
|
|
|
|
# Wait until the ejabberd server is available for use
|
2009-11-19 16:17:04 +01:00
|
|
|
count=0
|
|
|
|
while ! ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} status
|
|
|
|
do
|
|
|
|
if [ $count -eq 30 ]
|
|
|
|
then
|
|
|
|
echo "Tried 30 times, giving up..."
|
2011-02-16 22:03:14 +01:00
|
|
|
exit 1
|
2009-11-19 16:17:04 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Ejabberd daemon not yet started. Waiting for 1 second..."
|
|
|
|
count=$((count++))
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2011-02-16 22:03:14 +01:00
|
|
|
${concatMapStrings (dump:
|
|
|
|
''
|
|
|
|
echo "Importing dump: ${dump}"
|
|
|
|
|
|
|
|
if [ -f ${dump} ]
|
|
|
|
then
|
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} load ${dump}
|
|
|
|
elif [ -d ${dump} ]
|
|
|
|
then
|
|
|
|
for i in ${dump}/ejabberd-dump/*
|
|
|
|
do
|
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} load $i
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
'') cfg.loadDumps}
|
|
|
|
fi
|
|
|
|
''}
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
2011-02-16 22:03:14 +01:00
|
|
|
''
|
2009-11-19 14:15:15 +01:00
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} stop
|
2009-10-12 18:36:19 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-10-15 14:47:51 +02:00
|
|
|
security.pam.services.ejabberd = {};
|
|
|
|
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2011-02-16 22:03:14 +01:00
|
|
|
|
2008-02-04 14:40:01 +01:00
|
|
|
}
|