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

108 lines
2.8 KiB
Nix
Raw Normal View History

2016-10-20 18:54:38 +00:00
{ config, lib, pkgs, ... }@args: with import <stockholm/lib>; let
2017-07-22 17:18:02 +00:00
2016-02-21 05:05:49 +00:00
cfg = config.tv.ejabberd;
2017-07-22 17:18:02 +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-02-21 05:05:49 +00:00
in {
options.tv.ejabberd = {
enable = mkEnableOption "tv.ejabberd";
certfile = mkOption {
2021-12-25 10:41:20 +00:00
type = types.absolute-pathname;
default = toString <secrets> + "/ejabberd.pem";
2017-07-22 17:18:02 +00:00
};
2016-02-21 05:05:49 +00:00
hosts = mkOption {
type = with types; listOf str;
};
pkgs.ejabberd = mkOption {
2016-02-21 05:05:49 +00:00
type = types.package;
default = pkgs.symlinkJoin {
name = "ejabberd-wrapper";
paths = [
(pkgs.writeDashBin "ejabberdctl" ''
exec ${pkgs.ejabberd}/bin/ejabberdctl \
--config ${toFile "ejabberd.yaml" (import ./config.nix {
inherit pkgs;
config = cfg;
})} \
--logs ${shell.escape cfg.user.home} \
--spool ${shell.escape cfg.user.home} \
"$@"
'')
pkgs.ejabberd
];
};
2016-02-21 05:05:49 +00:00
};
2017-07-22 17:18:02 +00:00
registration_watchers = mkOption {
type = types.listOf types.str;
default = [
config.krebs.users.tv.mail
];
};
2016-02-21 05:05:49 +00:00
user = mkOption {
2016-02-21 05:39:12 +00:00
type = types.user;
default = {
name = "ejabberd";
2018-12-29 11:58:45 +00:00
home = "/var/lib/ejabberd";
2016-02-21 05:05:49 +00:00
};
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [
(pkgs.symlinkJoin {
name = "ejabberd-sudo-wrapper";
paths = [
(pkgs.writeDashBin "ejabberdctl" ''
set -efu
cd ${shell.escape cfg.user.home}
exec /run/wrappers/bin/sudo \
-u ${shell.escape cfg.user.name} \
${cfg.pkgs.ejabberd}/bin/ejabberdctl "$@"
'')
cfg.pkgs.ejabberd
];
})
];
2016-02-21 05:05:49 +00:00
2021-12-25 10:41:20 +00:00
krebs.systemd.services.ejabberd = {};
2016-02-21 05:05:49 +00:00
systemd.services.ejabberd = {
wantedBy = [ "multi-user.target" ];
2021-12-25 10:41:20 +00:00
after = [ "network.target" ];
2016-02-21 05:05:49 +00:00
serviceConfig = {
2021-12-25 10:41:20 +00:00
ExecStart = pkgs.writeDash "ejabberd" ''
${pkgs.coreutils}/bin/ln -s "$CREDENTIALS_DIRECTORY" /tmp/credentials
${gen-dhparam} /var/lib/ejabberd/dhfile
exec ${cfg.pkgs.ejabberd}/bin/ejabberdctl foreground
'';
LoadCredential = [
"certfile:${cfg.certfile}"
];
2017-07-22 17:18:02 +00:00
PermissionsStartOnly = true;
2021-12-25 10:41:20 +00:00
PrivateTmp = true;
2016-02-21 05:05:49 +00:00
SyslogIdentifier = "ejabberd";
2021-12-25 10:41:20 +00:00
StateDirectory = "ejabberd";
2016-02-21 05:05:49 +00:00
User = cfg.user.name;
2017-07-22 17:18:02 +00:00
TimeoutStartSec = 60;
2016-02-21 05:05:49 +00:00
};
};
users.users.${cfg.user.name} = {
2016-02-21 05:56:57 +00:00
inherit (cfg.user) home name uid;
2016-02-21 05:05:49 +00:00
createHome = true;
2021-12-23 23:48:38 +00:00
group = cfg.user.name;
2021-06-15 13:53:47 +00:00
isSystemUser = true;
2016-02-21 05:05:49 +00:00
};
2021-12-23 23:48:38 +00:00
users.groups.${cfg.user.name} = {};
2016-02-21 05:05:49 +00:00
};
}