Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 301 lines 10 kB view raw
1{ 2 bash, 3 bison, 4 buildGoModule, 5 cmake, 6 cups, 7 curl, 8 dlib, 9 fetchFromGitHub, 10 fetchurl, 11 flex, 12 freeipmi, 13 go, 14 google-cloud-cpp, 15 grpc, 16 jemalloc, 17 json_c, 18 lib, 19 libbacktrace, 20 libbpf, 21 libcap, 22 libelf, 23 libmnl, 24 libnetfilter_acct, 25 libossp_uuid, 26 libuuid, 27 libuv, 28 libyaml, 29 lm_sensors, 30 lz4, 31 makeWrapper, 32 ninja, 33 nixosTests, 34 openssl, 35 pkg-config, 36 protobuf, 37 replaceVars, 38 snappy, 39 stdenv, 40 systemd, 41 zlib, 42 43 withCloudUi ? false, 44 withConnPrometheus ? false, 45 withConnPubSub ? false, 46 withCups ? false, 47 withDBengine ? true, 48 withDebug ? false, 49 withEbpf ? false, 50 withIpmi ? (stdenv.hostPlatform.isLinux), 51 withLibbacktrace ? true, 52 withNdsudo ? false, 53 withNetfilter ? (stdenv.hostPlatform.isLinux), 54 withNetworkViewer ? (stdenv.hostPlatform.isLinux), 55 withSsl ? true, 56 withSystemdJournal ? (stdenv.hostPlatform.isLinux), 57 withML ? true, 58}: 59stdenv.mkDerivation (finalAttrs: { 60 version = "2.5.3"; 61 pname = "netdata"; 62 63 src = fetchFromGitHub { 64 owner = "netdata"; 65 repo = "netdata"; 66 rev = "v${finalAttrs.version}"; 67 hash = "sha256-OdH6cQ2dYvbeLh9ljaqmdr02VN2qbvNUXbPNCEkNzxc="; 68 fetchSubmodules = true; 69 }; 70 71 strictDeps = true; 72 73 nativeBuildInputs = [ 74 bison 75 cmake 76 flex 77 go 78 makeWrapper 79 ninja 80 pkg-config 81 ] 82 ++ lib.optionals withCups [ cups.dev ]; 83 84 # bash is only used to rewrite shebangs 85 buildInputs = [ 86 bash 87 curl 88 jemalloc 89 json_c 90 libuv 91 libyaml 92 lz4 93 protobuf 94 zlib 95 ] 96 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 97 libossp_uuid 98 ] 99 100 ++ lib.optionals (stdenv.hostPlatform.isLinux) [ 101 libcap 102 libuuid 103 lm_sensors 104 ] 105 ++ lib.optionals withConnPrometheus [ snappy ] 106 ++ lib.optionals withConnPubSub [ 107 google-cloud-cpp 108 grpc 109 ] 110 ++ lib.optionals withCups [ cups ] 111 ++ lib.optionals withEbpf [ 112 libbpf 113 libelf 114 ] 115 ++ lib.optionals withIpmi [ freeipmi ] 116 ++ lib.optionals withLibbacktrace [ libbacktrace ] 117 ++ lib.optionals withNetfilter [ 118 libmnl 119 libnetfilter_acct 120 ] 121 ++ lib.optionals withSsl [ openssl ] 122 ++ lib.optionals withSystemdJournal [ systemd ]; 123 124 patches = [ 125 # Allow ndsudo to use non-hardcoded `PATH` 126 # See https://github.com/netdata/netdata/pull/17377#issuecomment-2183017868 127 # https://github.com/netdata/netdata/security/advisories/GHSA-pmhq-4cxq-wj93 128 ./ndsudo-fix-path.patch 129 130 ./use-local-libbacktrace.patch 131 ] 132 ++ lib.optional withCloudUi ( 133 replaceVars ./dashboard-v3-add.patch { 134 # FIXME web.archive.org link can be replace once https://github.com/netdata/netdata-cloud/issues/1081 resolved 135 # last update 04/01/2025 04:45:14 136 dashboardTarball = fetchurl { 137 url = "https://web.archive.org/web/20250401044514/https://app.netdata.cloud/agent.tar.gz"; 138 hash = "sha256-NtmM1I3VrvFErMoBl+w63Nt0DzOOsaB98cxE/axm8mE="; 139 }; 140 } 141 ); 142 143 # Guard against unused build-time development inputs in closure. Without 144 # the ./skip-CONFIGURE_COMMAND.patch patch the closure retains inputs up 145 # to bootstrap tools: 146 # https://github.com/NixOS/nixpkgs/pull/175719 147 # We pick zlib.dev as a simple canary package with pkg-config input. 148 disallowedReferences = lib.optional (!withDebug) zlib.dev; 149 150 donStrip = withDebug || withLibbacktrace; 151 env.NIX_CFLAGS_COMPILE = lib.optionalString withDebug "-O1 -ggdb -DNETDATA_INTERNAL_CHECKS=1"; 152 153 postInstall = '' 154 # Relocate one folder above. 155 mv $out/usr/* $out/ 156 '' 157 + lib.optionalString (stdenv.hostPlatform.isLinux) '' 158 # rename this plugin so netdata will look for setuid wrapper 159 mv $out/libexec/netdata/plugins.d/apps.plugin \ 160 $out/libexec/netdata/plugins.d/apps.plugin.org 161 mv $out/libexec/netdata/plugins.d/cgroup-network \ 162 $out/libexec/netdata/plugins.d/cgroup-network.org 163 mv $out/libexec/netdata/plugins.d/perf.plugin \ 164 $out/libexec/netdata/plugins.d/perf.plugin.org 165 mv $out/libexec/netdata/plugins.d/slabinfo.plugin \ 166 $out/libexec/netdata/plugins.d/slabinfo.plugin.org 167 mv $out/libexec/netdata/plugins.d/debugfs.plugin \ 168 $out/libexec/netdata/plugins.d/debugfs.plugin.org 169 ${lib.optionalString withSystemdJournal '' 170 mv $out/libexec/netdata/plugins.d/systemd-journal.plugin \ 171 $out/libexec/netdata/plugins.d/systemd-journal.plugin.org 172 ''} 173 ${lib.optionalString withIpmi '' 174 mv $out/libexec/netdata/plugins.d/freeipmi.plugin \ 175 $out/libexec/netdata/plugins.d/freeipmi.plugin.org 176 ''} 177 ${lib.optionalString withNetworkViewer '' 178 mv $out/libexec/netdata/plugins.d/network-viewer.plugin \ 179 $out/libexec/netdata/plugins.d/network-viewer.plugin.org 180 ''} 181 ${lib.optionalString withNdsudo '' 182 mv $out/libexec/netdata/plugins.d/ndsudo \ 183 $out/libexec/netdata/plugins.d/ndsudo.org 184 185 ln -s /var/lib/netdata/ndsudo/ndsudo $out/libexec/netdata/plugins.d/ndsudo 186 ''} 187 ''; 188 189 preConfigure = '' 190 export GOCACHE=$TMPDIR/go-cache 191 export GOPATH=$TMPDIR/go 192 export GOSUMDB=off 193 194 substituteInPlace packaging/cmake/Modules/NetdataGoTools.cmake \ 195 --replace-fail \ 196 'GOPROXY=https://proxy.golang.org' \ 197 'GOPROXY=file://${finalAttrs.passthru.netdata-go-modules}' 198 199 # Prevent the path to be caught into the Nix store path. 200 substituteInPlace CMakeLists.txt \ 201 --replace-fail 'set(CACHE_DIR "''${NETDATA_RUNTIME_PREFIX}/var/cache/netdata")' 'set(CACHE_DIR "/var/cache/netdata")' \ 202 --replace-fail 'set(CONFIG_DIR "''${NETDATA_RUNTIME_PREFIX}/etc/netdata")' 'set(CONFIG_DIR "/etc/netdata")' \ 203 --replace-fail 'set(LIBCONFIG_DIR "''${NETDATA_RUNTIME_PREFIX}/usr/lib/netdata/conf.d")' 'set(LIBCONFIG_DIR "${placeholder "out"}/share/netdata/conf.d")' \ 204 --replace-fail 'set(LOG_DIR "''${NETDATA_RUNTIME_PREFIX}/var/log/netdata")' 'set(LOG_DIR "/var/log/netdata")' \ 205 --replace-fail 'set(PLUGINS_DIR "''${NETDATA_RUNTIME_PREFIX}/usr/libexec/netdata/plugins.d")' 'set(PLUGINS_DIR "${placeholder "out"}/libexec/netdata/plugins.d")' \ 206 --replace-fail 'set(VARLIB_DIR "''${NETDATA_RUNTIME_PREFIX}/var/lib/netdata")' 'set(VARLIB_DIR "/var/lib/netdata")' \ 207 --replace-fail 'set(pkglibexecdir_POST "''${NETDATA_RUNTIME_PREFIX}/usr/libexec/netdata")' 'set(pkglibexecdir_POST "${placeholder "out"}/libexec/netdata")' \ 208 --replace-fail 'set(localstatedir_POST "''${NETDATA_RUNTIME_PREFIX}/var")' 'set(localstatedir_POST "/var")' \ 209 --replace-fail 'set(sbindir_POST "''${NETDATA_RUNTIME_PREFIX}/''${BINDIR}")' 'set(sbindir_POST "${placeholder "out"}/bin")' \ 210 --replace-fail 'set(configdir_POST "''${NETDATA_RUNTIME_PREFIX}/etc/netdata")' 'set(configdir_POST "/etc/netdata")' \ 211 --replace-fail 'set(libconfigdir_POST "''${NETDATA_RUNTIME_PREFIX}/usr/lib/netdata/conf.d")' 'set(libconfigdir_POST "${placeholder "out"}/share/netdata/conf.d")' \ 212 --replace-fail 'set(cachedir_POST "''${NETDATA_RUNTIME_PREFIX}/var/cache/netdata")' 'set(libconfigdir_POST "/var/cache/netdata")' \ 213 --replace-fail 'set(registrydir_POST "''${NETDATA_RUNTIME_PREFIX}/var/lib/netdata/registry")' 'set(registrydir_POST "/var/lib/netdata/registry")' \ 214 --replace-fail 'set(varlibdir_POST "''${NETDATA_RUNTIME_PREFIX}/var/lib/netdata")' 'set(varlibdir_POST "/var/lib/netdata")' \ 215 --replace-fail 'set(BUILD_INFO_CMAKE_CACHE_ARCHIVE_PATH "usr/share/netdata")' 'set(BUILD_INFO_CMAKE_CACHE_ARCHIVE_PATH "${placeholder "out"}/share/netdata")' 216 ''; 217 218 cmakeFlags = [ 219 "-DWEB_DIR=share/netdata/web" 220 (lib.cmakeBool "ENABLE_DASHBOARD" withCloudUi) 221 (lib.cmakeBool "ENABLE_DBENGINE" withDBengine) 222 (lib.cmakeBool "ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE" withConnPrometheus) 223 (lib.cmakeBool "ENABLE_JEMALLOC" true) 224 (lib.cmakeBool "ENABLE_LIBBACKTRACE" withLibbacktrace) 225 (lib.cmakeBool "ENABLE_PLUGIN_CUPS" withCups) 226 (lib.cmakeBool "ENABLE_PLUGIN_EBPF" withEbpf) 227 (lib.cmakeBool "ENABLE_PLUGIN_FREEIPMI" withIpmi) 228 (lib.cmakeBool "ENABLE_PLUGIN_NETWORK_VIEWER" withNetworkViewer) 229 (lib.cmakeBool "ENABLE_PLUGIN_SYSTEMD_JOURNAL" withSystemdJournal) 230 (lib.cmakeBool "ENABLE_PLUGIN_XENSTAT" false) 231 (lib.cmakeBool "ENABLE_ML" withML) 232 # Suggested by upstream. 233 "-G Ninja" 234 ] 235 ++ lib.optional withML "-DNETDATA_DLIB_SOURCE_PATH=${dlib.src}"; 236 237 postFixup = '' 238 wrapProgram $out/bin/netdata-claim.sh --prefix PATH : ${lib.makeBinPath [ openssl ]} 239 wrapProgram $out/libexec/netdata/plugins.d/cgroup-network-helper.sh --prefix PATH : ${lib.makeBinPath [ bash ]} 240 wrapProgram $out/bin/netdatacli --set NETDATA_PIPENAME /run/netdata/ipc 241 ${lib.optionalString (stdenv.hostPlatform.isLinux) '' 242 substituteInPlace $out/lib/netdata/conf.d/go.d/sensors.conf --replace-fail '/usr/bin/sensors' '${lm_sensors}/bin/sensors' 243 ''} 244 245 # Time to cleanup the output directory. 246 unlink $out/sbin 247 cp $out/etc/netdata/edit-config $out/bin/netdata-edit-config 248 mv $out/lib/netdata/conf.d $out/share/netdata/conf.d 249 rm -rf $out/{var,usr,etc} 250 ''; 251 252 enableParallelBuilding = true; 253 254 passthru = rec { 255 netdata-go-modules = 256 (buildGoModule { 257 pname = "netdata-go-plugins"; 258 inherit (finalAttrs) version src; 259 260 sourceRoot = "${finalAttrs.src.name}/src/go/plugin/go.d"; 261 262 vendorHash = "sha256-N03IGTtF78PCo4kf0Sdtzv6f8z47ohg8g3YIXtINRjU="; 263 doCheck = false; 264 proxyVendor = true; 265 266 ldflags = [ 267 "-s" 268 "-w" 269 "-X main.version=${finalAttrs.version}" 270 ]; 271 272 passthru.tests = tests; 273 meta = finalAttrs.meta // { 274 description = "Netdata orchestrator for data collection modules written in Go"; 275 mainProgram = "godplugin"; 276 license = lib.licenses.gpl3Only; 277 }; 278 }).goModules; 279 inherit 280 withIpmi 281 withNdsudo 282 withNetworkViewer 283 withSystemdJournal 284 ; 285 tests.netdata = nixosTests.netdata; 286 }; 287 288 meta = with lib; { 289 broken = stdenv.buildPlatform != stdenv.hostPlatform || withEbpf; 290 description = "Real-time performance monitoring tool"; 291 homepage = "https://www.netdata.cloud/"; 292 changelog = "https://github.com/netdata/netdata/releases/tag/v${version}"; 293 license = [ licenses.gpl3Plus ] ++ lib.optionals (withCloudUi) [ licenses.ncul1 ]; 294 mainProgram = "netdata"; 295 platforms = platforms.unix; 296 maintainers = with maintainers; [ 297 mkg20001 298 rhoriguchi 299 ]; 300 }; 301})