nixpkgs/pkgs/servers/monitoring/grafana/plugins/grafana-plugin.nix
Adam Joseph c7e0f6b905 treewide: s_targetPlatform_hostPlatform_ in non-compiler packages
stdenv.targetPlatform really shouldn't be used by software that
doesn't generate or manipulate binaries.  I reviewed all uses of
targetPlatform outside of pkgs/development/compilers and pkgs/stdenv
and replaced those which weren't involved in something which fits
these criteria.
2023-11-17 08:07:34 +00:00

42 lines
1.2 KiB
Nix

{ stdenvNoCC, fetchurl, unzip, lib }:
{ pname, version, zipHash, meta ? {}, passthru ? {}, ... }@args:
let plat = stdenvNoCC.hostPlatform.system; in stdenvNoCC.mkDerivation ({
inherit pname version;
src = if lib.isAttrs zipHash then
fetchurl {
name = "${pname}-${version}-${plat}.zip";
hash = zipHash.${plat} or (throw "unsupported system");
url = "https://grafana.com/api/plugins/${pname}/versions/${version}/download" + {
x86_64-linux = "?os=linux&arch=amd64";
aarch64-linux = "?os=linux&arch=arm64";
x86_64-darwin = "?os=darwin&arch=amd64";
aarch64-darwin = "?os=darwin&arch=arm64";
}.${plat} or (throw "unknown system");
}
else
fetchurl {
name = "${pname}-${version}.zip";
hash = zipHash;
url = "https://grafana.com/api/plugins/${pname}/versions/${version}/download";
}
;
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 [ "zipHash" "pname" "version" "sha256" "meta" ]))