summaryrefslogtreecommitdiffstats
path: root/tv/3modules/ejabberd/default.nix
diff options
context:
space:
mode:
authorlassulus <lass@aidsballs.de>2016-02-22 01:08:46 +0100
committerlassulus <lass@aidsballs.de>2016-02-22 01:08:46 +0100
commit020fcc22000ce35337a765bfa37f4178fbbff68c (patch)
tree8485531b5285b4dce6e9b9abecba4ccad5b9b46a /tv/3modules/ejabberd/default.nix
parent2924afb8a2cb7d734b56a4a8934737129a20154c (diff)
parenta2b8eb75506fa27bc3d44f6a33d860ce7d3470e0 (diff)
Merge remote-tracking branch 'cd/master'
Diffstat (limited to 'tv/3modules/ejabberd/default.nix')
-rw-r--r--tv/3modules/ejabberd/default.nix67
1 files changed, 67 insertions, 0 deletions
diff --git a/tv/3modules/ejabberd/default.nix b/tv/3modules/ejabberd/default.nix
new file mode 100644
index 000000000..95ea24be1
--- /dev/null
+++ b/tv/3modules/ejabberd/default.nix
@@ -0,0 +1,67 @@
+{ config, lib, pkgs, ... }@args: with config.krebs.lib; let
+ cfg = config.tv.ejabberd;
+in {
+ options.tv.ejabberd = {
+ enable = mkEnableOption "tv.ejabberd";
+ certfile = mkOption {
+ type = types.secret-file;
+ default = {
+ path = "${cfg.user.home}/ejabberd.pem";
+ owner = cfg.user;
+ source-path = toString <secrets> + "/ejabberd.pem";
+ };
+ };
+ 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 {
+ type = types.secret-file;
+ default = cfg.certfile;
+ };
+ user = mkOption {
+ type = types.user;
+ default = {
+ name = "ejabberd";
+ home = "/var/ejabberd";
+ };
+ };
+ };
+ config = lib.mkIf cfg.enable {
+ environment.systemPackages = [ cfg.pkgs.ejabberdctl ];
+
+ krebs.secret.files = {
+ ejabberd-certfile = cfg.certfile;
+ ejabberd-s2s_certfile = cfg.s2s_certfile;
+ };
+
+ systemd.services.ejabberd = {
+ wantedBy = [ "multi-user.target" ];
+ requires = [ "secret.service" ];
+ after = [ "network.target" "secret.service" ];
+ 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;
+ };
+ };
+}