2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-03-06 12:26:29 +00:00
|
|
|
|
|
|
|
let
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
cfg = config.services.ejabberd;
|
|
|
|
|
2016-01-03 02:36:19 +00:00
|
|
|
ctlcfg = pkgs.writeText "ejabberdctl.cfg" ''
|
|
|
|
ERL_EPMD_ADDRESS=127.0.0.1
|
|
|
|
${cfg.ctlConfig}
|
|
|
|
'';
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2016-01-12 17:12:47 +00:00
|
|
|
ectl = ''${cfg.package}/bin/ejabberdctl ${if cfg.configFile == null then "" else "--config ${cfg.configFile}"} --ctl-config "${ctlcfg}" --spool "${cfg.spoolDir}" --logs "${cfg.logsDir}"'';
|
2016-01-03 02:36:19 +00:00
|
|
|
|
|
|
|
dumps = lib.concatMapStringsSep " " lib.escapeShellArg cfg.loadDumps;
|
|
|
|
|
|
|
|
in {
|
2009-10-12 17:36:19 +01:00
|
|
|
|
|
|
|
###### interface
|
2009-03-06 12:26:29 +00:00
|
|
|
|
|
|
|
options = {
|
2011-02-16 21:03:14 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
services.ejabberd = {
|
2011-02-16 21:03:14 +00:00
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
enable = mkOption {
|
2016-01-03 02:36:19 +00:00
|
|
|
type = types.bool;
|
2009-10-12 17:36:19 +01:00
|
|
|
default = false;
|
|
|
|
description = "Whether to enable ejabberd server";
|
|
|
|
};
|
|
|
|
|
2016-01-03 02:36:19 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.ejabberd;
|
|
|
|
description = "ejabberd server package to use";
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "ejabberd";
|
|
|
|
description = "User under which ejabberd is ran";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "ejabberd";
|
|
|
|
description = "Group under which ejabberd is ran";
|
|
|
|
};
|
|
|
|
|
2009-10-12 17:36:19 +01:00
|
|
|
spoolDir = mkOption {
|
2016-01-03 02:36:19 +00:00
|
|
|
type = types.path;
|
2009-10-12 17:36:19 +01:00
|
|
|
default = "/var/lib/ejabberd";
|
|
|
|
description = "Location of the spooldir of ejabberd";
|
|
|
|
};
|
|
|
|
|
|
|
|
logsDir = mkOption {
|
2016-01-03 02:36:19 +00:00
|
|
|
type = types.path;
|
2009-10-12 17:36:19 +01:00
|
|
|
default = "/var/log/ejabberd";
|
|
|
|
description = "Location of the logfile directory of ejabberd";
|
|
|
|
};
|
|
|
|
|
2016-01-03 02:36:19 +00:00
|
|
|
configFile = mkOption {
|
2016-01-12 17:12:47 +00:00
|
|
|
type = types.nullOr types.path;
|
2016-01-03 02:36:19 +00:00
|
|
|
description = "Configuration file for ejabberd in YAML format";
|
2016-01-12 17:12:47 +00:00
|
|
|
default = null;
|
2009-03-06 12:26:29 +00:00
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2016-01-03 02:36:19 +00:00
|
|
|
ctlConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Configuration of ejabberdctl";
|
2009-10-12 17:36:19 +01:00
|
|
|
};
|
|
|
|
|
2009-11-19 15:12:05 +00:00
|
|
|
loadDumps = mkOption {
|
2016-01-03 02:36:19 +00:00
|
|
|
type = types.listOf types.path;
|
2009-11-19 15:12:05 +00:00
|
|
|
default = [];
|
2016-01-03 02:36:19 +00:00
|
|
|
description = "Configuration dumps that should be loaded on the first startup";
|
2013-10-23 19:06:39 +01:00
|
|
|
example = literalExample "[ ./myejabberd.dump ]";
|
2009-11-19 15:12:05 +00:00
|
|
|
};
|
2009-03-06 12:26:29 +00:00
|
|
|
};
|
2011-02-16 21:03:14 +00:00
|
|
|
|
2009-03-06 12:26:29 +00:00
|
|
|
};
|
2011-02-16 21:03:14 +00: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 {
|
2016-01-03 02:36:19 +00:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
users.extraUsers = optionalAttrs (cfg.user == "ejabberd") (singleton
|
|
|
|
{ name = "ejabberd";
|
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.spoolDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.ejabberd;
|
|
|
|
});
|
|
|
|
|
|
|
|
users.extraGroups = optionalAttrs (cfg.group == "ejabberd") (singleton
|
|
|
|
{ name = "ejabberd";
|
|
|
|
gid = config.ids.gids.ejabberd;
|
|
|
|
});
|
2008-02-04 13:40:01 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.ejabberd = {
|
2016-01-03 02:36:19 +00:00
|
|
|
description = "ejabberd server";
|
2016-01-06 06:50:18 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-01-03 02:36:19 +00:00
|
|
|
after = [ "network.target" ];
|
|
|
|
path = [ pkgs.findutils pkgs.coreutils ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "forking";
|
|
|
|
# FIXME: runit is used for `chpst` -- can we get rid of this?
|
|
|
|
ExecStop = ''${pkgs.runit}/bin/chpst -u "${cfg.user}:${cfg.group}" ${ectl} stop'';
|
|
|
|
ExecReload = ''${pkgs.runit}/bin/chpst -u "${cfg.user}:${cfg.group}" ${ectl} reload_config'';
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
PermissionsStartOnly = true;
|
|
|
|
};
|
2016-01-06 06:50:18 +00:00
|
|
|
|
|
|
|
preStart = ''
|
2016-01-03 02:36:19 +00:00
|
|
|
mkdir -p -m750 "${cfg.logsDir}"
|
|
|
|
chown "${cfg.user}:${cfg.group}" "${cfg.logsDir}"
|
2016-01-06 06:50:18 +00:00
|
|
|
|
2016-01-03 02:36:19 +00:00
|
|
|
mkdir -p -m750 "/var/lock/ejabberdctl"
|
|
|
|
chown "${cfg.user}:${cfg.group}" "/var/lock/ejabberdctl"
|
2016-01-06 06:50:18 +00:00
|
|
|
|
2016-01-03 02:36:19 +00:00
|
|
|
mkdir -p -m750 "${cfg.spoolDir}"
|
|
|
|
chown -R "${cfg.user}:${cfg.group}" "${cfg.spoolDir}"
|
2016-01-06 06:50:18 +00:00
|
|
|
'';
|
2011-02-16 21:03:14 +00:00
|
|
|
|
2016-01-03 02:36:19 +00:00
|
|
|
script = ''
|
|
|
|
[ -z "$(ls -A '${cfg.spoolDir}')" ] && firstRun=1
|
|
|
|
|
|
|
|
${ectl} start
|
|
|
|
|
|
|
|
count=0
|
|
|
|
while ! ${ectl} status >/dev/null 2>&1; do
|
|
|
|
if [ $count -eq 30 ]; then
|
|
|
|
echo "ejabberd server hasn't started in 30 seconds, giving up"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
count=$((count++))
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$firstRun" ]; then
|
|
|
|
for src in ${dumps}; do
|
|
|
|
find "$src" -type f | while read dump; do
|
|
|
|
echo "Loading configuration dump at $dump"
|
|
|
|
${ectl} load "$dump"
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
2016-01-06 06:50:18 +00:00
|
|
|
'';
|
|
|
|
};
|
2009-10-12 17:36:19 +01:00
|
|
|
|
2013-10-15 13:47:51 +01:00
|
|
|
security.pam.services.ejabberd = {};
|
|
|
|
|
2009-03-06 12:26:29 +00:00
|
|
|
};
|
2011-02-16 21:03:14 +00:00
|
|
|
|
2008-02-04 13:40:01 +00:00
|
|
|
}
|