diff --git a/pkgs/servers/monitoring/grafana/plugins/default.nix b/pkgs/servers/monitoring/grafana/plugins/default.nix new file mode 100644 index 000000000000..95be470831c1 --- /dev/null +++ b/pkgs/servers/monitoring/grafana/plugins/default.nix @@ -0,0 +1,7 @@ +{ newScope, pkgs }: + +let + callPackage = newScope (pkgs // plugins); + plugins = import ./plugins.nix { inherit callPackage; }; +in + plugins diff --git a/pkgs/servers/monitoring/grafana/plugins/grafana-plugin.nix b/pkgs/servers/monitoring/grafana/plugins/grafana-plugin.nix new file mode 100644 index 000000000000..3b3cee88fd7a --- /dev/null +++ b/pkgs/servers/monitoring/grafana/plugins/grafana-plugin.nix @@ -0,0 +1,28 @@ +{ stdenvNoCC, fetchurl, unzip }: + +{ pname, version, zipHash, meta ? {}, passthru ? {}, ... }@args: +stdenvNoCC.mkDerivation ({ + inherit pname version; + + src = fetchurl { + name = "${pname}-${version}.zip"; + url = "https://grafana.com/api/plugins/${pname}/versions/${version}/download"; + hash = zipHash; + }; + + nativeBuildInputs = [ unzip ]; + + installPhase = '' + cp -R "." "$out" + chmod -R a-w "$out" + chmod u+w "$out" + ''; + + passthru = { + updateScript = [ ./update-grafana-plugin.sh pname ]; + } // passthru; + + meta = { + homepage = "https://grafana.com/grafana/plugins/${pname}"; + } // meta; +} // (builtins.removeAttrs args [ "pname" "version" "sha256" "meta" ])) diff --git a/pkgs/servers/monitoring/grafana/plugins/plugins.nix b/pkgs/servers/monitoring/grafana/plugins/plugins.nix new file mode 100644 index 000000000000..9b45ab9c58fd --- /dev/null +++ b/pkgs/servers/monitoring/grafana/plugins/plugins.nix @@ -0,0 +1,6 @@ +{ callPackage }: +{ + inherit callPackage; + + grafanaPlugin = callPackage ./grafana-plugin.nix { }; +} diff --git a/pkgs/servers/monitoring/grafana/plugins/update-grafana-plugin.sh b/pkgs/servers/monitoring/grafana/plugins/update-grafana-plugin.sh new file mode 100755 index 000000000000..dd8f050c633c --- /dev/null +++ b/pkgs/servers/monitoring/grafana/plugins/update-grafana-plugin.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl jq common-updater-scripts + +set -eu -o pipefail + +readonly plugin_name="$1" +readonly latest_version="$(curl "https://grafana.com/api/plugins/${plugin_name}" | jq -r .version)" +update-source-version "grafanaPlugins.${plugin_name}" "$latest_version" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 27c565bce0c7..a0aa129526a8 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17164,6 +17164,7 @@ in gofish = callPackage ../servers/gopher/gofish { }; grafana = callPackage ../servers/monitoring/grafana { }; + grafanaPlugins = dontRecurseIntoAttrs (callPackage ../servers/monitoring/grafana/plugins { }); grafana-loki = callPackage ../servers/monitoring/loki { };