27 "pkg/cmd/grafana-server"
31 src = fetchFromGitHub {
35 hash = "sha256-47jQ+ksq6zdS73o884q0xKLtOHssTnaIPdDOejlv/gU=";
38 # borrowed from: https://github.com/NixOS/nixpkgs/blob/d70d9425f49f9aba3c49e2c389fe6d42bac8c5b0/pkgs/development/tools/analysis/snyk/default.nix#L20-L22
41 CYPRESS_INSTALL_BINARY = 0;
43 // lib.optionalAttrs (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64) {
44 # Fix error: no member named 'aligned_alloc' in the global namespace.
45 # Occurs while building @esfx/equatable@npm:1.0.2 on x86_64-darwin
46 NIX_CFLAGS_COMPILE = "-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION=1";
49 offlineCache = stdenv.mkDerivation {
50 name = "${pname}-${version}-yarn-offline-cache";
59 # @esfx/equatable@npm:1.0.2 fails to build on darwin as it requires `xcbuild`
60 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild.xcbuild ];
63 export HOME="$(mktemp -d)"
64 yarn config set enableTelemetry 0
65 yarn config set cacheFolder $out
66 yarn config set --json supportedArchitectures.os '[ "linux", "darwin" ]'
67 yarn config set --json supportedArchitectures.cpu '["arm", "arm64", "ia32", "x64"]'
74 outputHashMode = "recursive";
77 x86_64-linux = "sha256-5/l0vXVjHC4oG7ahVscJOwS74be7F8jei9nq6m2v2tQ=";
78 aarch64-linux = x86_64-linux;
79 aarch64-darwin = "sha256-+texKSlcvtoi83ySEXy2E4SqnfyQ0l4MixTBpdemWvI=";
80 x86_64-darwin = aarch64-darwin;
82 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
85 disallowedRequisites = [ offlineCache ];
87 vendorHash = "sha256-3dRXvBmorItNa2HAFhEhMxKwD4LSKSgTUSjukOV2RSg=";
99 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild.xcbuild ];
102 # Generate DI code that's required to compile the package.
103 # From https://github.com/grafana/grafana/blob/v8.2.3/Makefile#L33-L35
104 wire gen -tags oss ./pkg/server
105 wire gen -tags oss ./pkg/cmd/grafana-cli/runner
107 GOARCH= CGO_ENABLED=0 go generate ./kinds/gen.go
108 GOARCH= CGO_ENABLED=0 go generate ./public/app/plugins/gen.go
110 export HOME="$(mktemp -d)"
112 # Help node-gyp find Node.js headers
113 # (see https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#pitfalls-javascript-yarn2nix-pitfalls)
114 mkdir -p $HOME/.node-gyp/${nodejs.version}
115 echo 9 > $HOME/.node-gyp/${nodejs.version}/installVersion
116 ln -sfv ${nodejs}/include $HOME/.node-gyp/${nodejs.version}
117 export npm_config_nodedir=${nodejs}
119 yarn config set enableTelemetry 0
120 yarn config set cacheFolder $offlineCache
121 yarn install --immutable-cache
123 # The build OOMs on memory constrained aarch64 without this
124 export NODE_OPTIONS=--max_old_space_size=4096
128 # After having built all the Go code, run the JS builders now.
130 # Workaround for https://github.com/nrwl/nx/issues/22445
131 faketty yarn run build
132 yarn run plugins:build-bundled
138 "-X main.version=${version}"
141 # Tests start http servers which need to bind to local addresses:
142 # panic: httptest: failed to listen on a port: listen tcp6 [::1]:0: bind: operation not permitted
143 __darwinAllowLocalNetworking = true;
145 # On Darwin, files under /usr/share/zoneinfo exist, but fail to open in sandbox:
146 # TestValueAsTimezone: date_formats_test.go:33: Invalid has err for input "Europe/Amsterdam": operation not permitted
148 export ZONEINFO=${tzdata}/share/zoneinfo
152 mkdir -p $out/share/grafana
153 cp -r public conf $out/share/grafana/
158 remove-references-to -t $offlineCache "$line"
159 done < <(find $out -type f -name '*.js.map' -or -name '*.js')
163 tests = { inherit (nixosTests) grafana; };
164 updateScript = nix-update-script { };
168 description = "Gorgeous metric viz, dashboards & editors for Graphite, InfluxDB & OpenTSDB";
169 license = licenses.agpl3Only;
170 homepage = "https://grafana.com";
171 maintainers = with maintainers; [
185 mainProgram = "grafana-server";