summary refs log tree commit diff
path: root/pkgs/servers/monitoring/zabbix/server.nix
blob: 4046cc7d8bb5931f73feb36d08f4149c0502cf38 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{ stdenv, fetchurl, pkgconfig, curl, libevent, libiconv, libxml2, openssl, pcre, zlib
, jabberSupport ? true, iksemel
, ldapSupport ? true, openldap
, odbcSupport ? true, unixODBC
, snmpSupport ? true, net-snmp
, sshSupport ? true, libssh2
, mysqlSupport ? false, libmysqlclient
, postgresqlSupport ? false, postgresql
}:

# ensure exactly one primary database type is selected
assert mysqlSupport -> !postgresqlSupport;
assert postgresqlSupport -> !mysqlSupport;

let
  inherit (stdenv.lib) optional optionalString;
in
  import ./versions.nix ({ version, sha256 }:
    stdenv.mkDerivation {
      pname = "zabbix-server";
      inherit version;

      src = fetchurl {
        url = "mirror://sourceforge/zabbix/ZABBIX%20Latest%20Stable/${version}/zabbix-${version}.tar.gz";
        inherit sha256;
      };

      nativeBuildInputs = [ pkgconfig ];
      buildInputs = [
        curl
        libevent
        libiconv
        libxml2
        openssl
        pcre
        zlib
      ]
      ++ optional odbcSupport unixODBC
      ++ optional jabberSupport iksemel
      ++ optional ldapSupport openldap
      ++ optional snmpSupport net-snmp
      ++ optional sshSupport libssh2
      ++ optional mysqlSupport libmysqlclient
      ++ optional postgresqlSupport postgresql;

      configureFlags = [
        "--enable-server"
        "--with-iconv"
        "--with-libcurl"
        "--with-libevent"
        "--with-libpcre"
        "--with-libxml2"
        "--with-openssl=${openssl.dev}"
        "--with-zlib=${zlib}"
      ]
      ++ optional odbcSupport "--with-unixodbc"
      ++ optional jabberSupport "--with-jabber"
      ++ optional ldapSupport "--with-ldap=${openldap.dev}"
      ++ optional snmpSupport "--with-net-snmp"
      ++ optional sshSupport "--with-ssh2=${libssh2.dev}"
      ++ optional mysqlSupport "--with-mysql"
      ++ optional postgresqlSupport "--with-postgresql";

      prePatch = ''
        find database -name data.sql -exec sed -i 's|/usr/bin/||g' {} +
      '';

      postInstall = ''
        mkdir -p $out/share/zabbix/database/
        cp -r include $out/
      '' + optionalString mysqlSupport ''
        mkdir -p $out/share/zabbix/database/mysql
        cp -prvd database/mysql/*.sql $out/share/zabbix/database/mysql/
      '' + optionalString postgresqlSupport ''
        mkdir -p $out/share/zabbix/database/postgresql
        cp -prvd database/postgresql/*.sql $out/share/zabbix/database/postgresql/
      '';

      meta = with stdenv.lib; {
        description = "An enterprise-class open source distributed monitoring solution";
        homepage = "https://www.zabbix.com/";
        license = licenses.gpl2;
        maintainers = with maintainers; [ mmahut psyanticy ];
        platforms = platforms.linux;
      };
    })