nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 174 lines 4.7 kB view raw
1{ 2 lib, 3 stdenv, 4 buildGoModule, 5 fetchFromGitHub, 6 removeReferencesTo, 7 tzdata, 8 wire, 9 yarn-berry_4, 10 python3, 11 jq, 12 moreutils, 13 nix-update-script, 14 nixosTests, 15 xcbuild, 16 faketty, 17}: 18 19let 20 # Grafana seems to just set it to the latest version available 21 # nowadays. 22 # NOTE: I(Ma27) leave this in, even if it's technically dead code because 23 # it doesn't make sense to pull this out of the history on every other release. 24 # 25 # Please make sure to always set a Go version to `.0`: it may happen that 26 # stable is on an older patch-release of Go and then the build would fail 27 # after a backport. 28 patchGoVersion = '' 29 find . -name go.mod -not -path "./.bingo/*" -print0 | while IFS= read -r -d ''' line; do 30 substituteInPlace "$line" \ 31 --replace-fail "go 1.24.4" "go 1.24.0" 32 done 33 find . -name go.work -print0 | while IFS= read -r -d ''' line; do 34 substituteInPlace "$line" \ 35 --replace-fail "go 1.24.4" "go 1.24.0" 36 done 37 substituteInPlace Makefile \ 38 --replace-fail "GO_VERSION = 1.24.4" "GO_VERSION = 1.24.0" 39 ''; 40in 41buildGoModule rec { 42 pname = "grafana"; 43 version = "12.0.2+security-01"; 44 45 subPackages = [ 46 "pkg/cmd/grafana" 47 "pkg/cmd/grafana-server" 48 "pkg/cmd/grafana-cli" 49 ]; 50 51 src = fetchFromGitHub { 52 owner = "grafana"; 53 repo = "grafana"; 54 rev = "v${version}"; 55 hash = "sha256-aMbxBDLikmUBZwfZQPLcCCk8BpMeQ7Pj1li4p28aZ88="; 56 }; 57 58 # borrowed from: https://github.com/NixOS/nixpkgs/blob/d70d9425f49f9aba3c49e2c389fe6d42bac8c5b0/pkgs/development/tools/analysis/snyk/default.nix#L20-L22 59 env = { 60 CYPRESS_INSTALL_BINARY = 0; 61 62 # The build OOMs on memory constrained aarch64 without this 63 NODE_OPTIONS = "--max_old_space_size=4096"; 64 }; 65 66 missingHashes = ./missing-hashes.json; 67 offlineCache = yarn-berry_4.fetchYarnBerryDeps { 68 inherit src missingHashes; 69 hash = "sha256-vQdiQyxebtVrO76Pl4oC3DM37owhtQgZqYWaiIyKysQ="; 70 }; 71 72 disallowedRequisites = [ offlineCache ]; 73 74 postPatch = patchGoVersion; 75 76 vendorHash = "sha256-cJxvZPJmf5YY+IWE7rdoGUkXxDeE6b0troGsdpsQzeU="; 77 78 proxyVendor = true; 79 80 nativeBuildInputs = [ 81 wire 82 jq 83 moreutils 84 removeReferencesTo 85 # required to run old node-gyp 86 (python3.withPackages (ps: [ ps.distutils ])) 87 faketty 88 yarn-berry_4 89 yarn-berry_4.yarnBerryConfigHook 90 ] 91 ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild.xcbuild ]; 92 93 # We have to remove this setupHook, otherwise it also runs in the `goModules` 94 # derivation and fails because `offlineCache` is missing there. 95 overrideModAttrs = ( 96 old: { 97 nativeBuildInputs = lib.filter ( 98 x: lib.getName x != (lib.getName yarn-berry_4.yarnBerryConfigHook) 99 ) old.nativeBuildInputs; 100 } 101 ); 102 103 postConfigure = '' 104 # Generate DI code that's required to compile the package. 105 # From https://github.com/grafana/grafana/blob/v8.2.3/Makefile#L33-L35 106 wire gen -tags oss ./pkg/server 107 wire gen -tags oss ./pkg/cmd/grafana-cli/runner 108 109 GOARCH= CGO_ENABLED=0 go generate ./kinds/gen.go 110 GOARCH= CGO_ENABLED=0 go generate ./public/app/plugins/gen.go 111 112 ''; 113 114 postBuild = '' 115 # After having built all the Go code, run the JS builders now. 116 117 # Workaround for https://github.com/nrwl/nx/issues/22445 118 faketty yarn run build 119 yarn run plugins:build-bundled 120 ''; 121 122 ldflags = [ 123 "-s" 124 "-w" 125 "-X main.version=${version}" 126 ]; 127 128 # Tests start http servers which need to bind to local addresses: 129 # panic: httptest: failed to listen on a port: listen tcp6 [::1]:0: bind: operation not permitted 130 __darwinAllowLocalNetworking = true; 131 132 # On Darwin, files under /usr/share/zoneinfo exist, but fail to open in sandbox: 133 # TestValueAsTimezone: date_formats_test.go:33: Invalid has err for input "Europe/Amsterdam": operation not permitted 134 preCheck = '' 135 export ZONEINFO=${tzdata}/share/zoneinfo 136 ''; 137 138 postInstall = '' 139 mkdir -p $out/share/grafana 140 cp -r public conf $out/share/grafana/ 141 ''; 142 143 postFixup = '' 144 while read line; do 145 remove-references-to -t $offlineCache "$line" 146 done < <(find $out -type f -name '*.js.map' -or -name '*.js') 147 ''; 148 149 passthru = { 150 tests = { inherit (nixosTests) grafana; }; 151 updateScript = nix-update-script { }; 152 }; 153 154 meta = with lib; { 155 description = "Gorgeous metric viz, dashboards & editors for Graphite, InfluxDB & OpenTSDB"; 156 license = licenses.agpl3Only; 157 homepage = "https://grafana.com"; 158 maintainers = with maintainers; [ 159 offline 160 fpletz 161 globin 162 ma27 163 Frostman 164 ryan4yin 165 ]; 166 platforms = [ 167 "x86_64-linux" 168 "x86_64-darwin" 169 "aarch64-linux" 170 "aarch64-darwin" 171 ]; 172 mainProgram = "grafana-server"; 173 }; 174}