Skip to content

Commit 2e35200

Browse files
committed
refactor(generators): reuse buildHelmChart in mkChartCRDsYaml
Drop the hand-rolled helm-template derivation in favor of klib.buildHelmChart, per review. Materialize its single-file output as $out/crds.yaml via runCommand cp rather than linkFarm: crdObjects reads crds.yaml at eval time, and a linkFarm symlink would make that read follow into buildHelmChart's separate output (a store path absent from the readFile string's context) which pure eval forbids. A real file keeps the read in-context.
1 parent e7dc0f7 commit 2e35200

1 file changed

Lines changed: 20 additions & 24 deletions

File tree

pkgs/generators/default.nix

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -404,31 +404,27 @@ let
404404
}:
405405
let
406406
_chart = if chart != null then chart else klib.downloadHelmChart chartAttrs;
407+
408+
templated = klib.buildHelmChart {
409+
inherit
410+
name
411+
values
412+
extraOpts
413+
kubeVersion
414+
;
415+
chart = _chart;
416+
includeCRDs = true;
417+
};
407418
in
408-
pkgs.stdenv.mkDerivation {
409-
name = "chart-crds-${name}";
410-
411-
passAsFile = [ "helmValues" ];
412-
helmValues = builtins.toJSON values;
413-
414-
allowSubstitutes = false;
415-
preferLocalBuild = true;
416-
417-
phases = [ "installPhase" ];
418-
installPhase = ''
419-
export HELM_CACHE_HOME="$TMP/.nix-helm-build-cache"
420-
mkdir -p $out
421-
422-
${pkgs.kubernetes-helm}/bin/helm template \
423-
--include-crds \
424-
--kube-version "${kubeVersion}" \
425-
--values "$helmValuesPath" \
426-
"${name}" \
427-
"${_chart}" \
428-
${builtins.concatStringsSep " " extraOpts} \
429-
> $out/crds.yaml
430-
'';
431-
};
419+
# `buildHelmChart` emits a single YAML *file*; copy (not symlink) it into a
420+
# directory `$out/crds.yaml`. `crdObjects` reads this at eval time via
421+
# `readFile "${src}/crds.yaml"`, and a `linkFarm` symlink would make that
422+
# read follow into a separate derivation output not carried in the string's
423+
# context — forbidden in pure eval. A real file keeps the read in-context.
424+
pkgs.runCommand "chart-crds-${name}" { } ''
425+
mkdir -p $out
426+
cp ${templated} $out/crds.yaml
427+
'';
432428

433429
# Chart counterpart to `fromCRDModule`: template a chart's CRDs and return a
434430
# module value (resource type options). `crds`, when non-empty, narrows the

0 commit comments

Comments
 (0)