summary refs log tree commit diff
path: root/nixos/modules/services/networking/openfire.nix
blob: c3b4ba90b4e77e5864ac8d3bb99202281645452c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{ config, lib, pkgs, ... }:

with lib;

let

  inherit (pkgs) jre openfire coreutils which gnugrep gawk gnused;

  extraStartDependency =
    if config.services.openfire.usePostgreSQL then "and started postgresql" else "";

in

{

  ###### interface

  options = {

    services.openfire = {

      enable = mkOption {
        default = false;
        description = "
          Whether to enable OpenFire XMPP server.
        ";
      };

      usePostgreSQL = mkOption {
        default = true;
        description = "
          Whether you use PostgreSQL service for your storage back-end.
        ";
      };

    };

  };


  ###### implementation

  config = mkIf config.services.openfire.enable {

    assertions = singleton
      { assertion = !(config.services.openfire.usePostgreSQL -> config.services.postgresql.enable);
        message = "OpenFire assertion failed.";
      };

    jobs.openfire =
      { description = "OpenFire XMPP server";

        startOn = "started networking ${extraStartDependency}";

        script =
          ''
            export PATH=${jre}/bin:${openfire}/bin:${coreutils}/bin:${which}/bin:${gnugrep}/bin:${gawk}/bin:${gnused}/bin
            export HOME=/tmp
            mkdir /var/log/openfire || true
            mkdir /etc/openfire || true
            for i in ${openfire}/conf.inst/*; do
                if ! test -f /etc/openfire/$(basename $i); then
                    cp $i /etc/openfire/
                fi
            done
            openfire start
          ''; # */
      };

  };

}