lol
1{ stdenv, runCommand, lib, fetchFromGitHub, fetchpatch, cmake, flex, bison, systemd
2, boost, openssl, patchelf, mariadb-connector-c, postgresql, zlib, tzdata
3# Databases
4, withMysql ? true, withPostgresql ? false
5# Features
6, withChecker ? true, withCompat ? false, withLivestatus ? false
7, withNotification ? true, withPerfdata ? true, withIcingadb ? true
8, nameSuffix ? "" }:
9
10stdenv.mkDerivation rec {
11 pname = "icinga2${nameSuffix}";
12 version = "2.14.0";
13
14 src = fetchFromGitHub {
15 owner = "icinga";
16 repo = "icinga2";
17 rev = "v${version}";
18 sha256 = "sha256-MrNfkbbmID27Ht2sDSklrPvRvCmewOuOOBIFnHJz1zE=";
19 };
20
21 patches = [
22 ./etc-icinga2.patch # Makes /etc/icinga2 relative to / instead of the store path
23 ./no-systemd-service.patch # Prevent systemd service from being written to /usr
24 ./no-var-directories.patch # Prevent /var directories from being created
25 ];
26
27 cmakeFlags = let
28 mkFeatureFlag = label: value: "-DICINGA2_WITH_${label}=${if value then "ON" else "OFF"}";
29 in [
30 # Paths
31 "-DCMAKE_INSTALL_SYSCONFDIR=etc"
32 "-DCMAKE_INSTALL_LOCALSTATEDIR=/var"
33 "-DCMAKE_INSTALL_FULL_SBINDIR=bin"
34 "-DICINGA2_RUNDIR=/run"
35 "-DMYSQL_INCLUDE_DIR=${mariadb-connector-c.dev}/include/mariadb"
36 "-DMYSQL_LIB=${mariadb-connector-c.out}/lib/mariadb/libmysqlclient.a"
37 "-DICINGA2_PLUGINDIR=bin"
38 "-DICINGA2_LTO_BUILD=yes"
39 # Features
40 (mkFeatureFlag "MYSQL" withMysql)
41 (mkFeatureFlag "PGSQL" withPostgresql)
42 (mkFeatureFlag "CHECKER" withChecker)
43 (mkFeatureFlag "COMPAT" withCompat)
44 (mkFeatureFlag "LIVESTATUS" withLivestatus)
45 (mkFeatureFlag "NOTIFICATION" withNotification)
46 (mkFeatureFlag "PERFDATA" withPerfdata)
47 (mkFeatureFlag "ICINGADB" withIcingadb)
48 # Misc.
49 "-DICINGA2_USER=icinga2"
50 "-DICINGA2_GROUP=icinga2"
51 "-DICINGA2_GIT_VERSION_INFO=OFF"
52 "-DUSE_SYSTEMD=ON"
53 ];
54
55 outputs = [ "out" "doc" ];
56
57 buildInputs = [ boost openssl systemd ]
58 ++ lib.optional withPostgresql postgresql;
59
60 nativeBuildInputs = [ cmake flex bison patchelf ];
61
62 doCheck = true;
63 nativeCheckInputs = [ tzdata ]; # legacytimeperiod/dst needs this
64
65 postFixup = ''
66 rm -r $out/etc/logrotate.d $out/etc/sysconfig $out/lib/icinga2/prepare-dirs
67
68 # Fix hardcoded paths
69 sed -i 's:/usr/bin/::g' $out/etc/icinga2/scripts/*
70
71 # Get rid of sbin
72 sed -i 's/sbin/bin/g' $out/lib/icinga2/safe-reload
73 rm $out/sbin
74
75 ${lib.optionalString withMysql ''
76 # Add dependencies of the MySQL shim to the shared library
77 patchelf --add-needed ${zlib.out}/lib/libz.so $(readlink -f $out/lib/icinga2/libmysql_shim.so)
78
79 # Make Icinga find the MySQL shim
80 icinga2Bin=$out/lib/icinga2/sbin/icinga2
81 patchelf --set-rpath $out/lib/icinga2:$(patchelf --print-rpath $icinga2Bin) $icinga2Bin
82 ''}
83 '';
84
85 vim = runCommand "vim-icinga2-${version}" { pname = "vim-icinga2"; } ''
86 mkdir -p $out/share/vim-plugins
87 cp -r "${src}/tools/syntax/vim" $out/share/vim-plugins/icinga2
88 '';
89
90 meta = {
91 description = "Open source monitoring system";
92 homepage = "https://www.icinga.com";
93 license = lib.licenses.gpl2Plus;
94 platforms = lib.platforms.linux;
95 maintainers = with lib.maintainers; [ das_j ];
96 };
97}