1 { config, lib, pkgs, ... }:
7 cfg = config.services.ejabberd;
9 ctlcfg = pkgs.writeText "ejabberdctl.cfg" ''
10 ERL_EPMD_ADDRESS=127.0.0.1
14 ectl = ''${cfg.package}/bin/ejabberdctl ${optionalString (cfg.configFile != null) "--config ${cfg.configFile}"} --ctl-config "${ctlcfg}" --spool "${cfg.spoolDir}" --logs "${cfg.logsDir}"'';
16 dumps = lib.escapeShellArgs cfg.loadDumps;
29 description = lib.mdDoc "Whether to enable ejabberd server";
34 default = pkgs.ejabberd;
35 defaultText = literalExpression "pkgs.ejabberd";
36 description = lib.mdDoc "ejabberd server package to use";
42 description = lib.mdDoc "User under which ejabberd is ran";
48 description = lib.mdDoc "Group under which ejabberd is ran";
53 default = "/var/lib/ejabberd";
54 description = lib.mdDoc "Location of the spooldir of ejabberd";
59 default = "/var/log/ejabberd";
60 description = lib.mdDoc "Location of the logfile directory of ejabberd";
63 configFile = mkOption {
64 type = types.nullOr types.path;
65 description = lib.mdDoc "Configuration file for ejabberd in YAML format";
69 ctlConfig = mkOption {
72 description = lib.mdDoc "Configuration of ejabberdctl";
75 loadDumps = mkOption {
76 type = types.listOf types.path;
78 description = lib.mdDoc "Configuration dumps that should be loaded on the first startup";
79 example = literalExpression "[ ./myejabberd.dump ]";
82 imagemagick = mkOption {
85 description = lib.mdDoc "Add ImageMagick to server's path; allows for image thumbnailing";
94 config = mkIf cfg.enable {
95 environment.systemPackages = [ cfg.package ];
97 users.users = optionalAttrs (cfg.user == "ejabberd") {
102 uid = config.ids.uids.ejabberd;
106 users.groups = optionalAttrs (cfg.group == "ejabberd") {
107 ejabberd.gid = config.ids.gids.ejabberd;
110 systemd.services.ejabberd = {
111 description = "ejabberd server";
112 wantedBy = [ "multi-user.target" ];
113 after = [ "network.target" ];
114 path = [ pkgs.findutils pkgs.coreutils ] ++ lib.optional cfg.imagemagick pkgs.imagemagick;
119 ExecStart = "${ectl} foreground";
120 ExecStop = "${ectl} stop";
121 ExecReload = "${ectl} reload_config";
125 if [ -z "$(ls -A '${cfg.spoolDir}')" ]; then
126 touch "${cfg.spoolDir}/.firstRun"
131 while ! ${ectl} status >/dev/null 2>&1; do
132 if ! kill -0 "$MAINPID"; then exit 1; fi
136 if [ -e "${cfg.spoolDir}/.firstRun" ]; then
137 rm "${cfg.spoolDir}/.firstRun"
138 for src in ${dumps}; do
139 find "$src" -type f | while read dump; do
140 echo "Loading configuration dump at $dump"
148 systemd.tmpfiles.rules = [
149 "d '${cfg.logsDir}' 0750 ${cfg.user} ${cfg.group} -"
150 "d '${cfg.spoolDir}' 0700 ${cfg.user} ${cfg.group} -"
153 security.pam.services.ejabberd = {};