2023-05-24 13:37:59 +00:00
|
|
|
{ lib
|
|
|
|
, buildGoModule
|
|
|
|
, fetchFromGitHub
|
2023-10-09 19:29:22 +00:00
|
|
|
, fetchYarnDeps
|
2024-04-21 15:54:59 +00:00
|
|
|
, fixup-yarn-lock
|
2023-05-24 13:37:59 +00:00
|
|
|
, grafana-agent
|
2024-04-21 15:54:59 +00:00
|
|
|
, nix-update-script
|
2023-05-24 13:37:59 +00:00
|
|
|
, nixosTests
|
2023-10-09 19:29:22 +00:00
|
|
|
, nodejs
|
2023-05-24 13:37:59 +00:00
|
|
|
, stdenv
|
|
|
|
, systemd
|
|
|
|
, testers
|
2023-10-09 19:29:22 +00:00
|
|
|
, yarn
|
2023-05-24 13:37:59 +00:00
|
|
|
}:
|
2021-02-05 17:12:51 +00:00
|
|
|
|
|
|
|
buildGoModule rec {
|
|
|
|
pname = "grafana-agent";
|
2024-10-04 16:56:33 +00:00
|
|
|
version = "0.43.3";
|
2021-02-05 17:12:51 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "grafana";
|
|
|
|
repo = "agent";
|
2023-07-15 17:15:38 +00:00
|
|
|
rev = "v${version}";
|
2024-10-04 16:56:33 +00:00
|
|
|
hash = "sha256-10H3qcvjbmwKL06u+gCxfAdn1z6HaJ/8sWoVa2/ojnA=";
|
2021-02-05 17:12:51 +00:00
|
|
|
};
|
|
|
|
|
2024-10-04 16:56:33 +00:00
|
|
|
vendorHash = "sha256-NtFdrdDnuLT5CSax81smNnZxe+I9OouwVyIANyTNzF8=";
|
2023-04-29 16:46:19 +00:00
|
|
|
proxyVendor = true; # darwin/linux hash mismatch
|
2022-11-04 12:27:35 +00:00
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
frontendYarnOfflineCache = fetchYarnDeps {
|
2024-06-05 15:53:02 +00:00
|
|
|
yarnLock = src + "/internal/web/ui/yarn.lock";
|
2024-09-26 11:04:55 +00:00
|
|
|
hash = "sha256-bnJL7W7VfJIrJKvRt9Q6kdEyjLH/IJoCi0TENxz7SUE=";
|
2023-10-09 19:29:22 +00:00
|
|
|
};
|
|
|
|
|
2022-11-04 12:27:35 +00:00
|
|
|
ldflags = let
|
2024-06-05 15:53:02 +00:00
|
|
|
prefix = "github.com/grafana/agent/internal/build";
|
2022-11-04 12:27:35 +00:00
|
|
|
in [
|
|
|
|
"-s" "-w"
|
2024-06-05 15:53:02 +00:00
|
|
|
# https://github.com/grafana/agent/blob/v0.41.0/Makefile#L132-L137
|
2022-11-04 12:27:35 +00:00
|
|
|
"-X ${prefix}.Version=${version}"
|
|
|
|
"-X ${prefix}.Branch=v${version}"
|
|
|
|
"-X ${prefix}.Revision=v${version}"
|
|
|
|
"-X ${prefix}.BuildUser=nix"
|
|
|
|
"-X ${prefix}.BuildDate=1980-01-01T00:00:00Z"
|
|
|
|
];
|
2021-07-14 22:03:04 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
nativeBuildInputs = [ fixup-yarn-lock nodejs yarn ];
|
2023-10-09 19:29:22 +00:00
|
|
|
|
2022-04-27 09:35:20 +00:00
|
|
|
tags = [
|
2023-10-09 19:29:22 +00:00
|
|
|
"builtinassets"
|
2022-04-27 09:35:20 +00:00
|
|
|
"nonetwork"
|
|
|
|
"nodocker"
|
2022-12-28 21:21:41 +00:00
|
|
|
"promtail_journal_enabled"
|
2021-07-14 22:03:04 +00:00
|
|
|
];
|
2021-02-05 17:12:51 +00:00
|
|
|
|
2022-11-04 12:27:35 +00:00
|
|
|
subPackages = [
|
2023-04-29 16:46:19 +00:00
|
|
|
"cmd/grafana-agent"
|
|
|
|
"cmd/grafana-agentctl"
|
2024-06-05 15:53:02 +00:00
|
|
|
"internal/web/ui"
|
2022-11-04 12:27:35 +00:00
|
|
|
];
|
|
|
|
|
2023-10-09 19:29:22 +00:00
|
|
|
preBuild = ''
|
|
|
|
export HOME="$TMPDIR"
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
pushd internal/web/ui
|
2024-01-02 11:29:13 +00:00
|
|
|
fixup-yarn-lock yarn.lock
|
2023-10-09 19:29:22 +00:00
|
|
|
yarn config --offline set yarn-offline-mirror $frontendYarnOfflineCache
|
|
|
|
yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
|
|
|
|
patchShebangs node_modules
|
|
|
|
yarn --offline run build
|
|
|
|
popd
|
|
|
|
'';
|
|
|
|
|
|
|
|
# do not pass preBuild to go-modules.drv, as it would otherwise fail to build.
|
|
|
|
# but even if it would work, it simply isn't needed in that scope.
|
|
|
|
overrideModAttrs = (_: {
|
|
|
|
preBuild = null;
|
|
|
|
});
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
# uses go-systemd, which uses libsystemd headers
|
|
|
|
# https://github.com/coreos/go-systemd/issues/351
|
2024-09-26 11:04:55 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = toString (lib.optionals stdenv.hostPlatform.isLinux [ "-I${lib.getDev systemd}/include" ]);
|
2021-02-05 17:12:51 +00:00
|
|
|
|
|
|
|
# go-systemd uses libsystemd under the hood, which does dlopen(libsystemd) at
|
|
|
|
# runtime.
|
|
|
|
# Add to RUNPATH so it can be found.
|
2024-09-26 11:04:55 +00:00
|
|
|
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
|
2021-02-05 17:12:51 +00:00
|
|
|
patchelf \
|
2023-04-29 16:46:19 +00:00
|
|
|
--set-rpath "${lib.makeLibraryPath [ (lib.getLib systemd) ]}:$(patchelf --print-rpath $out/bin/grafana-agent)" \
|
|
|
|
$out/bin/grafana-agent
|
2021-02-05 17:12:51 +00:00
|
|
|
'';
|
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
passthru = {
|
|
|
|
tests = {
|
|
|
|
inherit (nixosTests) grafana-agent;
|
|
|
|
version = testers.testVersion {
|
|
|
|
inherit version;
|
|
|
|
command = "${lib.getExe grafana-agent} --version";
|
|
|
|
package = grafana-agent;
|
|
|
|
};
|
2023-05-24 13:37:59 +00:00
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
updateScript = nix-update-script { };
|
|
|
|
# alias for nix-update to be able to find and update this attribute
|
|
|
|
offlineCache = frontendYarnOfflineCache;
|
2023-05-24 13:37:59 +00:00
|
|
|
};
|
2022-06-16 17:23:12 +00:00
|
|
|
|
2023-07-15 17:15:38 +00:00
|
|
|
meta = {
|
2024-06-20 14:57:18 +00:00
|
|
|
description = "Lightweight subset of Prometheus and more, optimized for Grafana Cloud";
|
2023-07-15 17:15:38 +00:00
|
|
|
license = lib.licenses.asl20;
|
2021-02-05 17:12:51 +00:00
|
|
|
homepage = "https://grafana.com/products/cloud";
|
2023-07-15 17:15:38 +00:00
|
|
|
changelog = "https://github.com/grafana/agent/blob/${src.rev}/CHANGELOG.md";
|
|
|
|
maintainers = with lib.maintainers; [ flokli emilylange ];
|
2023-08-04 22:07:22 +00:00
|
|
|
mainProgram = "grafana-agent";
|
2021-02-05 17:12:51 +00:00
|
|
|
};
|
|
|
|
}
|