Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

build-helm-chart.nix

Nix tooling for Helm chart repositories: a buildHelmChart function, and a flake-parts module that packages, checks and releases any number of charts from one flake.

Status: Beta

Features

  • buildHelmChart: lints and packages a chart
  • Multiple charts per flake: each chart under helmCharts.charts.<name> gets its own package, checks and release scripts.
  • Checks: lint and package build, a helm install --dry-run=client render, an optional app-version comparison against nixpkgs, and more.
  • Release helpers: towncrier changelog builds, release commits and git tags per chart.
  • Dev shell and an optional treefmt setup.
  • Template to start a new chart repository in one command.

Quick start

mkdir my-charts && cd my-charts
nix flake init -t git+https://git.bartoostveen.nl/bart/build-helm-chart.nix
git init && git add .
nix flake lock
nix develop

Usage

See the template.

Outputs

For every chart <name>:

OutputDescription
packages.defaultThe chart named by helmCharts.defaultChart, or the only chart if there is exactly one
packages.<name>The packaged chart
packages.towncrier-build-<name>Builds the changelog with towncrier for the chart’s version
packages.get-changelog-<name>Prints the lines the last commit added to the changelog
packages.tag-release-<name>Runs the changelog build, commits and creates the git tag
checks.<name>The package build (including helm lint)
checks.<name>-renderhelm install --dry-run=client of the chart
checks.<name>-versionChecks the app version against the appPackages version (only if appPackage is set)
checks.<name>-<k>Each entry of extraChecks
devShells.helm-charts/devShells.defaultA devshell with handy utilities

Options

All options live under perSystem.helmCharts. See full documentation at https://build-helm-chart.bartoostveen.nl.

Releasing

  1. Add news fragments with towncrier create.
  2. Bump version in Chart.yaml.
  3. Run nix run .#tag-release-<name> (or tag-release-<name> in the devshell).

The script runs towncrier build for the chart’s version, executes git add ., commits as chore: Release <name> <version> and tags <tagPrefix><version>. Extra arguments are passed to git tag.

To release several charts independently, give each its own towncrier.toml, changelog.d/ and CHANGELOG.md, and also set:

charts.my-chart.release.directory = "my-chart";

Formatting

flakeModules.treefmt configures treefmt-nix with nixfmt, statix, deadnix, shellcheck, keep-sorted, prettier, yamlfmt and markdownlint. The programs are enabled with mkDefault, so you can switch any of them off. Run it with nix fmt.

Using buildHelmChart

overlays.default adds buildHelmChart to your package set, which is an extension of stdenv.mkDerivation:

{
  buildHelmChart,
  lib,
}:

buildHelmChart {
  pname = "git-pages-chart";
  version = "1.0.0";

  src = ./git-pages;

  meta = {
    description = "git-pages Helm chart";
    homepage = "https://git.bartoostveen.nl/bart/git-pages-chart.git";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ bartoostveen ];
  };
}

Hooks

HookPhaseDescriptionTurn off
helmCheckHookcheckPhaseRuns helm lint for each chartdontHelmCheck = true;
helmBuildHookbuildPhasehelm package into dist/dontHelmBuild = true;
helmInstallHookinstallPhaseInstalls the resulting chartdontHelmInstall = true;
buildHelmChart {
  # ...
  helmLintFlags = [ "--strict" ]; # default
  helmPackageFlags = [ "--dependency-update" ]; # needs network or vendored charts/
  postBuild = "ls dist";
}

License

This utility is provided under the MIT License.