diff --git a/pkgs/by-name/pr/prometheus/disable-react-app.diff b/pkgs/by-name/pr/prometheus/disable-react-app.diff new file mode 100644 index 000000000000..f98eca28554a --- /dev/null +++ b/pkgs/by-name/pr/prometheus/disable-react-app.diff @@ -0,0 +1,10 @@ +--- ./build_ui.sh 2025-10-22 23:32:08.739188520 +0100 ++++ ./build_ui.sh 2025-10-22 23:32:23.753242986 +0100 +@@ -50,7 +50,6 @@ for i in "$@"; do + case ${i} in + --all) + buildModule +- buildReactApp + buildMantineUI + shift + ;; diff --git a/pkgs/by-name/pr/prometheus/package.nix b/pkgs/by-name/pr/prometheus/package.nix index 7b75b0b7bff7..88050c435489 100644 --- a/pkgs/by-name/pr/prometheus/package.nix +++ b/pkgs/by-name/pr/prometheus/package.nix @@ -4,8 +4,8 @@ lib, go, buildGoModule, + buildNpmPackage, fetchFromGitHub, - fetchurl, nixosTests, enableAWS ? true, enableAzure ? true, @@ -32,31 +32,62 @@ enableZookeeper ? true, }: -buildGoModule (finalAttrs: { +let pname = "prometheus"; version = "3.8.0"; + src = fetchFromGitHub { + owner = "prometheus"; + repo = "prometheus"; + tag = "v${version}"; + hash = "sha256-bitRDX1oymFfzvQVYL31BON6UBfQYnqjZefQKc+yXx0="; + }; + + assets = buildNpmPackage { + pname = "${pname}-assets"; + inherit version; + + src = "${src}/web/ui"; + + npmDepsHash = "sha256-Uq7vikiYLqhRQNCpB49aMJgAE/uK4Mst/Iz6W+hdxBw="; + + patches = [ + # Disable old React app as it depends on deprecated create-react-apps + # script + ./disable-react-app.diff + ]; + + env.CI = true; + + doCheck = true; + checkPhase = '' + runHook preCheck + + npm test + + runHook postCheck + ''; + + postInstall = '' + mkdir -p $out/static + cp -r $out/lib/node_modules/prometheus-io/static/* $out/static + find $out/static -type f -exec gzip -f9 {} \; + + # Remove node_modules + rm -rf $out/lib + ''; + }; +in +buildGoModule (finalAttrs: { + inherit pname version src; + outputs = [ "out" "doc" "cli" ]; - src = fetchFromGitHub { - owner = "prometheus"; - repo = "prometheus"; - tag = "v${finalAttrs.version}"; - hash = "sha256-hRuZxwPPDLxQvy5MPKEyfmanNabcSjLRO+XbNKugPtk="; - }; - - depsBuildBuild = [ buildPackages.stdenv.cc ]; - - vendorHash = "sha256-5wDaG01vcTtGzrS/S33U5XWXoSWM+N9z3dzXZlILxD8="; - - webUiStatic = fetchurl { - url = "https://github.com/prometheus/prometheus/releases/download/v${finalAttrs.version}/prometheus-web-ui-${finalAttrs.version}.tar.gz"; - hash = "sha256-oOEvNZFlYtTNBsn+B2pAWXi0A2oJ6IAo7V8bOLtjfCM="; - }; + vendorHash = "sha256-V+qLxjqGOaT1veEwtklqcS7iO31ufvDHBA9DbZLzDiE="; excludedPackages = [ "documentation/prometheus-mixin" @@ -65,7 +96,7 @@ buildGoModule (finalAttrs: { ]; postPatch = '' - tar -C web/ui -xzf ${finalAttrs.webUiStatic} + cp -r ${assets}/static web/ui/static/ patchShebangs scripts @@ -99,9 +130,18 @@ buildGoModule (finalAttrs: { ''; preBuild = '' - if [[ -d vendor ]]; then - GOARCH= CC="$CC_FOR_BUILD" LD="$LD_FOR_BUILD" make -o assets assets-compress plugins - fi + if [[ -d vendor ]]; then GOARCH= make -o assets plugins; fi + + # Recreate the `make assets-compress` target here - workaround permissions + # errors + cp web/ui/embed.go.tmpl web/ui/embed.go + + find web/ui/static -type f -name '*.gz' -print0 | sort -z | xargs -0 echo //go:embed >> web/ui/embed.go + + echo 'var EmbedFS embed.FS' >> web/ui/embed.go + + # EmbedFS requires relative paths + substituteInPlace web/ui/embed.go --replace-fail "web/ui/" "" ''; tags = [ "builtinassets" ];