nixpkgs/pkgs/tools/system/netdata/default.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

286 lines
9.9 KiB
Nix
Raw Normal View History

2024-09-12 23:21:37 +00:00
{
lib,
stdenv,
fetchFromGitHub,
bash,
buildGoModule,
cmake,
cups,
curl,
2024-09-12 23:37:55 +00:00
darwin,
2024-09-12 23:21:37 +00:00
freeipmi,
go,
google-cloud-cpp,
grpc,
jemalloc,
json_c,
libbpf,
libcap,
libelf,
libmnl,
libnetfilter_acct,
libossp_uuid,
libuuid,
libuv,
libyaml,
lm_sensors,
lz4,
makeWrapper,
ninja,
nixosTests,
openssl,
2024-09-12 23:37:55 +00:00
overrideSDK,
2024-09-12 23:21:37 +00:00
pkg-config,
protobuf,
snappy,
systemd,
withCloud ? false,
withCloudUi ? false,
withConnPrometheus ? false,
withConnPubSub ? false,
withCups ? false,
withDBengine ? true,
withDebug ? false,
withEbpf ? false,
2024-09-12 23:37:55 +00:00
withIpmi ? (stdenv.hostPlatform.isLinux),
withNetfilter ? (stdenv.hostPlatform.isLinux),
withNetworkViewer ? (stdenv.hostPlatform.isLinux),
2024-09-12 23:21:37 +00:00
withSsl ? true,
2024-09-12 23:37:55 +00:00
withSystemdJournal ? (stdenv.hostPlatform.isLinux),
2024-09-12 23:21:37 +00:00
zlib,
2019-07-03 10:49:29 +00:00
}:
2024-09-12 23:37:55 +00:00
let
stdenv' = if stdenv.hostPlatform.isDarwin then overrideSDK stdenv "11.0" else stdenv;
in
stdenv'.mkDerivation (finalAttrs: {
2024-10-10 19:26:42 +00:00
version = "1.47.4";
pname = "netdata";
2016-04-14 21:43:01 +00:00
2019-12-07 21:04:30 +00:00
src = fetchFromGitHub {
owner = "netdata";
repo = "netdata";
2024-09-12 23:23:53 +00:00
rev = "v${finalAttrs.version}";
2024-09-12 23:21:37 +00:00
hash =
if withCloudUi then
2024-10-10 19:26:42 +00:00
"sha256-PCaY6J3X4zUUJ8kRCGmLLbk2Pkp5CnH3rxOaoAdsKG4="
# we delete the v2 GUI after fetching
2024-09-12 23:21:37 +00:00
else
2024-10-10 19:26:42 +00:00
"sha256-W4g/ns+XfBSf6iACIW+6lfzZJLMktTfe5/n3egL27XE=";
2021-05-19 17:35:24 +00:00
fetchSubmodules = true;
# Remove v2 dashboard distributed under NCUL1. Make sure an empty
# Makefile.am exists, as autoreconf will get confused otherwise.
postFetch = lib.optionalString (!withCloudUi) ''
rm -rf $out/src/web/gui/v2/*
touch $out/src/web/gui/v2/Makefile.am
'';
2016-04-14 21:43:01 +00:00
};
strictDeps = true;
2024-09-12 23:21:37 +00:00
nativeBuildInputs = [
cmake
pkg-config
makeWrapper
go
ninja
] ++ lib.optionals withCups [ cups.dev ];
2023-03-01 11:50:28 +00:00
# bash is only used to rewrite shebangs
2024-09-12 23:21:37 +00:00
buildInputs =
[
bash
curl
jemalloc
json_c
libuv
zlib
libyaml
]
2024-09-12 23:37:55 +00:00
++ lib.optionals stdenv.hostPlatform.isDarwin (
with darwin.apple_sdk.frameworks;
[
CoreFoundation
IOKit
libossp_uuid
]
)
++ lib.optionals (stdenv.hostPlatform.isLinux) [
2024-09-12 23:21:37 +00:00
libcap
libuuid
2024-09-12 23:37:55 +00:00
lm_sensors
2024-09-12 23:21:37 +00:00
]
++ lib.optionals withCups [ cups ]
++ lib.optionals withDBengine [ lz4 ]
++ lib.optionals withIpmi [ freeipmi ]
2024-09-12 23:21:37 +00:00
++ lib.optionals withNetfilter [
libmnl
libnetfilter_acct
]
++ lib.optionals withConnPubSub [
google-cloud-cpp
grpc
]
++ lib.optionals withConnPrometheus [ snappy ]
2024-09-12 23:21:37 +00:00
++ lib.optionals withEbpf [
libelf
libbpf
]
++ lib.optionals (withCloud || withConnPrometheus) [ protobuf ]
++ lib.optionals withSystemdJournal [ systemd ]
++ lib.optionals withSsl [ openssl ];
2016-04-14 21:43:01 +00:00
patches = [
2024-06-22 01:27:50 +00:00
# Allow ndsudo to use non-hardcoded `PATH`
# See https://github.com/netdata/netdata/pull/17377#issuecomment-2183017868
# https://github.com/netdata/netdata/security/advisories/GHSA-pmhq-4cxq-wj93
./ndsudo-fix-path.patch
# Allow building without non-free v2 dashboard.
2024-06-22 01:27:50 +00:00
./dashboard-v2-removal.patch
];
2024-08-21 22:34:48 +00:00
# Guard against unused build-time development inputs in closure. Without
# the ./skip-CONFIGURE_COMMAND.patch patch the closure retains inputs up
# to bootstrap tools:
# https://github.com/NixOS/nixpkgs/pull/175719
# We pick zlib.dev as a simple canary package with pkg-config input.
disallowedReferences = lib.optional (!withDebug) zlib.dev;
2023-03-03 14:33:52 +00:00
donStrip = withDebug;
env.NIX_CFLAGS_COMPILE = lib.optionalString withDebug "-O1 -ggdb -DNETDATA_INTERNAL_CHECKS=1";
2019-07-04 10:08:11 +00:00
2024-09-12 23:21:37 +00:00
postInstall =
''
# Relocate one folder above.
mv $out/usr/* $out/
''
2024-09-12 23:37:55 +00:00
+ lib.optionalString (stdenv.hostPlatform.isLinux) ''
2024-09-12 23:21:37 +00:00
# rename this plugin so netdata will look for setuid wrapper
mv $out/libexec/netdata/plugins.d/apps.plugin \
$out/libexec/netdata/plugins.d/apps.plugin.org
mv $out/libexec/netdata/plugins.d/cgroup-network \
$out/libexec/netdata/plugins.d/cgroup-network.org
mv $out/libexec/netdata/plugins.d/perf.plugin \
$out/libexec/netdata/plugins.d/perf.plugin.org
mv $out/libexec/netdata/plugins.d/slabinfo.plugin \
$out/libexec/netdata/plugins.d/slabinfo.plugin.org
mv $out/libexec/netdata/plugins.d/debugfs.plugin \
$out/libexec/netdata/plugins.d/debugfs.plugin.org
${lib.optionalString withSystemdJournal ''
mv $out/libexec/netdata/plugins.d/systemd-journal.plugin \
$out/libexec/netdata/plugins.d/systemd-journal.plugin.org
''}
${lib.optionalString withIpmi ''
mv $out/libexec/netdata/plugins.d/freeipmi.plugin \
$out/libexec/netdata/plugins.d/freeipmi.plugin.org
''}
${lib.optionalString withNetworkViewer ''
mv $out/libexec/netdata/plugins.d/network-viewer.plugin \
$out/libexec/netdata/plugins.d/network-viewer.plugin.org
''}
${lib.optionalString (!withCloudUi) ''
rm -rf $out/share/netdata/web/index.html
cp $out/share/netdata/web/v1/index.html $out/share/netdata/web/index.html
''}
'';
2024-09-12 23:37:55 +00:00
preConfigure = ''
export GOCACHE=$TMPDIR/go-cache
export GOPATH=$TMPDIR/go
export GOSUMDB=off
2024-08-21 22:34:48 +00:00
substituteInPlace packaging/cmake/Modules/NetdataGoTools.cmake \
--replace-fail \
'GOPROXY=https://proxy.golang.org' \
2024-09-12 23:23:53 +00:00
'GOPROXY=file://${finalAttrs.passthru.netdata-go-modules}'
2024-08-21 22:34:48 +00:00
# Prevent the path to be caught into the Nix store path.
substituteInPlace CMakeLists.txt \
2024-08-21 22:34:48 +00:00
--replace-fail 'set(CACHE_DIR "''${NETDATA_RUNTIME_PREFIX}/var/cache/netdata")' 'set(CACHE_DIR "/var/cache/netdata")' \
--replace-fail 'set(CONFIG_DIR "''${NETDATA_RUNTIME_PREFIX}/etc/netdata")' 'set(CONFIG_DIR "/etc/netdata")' \
--replace-fail 'set(LIBCONFIG_DIR "''${NETDATA_RUNTIME_PREFIX}/usr/lib/netdata/conf.d")' 'set(LIBCONFIG_DIR "${placeholder "out"}/share/netdata/conf.d")' \
--replace-fail 'set(LOG_DIR "''${NETDATA_RUNTIME_PREFIX}/var/log/netdata")' 'set(LOG_DIR "/var/log/netdata")' \
--replace-fail 'set(PLUGINS_DIR "''${NETDATA_RUNTIME_PREFIX}/usr/libexec/netdata/plugins.d")' 'set(PLUGINS_DIR "${placeholder "out"}/libexec/netdata/plugins.d")' \
--replace-fail 'set(VARLIB_DIR "''${NETDATA_RUNTIME_PREFIX}/var/lib/netdata")' 'set(VARLIB_DIR "/var/lib/netdata")' \
--replace-fail 'set(pkglibexecdir_POST "''${NETDATA_RUNTIME_PREFIX}/usr/libexec/netdata")' 'set(pkglibexecdir_POST "${placeholder "out"}/libexec/netdata")' \
--replace-fail 'set(localstatedir_POST "''${NETDATA_RUNTIME_PREFIX}/var")' 'set(localstatedir_POST "/var")' \
--replace-fail 'set(sbindir_POST "''${NETDATA_RUNTIME_PREFIX}/''${BINDIR}")' 'set(sbindir_POST "${placeholder "out"}/bin")' \
--replace-fail 'set(configdir_POST "''${NETDATA_RUNTIME_PREFIX}/etc/netdata")' 'set(configdir_POST "/etc/netdata")' \
--replace-fail 'set(libconfigdir_POST "''${NETDATA_RUNTIME_PREFIX}/usr/lib/netdata/conf.d")' 'set(libconfigdir_POST "${placeholder "out"}/share/netdata/conf.d")' \
--replace-fail 'set(cachedir_POST "''${NETDATA_RUNTIME_PREFIX}/var/cache/netdata")' 'set(libconfigdir_POST "/var/cache/netdata")' \
--replace-fail 'set(registrydir_POST "''${NETDATA_RUNTIME_PREFIX}/var/lib/netdata/registry")' 'set(registrydir_POST "/var/lib/netdata/registry")' \
--replace-fail 'set(varlibdir_POST "''${NETDATA_RUNTIME_PREFIX}/var/lib/netdata")' 'set(varlibdir_POST "/var/lib/netdata")'
2019-03-07 21:01:48 +00:00
'';
cmakeFlags = [
"-DWEB_DIR=share/netdata/web"
(lib.cmakeBool "ENABLE_CLOUD" withCloud)
# ACLK is agent cloud link.
(lib.cmakeBool "ENABLE_ACLK" withCloud)
(lib.cmakeBool "ENABLE_DASHBOARD_V2" withCloudUi)
(lib.cmakeBool "ENABLE_DBENGINE" withDBengine)
(lib.cmakeBool "ENABLE_PLUGIN_FREEIPMI" withIpmi)
(lib.cmakeBool "ENABLE_PLUGIN_SYSTEMD_JOURNAL" withSystemdJournal)
(lib.cmakeBool "ENABLE_PLUGIN_NETWORK_VIEWER" withNetworkViewer)
(lib.cmakeBool "ENABLE_PLUGIN_EBPF" withEbpf)
(lib.cmakeBool "ENABLE_PLUGIN_XENSTAT" false)
(lib.cmakeBool "ENABLE_PLUGIN_CUPS" withCups)
(lib.cmakeBool "ENABLE_EXPORTER_PROMETHEUS_REMOTE_WRITE" withConnPrometheus)
(lib.cmakeBool "ENABLE_JEMALLOC" true)
# Suggested by upstream.
"-G Ninja"
];
2018-11-14 16:01:41 +00:00
postFixup = ''
wrapProgram $out/bin/netdata-claim.sh --prefix PATH : ${lib.makeBinPath [ openssl ]}
wrapProgram $out/libexec/netdata/plugins.d/cgroup-network-helper.sh --prefix PATH : ${lib.makeBinPath [ bash ]}
wrapProgram $out/bin/netdatacli --set NETDATA_PIPENAME /run/netdata/ipc
# Time to cleanup the output directory.
unlink $out/sbin
cp $out/etc/netdata/edit-config $out/bin/netdata-edit-config
mv $out/lib/netdata/conf.d $out/share/netdata/conf.d
rm -rf $out/{var,usr,etc}
2016-10-14 10:05:42 +00:00
'';
enableParallelBuilding = true;
2022-06-18 20:21:18 +00:00
passthru = rec {
2024-09-12 23:21:37 +00:00
netdata-go-modules =
(buildGoModule {
pname = "netdata-go-plugins";
2024-09-12 23:23:53 +00:00
inherit (finalAttrs) version src;
2024-09-12 23:23:53 +00:00
sourceRoot = "${finalAttrs.src.name}/src/go/plugin/go.d";
2024-09-12 23:21:37 +00:00
vendorHash = "sha256-NZ1tg+lvXNgypqmjjb5f7dHH6DIA9VOa4PMM4eq11n0=";
doCheck = false;
proxyVendor = true;
2024-09-12 23:21:37 +00:00
ldflags = [
"-s"
"-w"
2024-09-12 23:23:53 +00:00
"-X main.version=${finalAttrs.version}"
2024-09-12 23:21:37 +00:00
];
2024-09-12 23:21:37 +00:00
passthru.tests = tests;
2024-09-12 23:23:53 +00:00
meta = finalAttrs.meta // {
2024-09-12 23:21:37 +00:00
description = "Netdata orchestrator for data collection modules written in Go";
mainProgram = "godplugin";
license = lib.licenses.gpl3Only;
};
}).goModules;
inherit withIpmi withNetworkViewer;
tests.netdata = nixosTests.netdata;
};
2020-08-28 08:49:26 +00:00
meta = with lib; {
2024-09-12 23:37:55 +00:00
broken = stdenv.buildPlatform != stdenv.hostPlatform || withEbpf;
2016-04-14 21:43:01 +00:00
description = "Real-time performance monitoring tool";
homepage = "https://www.netdata.cloud/";
2023-05-28 10:48:00 +00:00
changelog = "https://github.com/netdata/netdata/releases/tag/v${version}";
2024-09-12 23:21:37 +00:00
license = [ licenses.gpl3Plus ] ++ lib.optionals (withCloudUi) [ licenses.ncul1 ];
2018-11-14 16:01:41 +00:00
platforms = platforms.unix;
maintainers = [ ];
2016-04-14 21:43:01 +00:00
};
2024-09-12 23:23:53 +00:00
})