From 5a2bd826f84d26f257ce8aae4ec8709ce817c0f4 Mon Sep 17 00:00:00 2001 From: r-vdp Date: Mon, 28 Apr 2025 12:06:48 +0200 Subject: [PATCH] prometheus: use finalAttrs to make the version and webui overridable This makes it possible to override the version and have the right webui assets. It also makes sure that the right version is used in other places of the derivation. Overriding now can be done like this: ```nix final: prev: prometheus = prev.prometheus.overrideAttrs ( finalAttrs: prevAttrs: { version = "3.1.0"; src = final.fetchFromGitHub { owner = "prometheus"; repo = "prometheus"; tag = "v${finalAttrs.version}"; hash = ""; }; vendorHash = ""; webUiStatic = final.fetchurl { url = "https://github.com/prometheus/prometheus/releases/download/v${finalAttrs.version}/prometheus-web-ui-${finalAttrs.version}.tar.gz"; hash = ""; }; } ); ``` Whereas before you'd have to copy over things like the postPatch hook. --- pkgs/by-name/pr/prometheus/package.nix | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pkgs/by-name/pr/prometheus/package.nix b/pkgs/by-name/pr/prometheus/package.nix index 0908777635bb..f7985edd5f61 100644 --- a/pkgs/by-name/pr/prometheus/package.nix +++ b/pkgs/by-name/pr/prometheus/package.nix @@ -31,16 +31,9 @@ enableZookeeper ? true, }: -let - version = "3.1.0"; - webUiStatic = fetchurl { - url = "https://github.com/prometheus/prometheus/releases/download/v${version}/prometheus-web-ui-${version}.tar.gz"; - hash = "sha256-05DaaDIFtADnkLFqdHe5eUvo6LRz6BduMvGVmzOeurM="; - }; -in -buildGoModule rec { +buildGoModule (finalAttrs: { pname = "prometheus"; - inherit version; + version = "3.1.0"; outputs = [ "out" @@ -51,19 +44,24 @@ buildGoModule rec { src = fetchFromGitHub { owner = "prometheus"; repo = "prometheus"; - tag = "v${version}"; + tag = "v${finalAttrs.version}"; hash = "sha256-Q3f0L6cRVQRL1AHgUI3VNbMG9eTfcApbXfSjOTHr7Go="; }; vendorHash = "sha256-vQwBnSxoyIYTeWLk3GD9pKDuUjjsMfwPptgyVnzcTok="; + webUiStatic = fetchurl { + url = "https://github.com/prometheus/prometheus/releases/download/v${finalAttrs.version}/prometheus-web-ui-${finalAttrs.version}.tar.gz"; + hash = "sha256-05DaaDIFtADnkLFqdHe5eUvo6LRz6BduMvGVmzOeurM="; + }; + excludedPackages = [ "documentation/prometheus-mixin" "web/ui/mantine-ui/src/promql/tools" ]; postPatch = '' - tar -C web/ui -xzf ${webUiStatic} + tar -C web/ui -xzf ${finalAttrs.webUiStatic} patchShebangs scripts @@ -109,7 +107,7 @@ buildGoModule rec { [ "-s" "-w" - "-X ${t}.Version=${version}" + "-X ${t}.Version=${finalAttrs.version}" "-X ${t}.Revision=unknown" "-X ${t}.Branch=unknown" "-X ${t}.BuildUser=nix@nixpkgs" @@ -142,4 +140,4 @@ buildGoModule rec { Frostman ]; }; -} +})