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=clientrender, 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>:
| Output | Description |
|---|---|
packages.default | The 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>-render | helm install --dry-run=client of the chart |
checks.<name>-version | Checks the app version against the appPackages version (only if appPackage is set) |
checks.<name>-<k> | Each entry of extraChecks |
devShells.helm-charts/devShells.default | A devshell with handy utilities |
Options
All options live under perSystem.helmCharts.
See full documentation at https://build-helm-chart.bartoostveen.nl.
Releasing
- Add news fragments with
towncrier create. - Bump
versioninChart.yaml. - Run
nix run .#tag-release-<name>(ortag-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
| Hook | Phase | Description | Turn off |
|---|---|---|---|
helmCheckHook | checkPhase | Runs helm lint for each chart | dontHelmCheck = true; |
helmBuildHook | buildPhase | helm package into dist/ | dontHelmBuild = true; |
helmInstallHook | installPhase | Installs the resulting chart | dontHelmInstall = 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.