1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
{ lib
, stdenv
, fetchFromGitHub
, fetchYarnDeps
, buildGoModule
, systemd
, yarn
, fixup-yarn-lock
, nodejs
, grafana-alloy
, nixosTests
, nix-update-script
, installShellFiles
, testers
}:
buildGoModule rec {
pname = "grafana-alloy";
version = "1.2.0";
src = fetchFromGitHub {
rev = "v${version}";
owner = "grafana";
repo = "alloy";
hash = "sha256-0AR7JE79QHA6nO6Wu3ebousH2pyeDiP4+9DnUL/OSYI=";
};
proxyVendor = true;
vendorHash = "sha256-Pnf/oiwldRIjvVa85igwQ/AoT/iups7LQ46T2iGAIlM=";
nativeBuildInputs = [ fixup-yarn-lock yarn nodejs installShellFiles ];
ldflags =
let
prefix = "github.com/grafana/alloy/internal/build";
in
[
"-s"
"-w"
# https://github.com/grafana/alloy/blob/3201389252d2c011bee15ace0c9f4cdbcb978f9f/Makefile#L110
"-X ${prefix}.Branch=v${version}"
"-X ${prefix}.Version=${version}"
"-X ${prefix}.Revision=v${version}"
"-X ${prefix}.BuildUser=nix"
"-X ${prefix}.BuildDate=1970-01-01T00:00:00Z"
];
tags = [
"netgo"
"builtinassets"
"promtail_journal_enabled"
];
subPackages = [
"."
];
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/internal/web/ui/yarn.lock";
hash = "sha256-8/siWMFoUokMXJ13QT8050AXynsApiC67TP/7Hvugsk=";
};
preBuild = ''
pushd internal/web/ui
# Yarn wants a real home directory to write cache, config, etc to
export HOME=$NIX_BUILD_TOP/fake_home
fixup-yarn-lock yarn.lock
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
yarn install --offline --frozen-lockfile --ignore-platform --ignore-scripts --no-progress --non-interactive
patchShebangs node_modules/
yarn --offline build
popd
'';
# uses go-systemd, which uses libsystemd headers
# https://github.com/coreos/go-systemd/issues/351
NIX_CFLAGS_COMPILE = lib.optionals stdenv.isLinux [ "-I${lib.getDev systemd}/include" ];
checkFlags = [
"-tags nonetwork" # disable network tests
"-tags nodocker" # disable docker tests
];
# go-systemd uses libsystemd under the hood, which does dlopen(libsystemd) at
# runtime.
# Add to RUNPATH so it can be found.
postFixup = lib.optionalString stdenv.isLinux ''
patchelf \
--set-rpath "${lib.makeLibraryPath [ (lib.getLib systemd) ]}:$(patchelf --print-rpath $out/bin/alloy)" \
$out/bin/alloy
'';
postInstall = ''
installShellCompletion --cmd alloy \
--bash <($out/bin/alloy completion bash) \
--fish <($out/bin/alloy completion fish) \
--zsh <($out/bin/alloy completion zsh)
'';
passthru = {
tests = {
inherit (nixosTests) alloy;
version = testers.testVersion {
version = "v${version}";
package = grafana-alloy;
};
};
updateScript = nix-update-script { };
# alias for nix-update to be able to find and update this attribute
offlineCache = yarnOfflineCache;
};
meta = with lib; {
description = "Open source OpenTelemetry Collector distribution with built-in Prometheus pipelines and support for metrics, logs, traces, and profiles";
mainProgram = "alloy";
license = licenses.asl20;
homepage = "https://grafana.com/oss/alloy";
changelog = "https://github.com/grafana/alloy/blob/${src.rev}/CHANGELOG.md";
maintainers = with maintainers; [ azahi flokli emilylange hbjydev ];
platforms = lib.platforms.unix;
};
}
|