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

68 lines
1.8 KiB
Nix
Raw Normal View History

2016-05-19 22:01:43 +00:00
{ config, lib, pkgs, ... }@args: with config.krebs.lib; let
cfg = config.lass.ejabberd;
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
};
hosts = mkOption {
type = with types; listOf str;
};
pkgs.ejabberdctl = mkOption {
type = types.package;
default = pkgs.writeDashBin "ejabberdctl" ''
set -efu
export SPOOLDIR=${shell.escape cfg.user.home}
export EJABBERD_CONFIG_PATH=${shell.escape (import ./config.nix args)}
exec ${pkgs.ejabberd}/bin/ejabberdctl \
--logs ${shell.escape cfg.user.home} \
"$@"
'';
};
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 = {
Type = "oneshot";
RemainAfterExit = "yes";
PermissionsStartOnly = "true";
SyslogIdentifier = "ejabberd";
User = cfg.user.name;
ExecStart = "${cfg.pkgs.ejabberdctl}/bin/ejabberdctl start";
};
};
users.users.${cfg.user.name} = {
inherit (cfg.user) home name uid;
createHome = true;
};
};
}