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