1 { lib, stdenv, buildGoModule, fetchFromGitHub, removeReferencesTo
3 , yarn, nodejs, python3, cacert
5 , nix-update-script, nixosTests, xcbuild
9 # We need dev dependencies to run webpack, but patch away
10 # `cypress` (and @grafana/e2e which has a direct dependency on cypress).
11 # This attempts to download random blobs from the Internet in
12 # postInstall. Also, it's just a testing framework, so not worth the hassle.
13 patchAwayGrafanaE2E = ''
14 find . -name package.json | while IFS=$'\n' read -r pkg_json; do
15 <"$pkg_json" jq '. + {
16 "devDependencies": .devDependencies | del(."@grafana/e2e") | del(.cypress)
17 }' | sponge "$pkg_json"
19 rm -r packages/grafana-e2e
26 subPackages = [ "pkg/cmd/grafana" "pkg/cmd/grafana-server" "pkg/cmd/grafana-cli" ];
28 src = fetchFromGitHub {
32 hash = "sha256-ahG9ABJJUUgrFqqNjkJRA1Gia8T4J90jIsCMFOhZ55w=";
35 # borrowed from: https://github.com/NixOS/nixpkgs/blob/d70d9425f49f9aba3c49e2c389fe6d42bac8c5b0/pkgs/development/tools/analysis/snyk/default.nix#L20-L22
36 env = lib.optionalAttrs (stdenv.isDarwin && stdenv.isx86_64) {
37 # Fix error: no member named 'aligned_alloc' in the global namespace.
38 # Occurs while building @esfx/equatable@npm:1.0.2 on x86_64-darwin
39 NIX_CFLAGS_COMPILE = "-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION=1";
42 offlineCache = stdenv.mkDerivation {
43 name = "${pname}-${version}-yarn-offline-cache";
48 # @esfx/equatable@npm:1.0.2 fails to build on darwin as it requires `xcbuild`
49 ] ++ lib.optionals stdenv.isDarwin [ xcbuild.xcbuild ];
51 ${patchAwayGrafanaE2E}
55 export HOME="$(mktemp -d)"
56 yarn config set enableTelemetry 0
57 yarn config set cacheFolder $out
58 yarn config set --json supportedArchitectures.os '[ "linux", "darwin" ]'
59 yarn config set --json supportedArchitectures.cpu '["arm", "arm64", "ia32", "x64"]'
66 outputHashMode = "recursive";
68 x86_64-linux = "sha256-3CZgs732c6Z64t2sfWjPAmMFKVTzoolv2TwrbjeRCBA=";
69 aarch64-linux = x86_64-linux;
70 aarch64-darwin = "sha256-NKEajOe9uDZw0MF5leiKBIRH1CHUELRho7gyCa96BO8=";
71 x86_64-darwin = aarch64-darwin;
72 }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
75 disallowedRequisites = [ offlineCache ];
77 vendorHash = "sha256-XmIF/ZWVO1qjSmRPTFnHgxvnliXXicGgsV8gQcKJl9U=";
81 nativeBuildInputs = [ wire yarn jq moreutils removeReferencesTo python3 ] ++ lib.optionals stdenv.isDarwin [ xcbuild.xcbuild ];
84 ${patchAwayGrafanaE2E}
88 # Generate DI code that's required to compile the package.
89 # From https://github.com/grafana/grafana/blob/v8.2.3/Makefile#L33-L35
90 wire gen -tags oss ./pkg/server
91 wire gen -tags oss ./pkg/cmd/grafana-cli/runner
93 GOARCH= CGO_ENABLED=0 go generate ./pkg/plugins/plugindef
94 GOARCH= CGO_ENABLED=0 go generate ./kinds/gen.go
95 GOARCH= CGO_ENABLED=0 go generate ./public/app/plugins/gen.go
97 export HOME="$(mktemp -d)"
99 # Help node-gyp find Node.js headers
100 # (see https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#pitfalls-javascript-yarn2nix-pitfalls)
101 mkdir -p $HOME/.node-gyp/${nodejs.version}
102 echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
103 ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
104 export npm_config_nodedir=${nodejs}
106 yarn config set enableTelemetry 0
107 yarn config set cacheFolder $offlineCache
108 yarn --immutable-cache
110 # The build OOMs on memory constrained aarch64 without this
111 export NODE_OPTIONS=--max_old_space_size=4096
115 # After having built all the Go code, run the JS builders now.
117 yarn run plugins:build-bundled
121 "-s" "-w" "-X main.version=${version}"
124 # Tests start http servers which need to bind to local addresses:
125 # panic: httptest: failed to listen on a port: listen tcp6 [::1]:0: bind: operation not permitted
126 __darwinAllowLocalNetworking = true;
128 # On Darwin, files under /usr/share/zoneinfo exist, but fail to open in sandbox:
129 # TestValueAsTimezone: date_formats_test.go:33: Invalid has err for input "Europe/Amsterdam": operation not permitted
131 export ZONEINFO=${tzdata}/share/zoneinfo
135 mkdir -p $out/share/grafana
136 cp -r public conf $out/share/grafana/
141 remove-references-to -t $offlineCache "$line"
142 done < <(find $out -type f -name '*.js.map' -or -name '*.js')
146 tests = { inherit (nixosTests) grafana; };
147 updateScript = nix-update-script { };
151 description = "Gorgeous metric viz, dashboards & editors for Graphite, InfluxDB & OpenTSDB";
152 license = licenses.agpl3Only;
153 homepage = "https://grafana.com";
154 maintainers = with maintainers; [ offline fpletz willibutz globin ma27 Frostman ];
155 platforms = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
156 mainProgram = "grafana-server";