2009-10-12 17:36:19 +01:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
2009-03-06 12:26:29 +00:00
|
|
|
|
|
|
|
let
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
cfg = config.services.ejabberd;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2009-03-06 12:26:29 +00:00
|
|
|
|
|
|
|
options = {
|
2009-10-12 17:36:19 +01: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 12:26:29 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
virtualHosts = mkOption {
|
|
|
|
default = "\"localhost\"";
|
|
|
|
description = "Virtualhosts that ejabberd should host. Hostnames are surrounded with doublequotes and separated by commas";
|
|
|
|
};
|
|
|
|
|
2009-03-06 12:26:29 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2009-03-06 12:26:29 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2009-03-06 12:26:29 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
###### implementation
|
2008-02-04 13:40:01 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
config = mkIf cfg.enable {
|
2009-11-02 12:13:09 +00:00
|
|
|
environment.systemPackages = [ pkgs.ejabberd ];
|
2008-02-04 13:40:01 +00:00
|
|
|
|
2009-10-12 19:09:34 +01:00
|
|
|
jobs.ejabberd =
|
2009-10-12 17:36:19 +01:00
|
|
|
{ description = "EJabberd server";
|
2008-02-04 13:40:01 +00:00
|
|
|
|
2009-11-06 22:19:17 +00:00
|
|
|
startOn = "started network-interface";
|
|
|
|
stopOn = "stopping network-interfaces";
|
2009-11-19 13:15:15 +00:00
|
|
|
|
|
|
|
environment = {
|
|
|
|
PATH = "$PATH:${pkgs.ejabberd}/sbin:${pkgs.ejabberd}/bin:${pkgs.coreutils}/bin:${pkgs.bash}/bin:${pkgs.gnused}/bin";
|
|
|
|
};
|
2009-03-06 12:26:29 +00:00
|
|
|
|
2009-10-12 17:36:19 +01: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
|
2009-11-02 12:13:09 +00:00
|
|
|
|
|
|
|
if ! test -d ${cfg.confDir}
|
|
|
|
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
|
2009-11-19 13:15:15 +00:00
|
|
|
|
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} start
|
2009-10-12 17:36:19 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
postStop =
|
|
|
|
''
|
2009-11-19 13:15:15 +00:00
|
|
|
ejabberdctl --config-dir ${cfg.confDir} --logs ${cfg.logsDir} --spool ${cfg.spoolDir} stop
|
2009-10-12 17:36:19 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2009-03-06 12:26:29 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2008-02-04 13:40:01 +00:00
|
|
|
}
|