2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2009-03-06 13:26:29 +01:00
|
|
|
|
|
|
|
let
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
cfg = config.services.ejabberd;
|
|
|
|
|
2016-01-03 03:36:19 +01:00
|
|
|
ctlcfg = pkgs.writeText "ejabberdctl.cfg" ''
|
|
|
|
ERL_EPMD_ADDRESS=127.0.0.1
|
|
|
|
${cfg.ctlConfig}
|
|
|
|
'';
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-04-17 23:50:29 +02:00
|
|
|
ectl = ''${cfg.package}/bin/ejabberdctl ${optionalString (cfg.configFile != null) "--config ${cfg.configFile}"} --ctl-config "${ctlcfg}" --spool "${cfg.spoolDir}" --logs "${cfg.logsDir}"'';
|
2016-01-03 03:36:19 +01:00
|
|
|
|
2016-06-12 19:11:37 +02:00
|
|
|
dumps = lib.escapeShellArgs cfg.loadDumps;
|
2016-01-03 03:36:19 +01:00
|
|
|
|
|
|
|
in {
|
2009-10-12 18:36:19 +02:00
|
|
|
|
|
|
|
###### 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 {
|
2016-01-03 03:36:19 +01:00
|
|
|
type = types.bool;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Whether to enable ejabberd server";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
|
2016-01-03 03:36:19 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.ejabberd;
|
2021-10-03 18:06:03 +02:00
|
|
|
defaultText = literalExpression "pkgs.ejabberd";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "ejabberd server package to use";
|
2016-01-03 03:36:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "ejabberd";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "User under which ejabberd is ran";
|
2016-01-03 03:36:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "ejabberd";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Group under which ejabberd is ran";
|
2016-01-03 03:36:19 +01:00
|
|
|
};
|
|
|
|
|
2009-10-12 18:36:19 +02:00
|
|
|
spoolDir = mkOption {
|
2016-01-03 03:36:19 +01:00
|
|
|
type = types.path;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = "/var/lib/ejabberd";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Location of the spooldir of ejabberd";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
logsDir = mkOption {
|
2016-01-03 03:36:19 +01:00
|
|
|
type = types.path;
|
2009-10-12 18:36:19 +02:00
|
|
|
default = "/var/log/ejabberd";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Location of the logfile directory of ejabberd";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
|
2016-01-03 03:36:19 +01:00
|
|
|
configFile = mkOption {
|
2016-01-12 18:12:47 +01:00
|
|
|
type = types.nullOr types.path;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Configuration file for ejabberd in YAML format";
|
2016-01-12 18:12:47 +01:00
|
|
|
default = null;
|
2009-03-06 13:26:29 +01:00
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2016-01-03 03:36:19 +01:00
|
|
|
ctlConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Configuration of ejabberdctl";
|
2009-10-12 18:36:19 +02:00
|
|
|
};
|
|
|
|
|
2009-11-19 16:12:05 +01:00
|
|
|
loadDumps = mkOption {
|
2016-01-03 03:36:19 +01:00
|
|
|
type = types.listOf types.path;
|
2009-11-19 16:12:05 +01:00
|
|
|
default = [];
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Configuration dumps that should be loaded on the first startup";
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression "[ ./myejabberd.dump ]";
|
2009-11-19 16:12:05 +01:00
|
|
|
};
|
2016-05-07 13:31:16 +02:00
|
|
|
|
|
|
|
imagemagick = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-07-28 23:19:15 +02:00
|
|
|
description = lib.mdDoc "Add ImageMagick to server's path; allows for image thumbnailing";
|
2016-05-07 13:31:16 +02: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 {
|
2016-01-03 03:36:19 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users = optionalAttrs (cfg.user == "ejabberd") {
|
|
|
|
ejabberd = {
|
2016-01-03 03:36:19 +01:00
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.spoolDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.ejabberd;
|
2019-09-14 19:51:29 +02:00
|
|
|
};
|
|
|
|
};
|
2016-01-03 03:36:19 +01:00
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.groups = optionalAttrs (cfg.group == "ejabberd") {
|
|
|
|
ejabberd.gid = config.ids.gids.ejabberd;
|
|
|
|
};
|
2008-02-04 14:40:01 +01:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
systemd.services.ejabberd = {
|
2016-01-03 03:36:19 +01:00
|
|
|
description = "ejabberd server";
|
2016-01-06 07:50:18 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-01-03 03:36:19 +01:00
|
|
|
after = [ "network.target" ];
|
2019-04-17 23:50:29 +02:00
|
|
|
path = [ pkgs.findutils pkgs.coreutils ] ++ lib.optional cfg.imagemagick pkgs.imagemagick;
|
2016-01-03 03:36:19 +01:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
2019-04-17 23:50:29 +02:00
|
|
|
ExecStart = "${ectl} foreground";
|
|
|
|
ExecStop = "${ectl} stop";
|
|
|
|
ExecReload = "${ectl} reload_config";
|
2016-01-03 03:36:19 +01:00
|
|
|
};
|
2016-01-06 07:50:18 +01:00
|
|
|
|
|
|
|
preStart = ''
|
2016-08-12 03:31:02 +02:00
|
|
|
if [ -z "$(ls -A '${cfg.spoolDir}')" ]; then
|
|
|
|
touch "${cfg.spoolDir}/.firstRun"
|
|
|
|
fi
|
|
|
|
'';
|
2016-01-03 03:36:19 +01:00
|
|
|
|
2016-08-12 03:31:02 +02:00
|
|
|
postStart = ''
|
2016-01-03 03:36:19 +01:00
|
|
|
while ! ${ectl} status >/dev/null 2>&1; do
|
2016-08-12 03:31:02 +02:00
|
|
|
if ! kill -0 "$MAINPID"; then exit 1; fi
|
|
|
|
sleep 0.1
|
2016-01-03 03:36:19 +01:00
|
|
|
done
|
|
|
|
|
2016-08-12 03:31:02 +02:00
|
|
|
if [ -e "${cfg.spoolDir}/.firstRun" ]; then
|
|
|
|
rm "${cfg.spoolDir}/.firstRun"
|
2016-01-03 03:36:19 +01:00
|
|
|
for src in ${dumps}; do
|
|
|
|
find "$src" -type f | while read dump; do
|
|
|
|
echo "Loading configuration dump at $dump"
|
2019-04-17 23:50:29 +02:00
|
|
|
${ectl} load "$dump"
|
2016-01-03 03:36:19 +01:00
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
2016-01-06 07:50:18 +01:00
|
|
|
'';
|
|
|
|
};
|
2009-10-12 18:36:19 +02:00
|
|
|
|
2019-04-17 23:50:29 +02:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.logsDir}' 0750 ${cfg.user} ${cfg.group} -"
|
|
|
|
"d '${cfg.spoolDir}' 0700 ${cfg.user} ${cfg.group} -"
|
|
|
|
];
|
|
|
|
|
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
|
|
|
}
|