3
0
Fork 0
forked from mirrors/nixpkgs
nixpkgs/nixos/modules/services/networking/ejabberd.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

158 lines
4 KiB
Nix
Raw Normal View History

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