Bzlmod extensions

Module Extensions

helm

helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.host_tools(name, version)
helm.plugin(name, integrity, strip_prefix, url_templates, version, yaml)
helm.toolchain(name, plugins)

TAG CLASSES

host_tools

An extension for creating a host alias repository that provides a shorter name for the host platform's helm binary.

An example of defining and using host tools:

helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.host_tools(name = "helm")
use_repo(helm, "helm")

# Then you can use @helm//:helm in your BUILD files

Attributes

NameDescriptionTypeMandatoryDefault
nameThe name of the host alias repository.Nameoptional"helm"
versionThe version of helm to use for host tools.Stringoptional"4.2.0"

plugin

An extension tag for declaring Helm plugins.

Plugins are downloaded per-platform and made available to helm.toolchain() tags that reference them by name. Only platforms listed in integrity (and url_templates) will receive the plugin.

An example of declaring the helm-diff plugin and wiring it into a named toolchain:

helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.host_tools()
helm.plugin(
    name = "diff",
    version = "3.15.5",
    strip_prefix = "diff",
    url_templates = {
        "darwin-arm64": ["https://github.com/databus23/helm-diff/releases/download/v{version}/helm-diff-macos-arm64.tgz"],
        "linux-amd64": ["https://github.com/databus23/helm-diff/releases/download/v{version}/helm-diff-linux-amd64.tgz"],
    },
    integrity = {
        "darwin-arm64": "sha256-KJmZ7wY3gAcWFzK5R9+TfQlaRfEXzJ7hDNRC8NgIDog=",
        "linux-amd64": "sha256-ToJjCrKyMxfAOeezsWYF95qKwPPSKHPg1G6pzZgN2o4=",
    },
)
helm.toolchain(
    name = "with_diff",
    plugins = ["diff"],
)
use_repo(helm, "helm", "helm_toolchains", "with_diff_toolchains")
register_toolchains("@helm_toolchains//:all")

Attributes

NameDescriptionTypeMandatoryDefault
nameThe name of the plugin.Namerequired
integrityA mapping of helm platform name to integrity hash. Only platforms listed here will receive the plugin.Dictionary: String -> Stringrequired
strip_prefixA directory prefix to strip from the extracted plugin archive.Stringoptional""
url_templatesMapping of helm platform name to a list of URL templates for downloading the plugin on that platform. Only {version} is substituted; spell the platform name into the URL string directly. Every key in integrity must have a matching entry here.Dictionary: String -> List of stringsrequired
versionThe version of the plugin to download.Stringrequired
yamlRelative path to plugin.yaml within the extracted archive (after strip_prefix).Stringoptional"plugin.yaml"

toolchain

Define a named set of helm toolchains with specific plugins.

Creates an independent hub repository @{name}_toolchains containing toolchains for the default helm version with the specified plugins baked in. Only platforms where all referenced plugins are available will have toolchains generated.

The hub is not registered automatically — call register_toolchains explicitly, or use a Starlark transition to override toolchain resolution.

helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
helm.plugin(name = "diff", ...)
helm.toolchain(
    name = "with_diff",
    plugins = ["diff"],
)
use_repo(helm, "with_diff_toolchains")
register_toolchains("@with_diff_toolchains//:all")

Attributes

NameDescriptionTypeMandatoryDefault
nameName prefix for the hub repository. Produces @{name}_toolchains.Namerequired
pluginsPlugin names (from helm.plugin() tags) to include in these toolchains.List of stringsoptional[]

helm_charts

helm_charts = use_extension("@rules_helm//helm:extensions.bzl", "helm_charts")
helm_charts.chart(name, sha256, url)

Module extension for fetching Helm charts from OCI registries.

Charts live in their own extension, so an unreachable registry does not stop the helm extension from resolving toolchains. All tags are resolved in one evaluation, so a lookup that fails (an unknown version or an unreachable registry) fails every repository from this extension. Set sha256 to skip the lookup. A command that loads a target from one of these repositories, such as bazel query, needs every lookup that has no stored fact. Tags from every module are used, so repository names must be unique across modules.

TAG CLASSES

chart

Fetch a Helm chart from an OCI registry with helm_import_repository.

The repository holds a helm_import target named after the name in the Chart.yaml of the chart, which is normally the last path segment of url without the version. Refer to it as @<name>//:<chart>. The shorthand @<name> is an alias of it, but only when the name in use_repo is the same as the tag name, because Bazel reads @x as @x//:x. Neither name nor the chart can be called license or package_metadata.

If sha256 is unset, the extension reads the digest of the chart package from the registry manifest, and trusts the registry for it on first use. On Bazel 8.5 and newer the digest is stored as a fact in MODULE.bazel.lock, keyed by url, so later evaluations make no registry request for it. Older Bazel versions record the digest in the lockfile as part of the repository. Without a lockfile, the digest is looked up whenever the extension is evaluated, and a version tag that the registry moves gives a different chart. Set sha256 to pin the digest in MODULE.bazel.

Each lookup is a token request and a manifest download, and the lookups run one after another. While a lookup is needed, an unreachable registry fails the evaluation, and so fails every target that depends on a repository from this extension. This applies whenever no stored fact exists: with the lockfile off, on the first evaluation, or after you delete the fact. A tag with sha256 makes no lookup while the extension evaluates. Fetching the chart can still contact the registry, unless the chart is in the repository cache.

A stored digest is not checked against the registry. If the registry replaces the chart behind a version tag, the fetch fails with a checksum mismatch. Delete the entry for url from the facts section of MODULE.bazel.lock to look the digest up again.

helm_charts = use_extension("@rules_helm//helm:extensions.bzl", "helm_charts")
helm_charts.chart(
    name = "karpenter",
    url = "oci://public.ecr.aws/karpenter/karpenter:1.9.0",
)
use_repo(helm_charts, "karpenter")

# Then you can use @karpenter//:karpenter as a dependency in your BUILD files

Attributes

NameDescriptionTypeMandatoryDefault
nameThe name of the repository.Namerequired
sha256The expected SHA-256 hash of the chart package. If unset, the extension looks it up in the registry.Stringoptional""
urlThe chart url, in the form oci://<host>/<path>:<version>.Stringrequired