Unverified Commit 5a2bd826 authored by r-vdp's avatar r-vdp
Browse files

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.
parent bafb63cd
Loading
Loading
Loading
Loading
+11 −13
Original line number Diff line number Diff line
@@ -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
    ];
  };
}
})