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