stockholm/lass/3modules/ejabberd/default.nix

95 lines
2.5 KiB
Nix
Raw Normal View History

2016-10-20 18:54:38 +00:00
{ config, lib, pkgs, ... }@args: with import <stockholm/lib>; let
2016-05-19 22:01:43 +00:00
cfg = config.lass.ejabberd;
2017-10-03 21:53:09 +00:00
gen-dhparam = pkgs.writeDash "gen-dhparam" ''
set -efu
path=$1
bits=2048
# TODO regenerate dhfile after some time?
if ! test -e "$path"; then
${pkgs.openssl}/bin/openssl dhparam "$bits" > "$path"
fi
'';
2016-05-19 22:01:43 +00:00
in {
options.lass.ejabberd = {
enable = mkEnableOption "lass.ejabberd";
certfile = mkOption {
2016-07-07 20:19:29 +00:00
type = types.secret-file;
default = {
path = "${cfg.user.home}/ejabberd.pem";
owner = cfg.user;
source-path = "/var/lib/acme/lassul.us/full.pem";
};
2016-05-19 22:01:43 +00:00
};
2017-10-03 21:53:09 +00:00
dhfile = mkOption {
type = types.secret-file;
default = {
path = "${cfg.user.home}/dhparams.pem";
owner = cfg.user;
source-path = "/dev/null";
};
};
2016-05-19 22:01:43 +00:00
hosts = mkOption {
type = with types; listOf str;
};
pkgs.ejabberdctl = mkOption {
type = types.package;
default = pkgs.writeDashBin "ejabberdctl" ''
exec ${pkgs.ejabberd}/bin/ejabberdctl \
2017-10-03 21:53:09 +00:00
--config ${toFile "ejabberd.yaml" (import ./config.nix {
inherit pkgs;
config = cfg;
})} \
2016-05-19 22:01:43 +00:00
--logs ${shell.escape cfg.user.home} \
2017-10-03 21:53:09 +00:00
--spool ${shell.escape cfg.user.home} \
2016-05-19 22:01:43 +00:00
"$@"
'';
};
2017-10-03 21:53:09 +00:00
registration_watchers = mkOption {
type = types.listOf types.str;
default = [
config.krebs.users.tv.mail
];
};
2016-05-19 22:01:43 +00:00
s2s_certfile = mkOption {
2016-07-07 20:19:29 +00:00
type = types.secret-file;
2016-05-19 22:01:43 +00:00
default = cfg.certfile;
};
user = mkOption {
type = types.user;
default = {
name = "ejabberd";
home = "/var/ejabberd";
};
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.pkgs.ejabberdctl ];
2016-07-07 20:19:29 +00:00
krebs.secret.files = {
ejabberd-certfile = cfg.certfile;
ejabberd-s2s_certfile = cfg.s2s_certfile;
};
2016-05-19 22:01:43 +00:00
systemd.services.ejabberd = {
wantedBy = [ "multi-user.target" ];
2016-07-07 20:19:29 +00:00
requires = [ "secret.service" ];
after = [ "network.target" "secret.service" ];
2016-05-19 22:01:43 +00:00
serviceConfig = {
2017-10-03 21:53:09 +00:00
ExecStartPre = "${gen-dhparam} ${cfg.dhfile.path}";
ExecStart = "${cfg.pkgs.ejabberdctl}/bin/ejabberdctl foreground";
PermissionsStartOnly = true;
2016-05-19 22:01:43 +00:00
SyslogIdentifier = "ejabberd";
User = cfg.user.name;
2017-10-03 21:53:09 +00:00
TimeoutStartSec = 60;
2016-05-19 22:01:43 +00:00
};
};
users.users.${cfg.user.name} = {
inherit (cfg.user) home name uid;
createHome = true;
};
};
}