kubenix/lib/helm/fetchhelm.nix

51 lines
1.2 KiB
Nix
Raw Normal View History

{ stdenvNoCC, lib, kubernetes-helm, cacert }:
let
2021-05-13 17:27:08 -04:00
cleanName = name: lib.replaceStrings [ "/" ] [ "-" ] name;
2021-05-13 17:27:08 -04:00
in
{
# name of the chart
chart
# chart url to fetch from custom location
, chartUrl ? null
# version of the chart
, version ? null
2021-05-13 17:27:08 -04:00
# chart hash
, sha256
2021-05-13 17:27:08 -04:00
# whether to extract chart
, untar ? true
2021-05-13 17:27:08 -04:00
# use custom charts repo
, repo ? null
2021-05-13 17:27:08 -04:00
# pass --verify to helm chart
, verify ? false
2021-05-13 17:27:08 -04:00
# pass --devel to helm chart
, devel ? false
}: stdenvNoCC.mkDerivation {
name = "${cleanName chart}-${if version == null then "dev" else version}";
buildCommand = ''
export HOME="$PWD"
2020-01-14 19:09:39 +00:00
echo "adding helm repo"
${if repo == null then "" else "helm repo add repository ${repo}"}
2020-01-14 19:09:39 +00:00
echo "fetching helm chart"
helm fetch -d ./chart \
${if untar then "--untar" else ""} \
${if version == null then "" else "--version ${version}"} \
${if devel then "--devel" else ""} \
${if verify then "--verify" else ""} \
${if chartUrl == null then (if repo == null then chart else "repository/${chart}") else chartUrl}
cp -r chart/*/ $out
'';
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = sha256;
nativeBuildInputs = [ kubernetes-helm cacert ];
}