Skip to content
Install the CLI

Reference Package authoring

Helm and imports

These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.

Not everything in your cluster starts as a native Kix package: you might want to deploy a complex third-party operator published as a Helm chart, or connect your workloads to a managed database or cloud ingress controller that already exists outside Kix. This page covers the two bridges for bringing external software into Kix’s dependency graph: Helm chart wrappers (kix.helmChart and scope.helm.importChart) and external service markers (kix.mkImport).

Helm chart wrappers are a fallback bridge for third-party software that does not have a native Kix package yet. Compared to native Kix packages, Helm charts use untyped values maps (unless wrapped with custom options), rely on YAML heuristics rather than .out references for dependency and network-policy discovery, ignore cluster.availability scaling by default, and often require overrides to satisfy scorecard rules. See Trade-offs of wrapping a Helm chart for when to use each tier.

Kix provides two entry points for Helm charts:

  1. kix.helmChart: A turn-key package constructor for quick chart adoption that exposes a values option (options.values) and wraps the rendered resources automatically.
  2. scope.helm.importChart: The full chart-adoption builder used inside custom packages that expose typed options, translate them into Helm values, and patch or extend the rendered resources.
pkgs/reloader/default.nix
{ kix, ... }:
kix.helmChart {
repo = "https://stakater.github.io/stakater-charts";
name = "reloader";
version = "1.0.115";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
metaExtra = {
description = "Kubernetes controller that watches ConfigMaps and Secrets and triggers rollouts";
};
}
kix.helmChart argumentTypeDefaultDescription
repostringRequiredHelm repository URL (https://... or oci://...).
namestringRequiredUpstream chart name.
versionstringRequiredChart version string (also used as default meta.version).
hashstringRequiredFixed-output Nix SRI hash ("sha256-...") of the fetched chart tarball.
releaseNamestringnameHelm release name passed to helm template.
helmVersion"3" or "4""4"Major version of the Helm in the Kix runtime used to render the chart ("4" is 4.3.1, "3" is 3.19.1; see Helm versions).
root{ kind, name } or nullnullExplicit root resource selector; when null, Kix selects the primary Service or workload automatically (chart.autoRoot).
includeCrdsbooltrueWhether to pass --include-crds to helm template.
strip{ helmAnnotations ? true; helmLabels ? true; defaultStrategy ? true; }{ }Controls normalization of Helm metadata annotations (helmAnnotations), app.kubernetes.io/managed-by and helm.sh/chart labels (helmLabels), and default RollingUpdate strategy blocks (defaultStrategy).
patchResourceslist -> listlib.idFunction transforming the list of parsed chart resource attribute sets before Kix reconstructs the DAG and wraps them.
metaExtraattrset{ }Additional fields merged into the package’s meta block.

Full adoption with scope.helm.fetchHelmChart and scope.helm.importChart

Section titled “Full adoption with scope.helm.fetchHelmChart and scope.helm.importChart”

In a typed package, fetch the chart tarball with scope.helm.fetchHelmChart and render it into Kix resources with scope.helm.importChart:

{
scope,
lib,
kix,
...
}:
let
chart = scope.helm.fetchHelmChart {
repo = "https://charts.jetstack.io";
name = "cert-manager";
version = "1.14.4";
hash = "sha256-BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=";
};
in
{
meta = {
version = "1.14.4";
description = "X.509 certificate controller for Kubernetes";
};
options = {
replicas = lib.mkOption {
type = lib.types.ints.positive;
default = 1;
description = "Controller replica count.";
};
values = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = { };
description = "Extra Helm values merged over typed options.";
};
};
build =
{ self, config }:
let
rendered = scope.helm.importChart {
inherit chart scope;
releaseName = "cert-manager";
values = lib.recursiveUpdate {
replicaCount = config.replicas;
installCRDs = true;
} config.values;
patchResources = builtins.filter (r: r.kind != "Pod");
};
in
rendered.mkParts {
root = rendered.get "Deployment" "cert-manager";
};
}
ArgumentTypeDefaultDescription
chartderivationRequiredChart tarball derivation returned by scope.helm.fetchHelmChart { repo, name, version, hash }.
scopeattrsetRequiredPackage scope (automatically configured with labelStyle = "helm" for wrapped resources).
valuesattrset{ }Nix attribute set serialized to values.yaml and passed to helm template --values.
releaseNamestring"release"Release name passed to helm template.
namespacestringscope.namespaceNameNamespace passed to helm template --namespace.
helmVersion"3" or "4""4"Major version of the Helm in the Kix runtime used to render the chart ("4" is 4.3.1, "3" is 3.19.1; see Helm versions).
includeCrdsbooltruePasses --include-crds and wraps rendered CRDs with scope.mkCRD.
includeHooksbooltrueWhen false, passes --no-hooks to helm template. Chart test hooks (helm.sh/hook containing "test") are always dropped when wrapping resources.
extraFlagslist of strings[ ]Extra CLI arguments appended to helm template, one argument per list element (for example, [ "--api-versions" "monitoring.coreos.com/v1" ]). Do not pass --values, --namespace, --include-crds, or --no-hooks here: Kix passes those flags itself and does not filter extraFlags. Set --kube-version with kubeVersion instead.
kubeVersionstring or nullnullKubernetes version passed to helm template --kube-version to set .Capabilities.KubeVersion. When null, Helm uses its built-in default (see Helm versions).
strip{ helmAnnotations ? true; helmLabels ? true; defaultStrategy ? true; }{ }Normalization booleans controlling whether Kix strips meta.helm.sh/*, helm.sh/*, and checksum/* annotations (helmAnnotations), app.kubernetes.io/managed-by and helm.sh/chart labels (helmLabels), and default RollingUpdate strategy blocks (defaultStrategy). To filter or modify rendered resources, use patchResources.
preserveAnnotationPrefixeslist of strings[ ]Keeps matching annotation prefixes (such as "argocd.argoproj.io/") when strip.helmAnnotations is enabled.
patchResourceslist -> listlib.idTransforms the list of parsed chart resource attribute sets (after List expansion and test-hook filtering) before DAG reconstruction and scope.mk* wrapping.
extraEdgeslist of { from = { kind; name; }; to = { kind; name; }; }[ ]Additional intra-chart dependency edges (from depends on to) merged with Kix’s automatic DAG reconstruction (for example, [ { from = { kind = "Deployment"; name = "my-app"; }; to = { kind = "Job"; name = "my-migration"; }; } ]).
networkDepslist of strings[ ]Additional context-carrying strings (such as nested dep.out.byKind outputs) attached to chart workloads for network-policy edge discovery.
depslist of dependency views[ ]Upstream Kix dependency views whose top-level context-carrying out.* strings are attached to chart workloads for network-policy edge discovery.

Raw Helm YAML files have no deployment ordering between objects. When scope.helm.importChart wraps a chart, Kix inspects every rendered manifest and reconstructs the intra-chart dependency graph automatically:

  • Workloads depend on the ServiceAccount named in spec.template.spec.serviceAccountName, any ConfigMap, Secret, or PersistentVolumeClaim mounted in volumes or referenced in env / envFrom, and any CRD whose custom resources are present.
  • RoleBinding and ClusterRoleBinding resources depend on their target Role / ClusterRole and ServiceAccount subjects.
  • Service resources depend on the workload whose pod template labels match spec.selector.
  • Ingress, HTTPRoute, ServiceMonitor, and webhook configurations depend on their target Service.

Use extraEdges when a chart has a runtime dependency that is not visible in standard Kubernetes reference fields (for example, an application Deployment that expects a chart Job to initialize an external schema).

WiringNetwork policyDeploy ordering
Reference in values onlyNone. Kix serializes values to JSON before helm template, stripping dependency metadata. Chart workloads receive only DNS egress.None.
deps = [ dep ] (dep must also be an argument of build)Attaches top-level strings in dep.out (out.name, out.fqdn, and out.url) to every chart workload. When network policy is enabled, Kix generates egress from each chart workload to dep’s Service pods on the target port, plus matching ingress on dep.When network policy is enabled, chart workloads wait for cluster DNS and their generated policies, which apply after dep’s Service. When network policy is disabled, chart workloads wait only for cluster DNS. Chart workloads never wait for dep’s Deployment or StatefulSet.
networkDeps = [ ... ] (dep must also be an argument of build)Attaches nested output strings (such as dep.out.byKind.<Kind>.<name>) to every chart workload so Kix generates the same egress and ingress policies.Same as deps: orders chart workloads after cluster DNS (and after the target Service when network policy is enabled), never after dep’s workloads.

kix.helmChart does not accept deps or networkDeps. To connect a chart to another package, wrap it in a package that calls scope.helm.importChart:

build =
{ backend, ... }:
let
rendered = scope.helm.importChart {
inherit chart scope;
releaseName = "web";
values = {
backendHost = backend.out.fqdn;
networkPolicy.enabled = false;
};
# Lets Kix derive egress from the chart's workloads to backend.
deps = [ backend ];
};
in
rendered.mkParts { root = rendered.get "Service" "web"; };

If a chart renders its own NetworkPolicy templates, Kix applies them alongside its generated CiliumNetworkPolicy objects, and Cilium enforces both. Disable the chart’s built-in policies in either of two ways:

  • Chart values: Turn them off through the chart’s own option when available, such as values.networkPolicy.enabled = false (check the chart’s values.yaml for the exact key).
  • patchResources: Filter them out after rendering with patchResources = builtins.filter (r: r.kind != "NetworkPolicy"); on scope.helm.importChart or kix.helmChart.

scope.helm.importChart returns a collection attribute set with the following selectors and helpers:

Attribute or methodSignatureDescription
alllist of resourcesAll wrapped Kix resources in the chart.
attrsattrset of resourcesMap of <partKey> = resource (for example, "deployment-cert-manager").
crdsattrset of CRD handlesMap of <Kind> = { cr; mkCR; } CRD builder handles for all CRDs rendered by the chart.
getkind -> name -> resourceLooks up a single resource by kind and metadata.name. Throws an evaluation error listing available resources if not found.
findkind -> name -> resource or nullSame as get, but returns null if the resource is not present.
byKindkind -> list of resourcesReturns the list of wrapped resources of the given kind.
workloadslist of resourcesAll Deployment, StatefulSet, DaemonSet, Job, and CronJob resources in the chart.
excluding[ resources ] -> listReturns all minus the listed resources.
depsOfresource -> listReturns the reconstructed intra-chart dependencies of resource.
edgeslist of { from; to; type; }List of reconstructed intra-chart dependency edge records, where from and to are wrapped Kix resources and type names the rule that inferred the edge.
autoRootresourceAutomatically selects the chart’s sole Service, or (when there are no Services) its sole Deployment, StatefulSet, or DaemonSet. Throws an evaluation error if there are multiple Services, no Services and multiple workloads, or neither Services nor workloads.
replaceResourcekind -> name -> newResource -> collectionReplaces a wrapped chart resource with a custom Kix resource and re-evaluates all downstream chart resources so they depend on newResource.
mkParts{ root, extraParts ? { }, extraRequires ? [ ], out ? { } } -> partsProduces the build return set (attrs // extraParts // { root = { resource = root; requires = ...; out = ...; }; }), wiring all other chart resources into root.requires and populating root.out.byKind.<Kind>.<name> (plus root.out.crds when the chart renders CRDs). root is required. When root is a workload (Deployment, StatefulSet, DaemonSet, Job, or CronJob) selected by exactly one Service in the chart, that Service’s name, fqdn, selector, ports, and url are also promoted onto root.out.

Extracting CRDs only with scope.helm.importChartCrds

Section titled “Extracting CRDs only with scope.helm.importChartCrds”

When you write a native Kix package for an operator but want to load its CRD definitions from the upstream Helm chart tarball, use scope.helm.importChartCrds:

crdList = scope.helm.importChartCrds {
inherit chart scope;
};

scope.helm.importChartCrds accepts { chart, scope, releaseName ? "release", values ? { }, helmVersion ? "4" } and returns a list of wrapped CustomResourceDefinition resources. Pass helmVersion = "3"; to render the chart’s CRDs with Helm 3.

kix.helmChart, scope.helm.importChart, and scope.helm.importChartCrds render charts with Helm 4 (4.3.1) by default. If an upstream chart relies on template behavior that changed in Helm 4, set helmVersion = "3"; to render that chart with Helm 3 (3.19.1). Upstream Helm 3 receives security fixes until 10 February 2027. Passing any other major version fails evaluation and lists the shipped versions.

The exact Helm release for each major version is pinned in kix/lib/helm-versions.json and shipped with Kix. A new version of Kix can change a Helm version in the Kix runtime (for example, a Helm security or patch update). Because helm template output feeds into resource identity hashes (kix.run/identity-hash), the Kix library and Kix must name the same Helm version. Each cluster pinned to a version of Kix builds with the matching version of the Kix library, and Kix stops when they differ (see When the Kix library does not match Kix). kix upgrade updates the Kix library tag in flake.nix and flake.lock when upgrading to a new version of Kix.

Kix renders charts offline by running helm template with an isolated empty home directory, never contacting a cluster:

helm template <releaseName> <chart> --values values.json --namespace <namespace> [--include-crds] [--no-hooks] [--kube-version <v>] [<extraFlags>...]

Kix passes --include-crds when includeCrds = true (the default), --no-hooks when includeHooks = false, --kube-version <v> when kubeVersion is set on scope.helm.importChart, and then any extraFlags.

Chart featureBehavior in KixHow to configure
HooksKix renders hooks by default (includeHooks = true), drops test hooks (helm.sh/hook containing test), and strips helm.sh/* annotations (strip.helmAnnotations = true). Remaining hook objects are applied as ordinary resources: Kix ignores hook phases (pre-install, post-upgrade, and so on), weights, and delete policies, and chart workloads do not wait for hook Jobs automatically. Kix also strips ttlSecondsAfterFinished from Jobs and skips unchanged resources on later deploys, so finished hook Jobs stay on the cluster and do not rerun.On scope.helm.importChart, pass extraEdges = [ { from = { kind = "Deployment"; name = "my-app"; }; to = { kind = "Job"; name = "my-app-migrate"; }; } ]; to make a workload wait for a migration Job, or set includeHooks = false to omit hooks. On kix.helmChart (which lacks includeHooks and extraEdges), filter hooks out with patchResources or use scope.helm.importChart.
lookupAlways returns an empty map ({}) in both Helm 3.19.1 and 4.3.1. Templates that branch on lookup (for example, to reuse an existing generated password) take the empty branch on every build.Not configurable; Kix cannot query cluster resources from lookup today.
.Release.IsInstall / .Release.IsUpgrade.Release.IsInstall is always true, and .Release.IsUpgrade is always false.Not configurable.
.Capabilities.KubeVersionUses Helm’s compiled-in default (v1.37.0 in Helm 4.3.1, v1.34.0 in Helm 3.19.1) unless overridden, and does not track the cluster’s Kubernetes version. scope.helm.importChartCrds always passes --kube-version 1.32.0.Set kubeVersion on scope.helm.importChart (kix.helmChart has no kubeVersion argument).
.Capabilities.APIVersionsContains only built-in Kubernetes API groups (such as apps/v1). Custom resource groups (such as monitoring.coreos.com/v1) are absent, so .Capabilities.APIVersions.Has checks for CRDs evaluate to false.Pass extraFlags = [ "--api-versions" "monitoring.coreos.com/v1" ]; on scope.helm.importChart. When the CRD belongs to another Kix package, build the custom resource in Kix instead (for example, with kix.monitor), because a chart-rendered custom resource lacks a dependency link to the other package’s CRD and fails validation check 21.
CRDs in crds/Helm never templates files in crds/. By default (includeCrds = true), Kix passes --include-crds and manages those CRDs like any other resource: creating them on first deploy and updating them via server-side apply when they change (unlike upstream helm install, which skips existing CRDs and never upgrades or deletes them). Kix never deletes CRDs automatically during prune or kix gc. Templated CRDs under templates/ are always included.Set includeCrds = false to omit files in crds/.
  • Chart compatibility: Kix renders charts with Helm 4 (4.3.1) by default. According to the upstream Helm overview, charts deployable with Helm 3 should be deployable with Helm 4, and apiVersion: v2 charts in Chart.yaml continue to work.
  • Default KubeVersion: Helm 4.3.1 defaults .Capabilities.KubeVersion to v1.37.0 (up from v1.34.0 in Helm 3.19.1). If a chart sets a kubeVersion constraint in Chart.yaml or branches on .Capabilities.KubeVersion, set kubeVersion on scope.helm.importChart to match your cluster’s Kubernetes version.
  • Install-time Helm 4 changes: Helm 4 moved post-renderers into plugins and made server-side apply the default for new installs (Helm overview). Neither change affects Kix, which runs helm template without post-renderers and applies manifests itself.
  • Pinning Helm 3: If a chart renders differently under Helm 4, set helmVersion = "3"; to render it with Helm 3.19.1.

How project builders fetch and render charts

Section titled “How project builders fetch and render charts”

How fetchHelmChart and importChart run depends on the project’s builder in kix.toml:

  • builder = "kix" (default): Kix runs the helm programs in the Kix runtime (3.19.1 or 4.3.1) to pull each chart tarball, verify its SRI hash, run helm template, and store the rendered manifests in Kix’s local store (~/.cache/kix/store).
  • builder = "nix": The machine’s Nix fetches the chart and runs the same Helm release (kix/lib/helm-versions.json) with the same helm template flags during evaluation (allow-import-from-derivation must be true, the Nix default). A chart renders the same way under either builder.

Clusters frequently rely on services or platform components that live outside the Kix cluster configuration, such as a cloud-managed PostgreSQL instance (RDS or Cloud SQL), an external OIDC provider, or a CNI / storage driver pre-installed by a managed Kubernetes control plane (EKS, GKE, or k3s).

kix.mkImport creates an import definition that can be bound in instances.<namespace>.<name>.package (or inside a cluster flavor). Imports participate in dependency resolution, role binding, and contract checking without emitting workload manifests. At build time, Kix emits a kix.run/v1alpha1 PackageInstance marker with metadata.annotations."kix.run/mode" = "import" (and spec.mode = "import") so kix deploy can verify any expected in-cluster resources before deploying consumers.

# Importing an external RDS PostgreSQL database in cluster configuration
{ ref, packages, kix, ... }:
{
instances.app.rds-login = {
package = packages.secret;
config.source = ./secrets/rds-login.sops.yaml;
config.keys = [ "username" "password" ];
};
instances.app.database.package = kix.mkImport {
scope = "namespace";
out = {
host = "app.abc123.eu-west-1.rds.amazonaws.com";
port = "5432";
database = "app";
tls = true;
credentials = ref.app.rds-login;
};
};
}
ArgumentTypeDefaultDescription
frompackage or nullnullOptional Kix package evaluated against a synthetic import scope to derive its default out surface and root resource kind and apiVersion hints. Does not inherit meta.roles or crds from from.meta (unless from’s root.out exposes out.crds).
outattrset{ }Output fields exposed to downstream consumers (host, fqdn, port, credentials, storageClassName, etc.). May contain ref.<namespace>.<instance> at any depth of plain attribute sets (see Referencing instances in out and namespace scope). When both from and out are set, out overrides matching keys on the package-derived out.
kindstring or nullDerived from from’s root resource, or nullOptional Kubernetes kind of an existing in-cluster resource ("Service", "Deployment", "StorageClass", etc.). When present, Kix stamps kix.run/import-kind (and kix.run/import-name when out.name is set) on the PackageInstance import marker so kix deploy checks that the resource exists in the cluster.
apiVersionstring or nullDerived from from’s root resource, or nullAPI version stamped as kix.run/import-apiversion on the import marker when kind is present. Not inferred from kind when from is null.
namespacestring or nullnullNamespace of the existing in-cluster resource. Defaults to the import instance’s namespace when null. Set this when the cluster blocks writes to the resource’s namespace (such as kube-system on GKE Autopilot) so the import instance can live in another namespace. When namespace differs from the instance’s namespace, Kix stamps kix.run/import-namespace on the PackageInstance import marker so build validation and kix deploy look for the resource there.
roleslist of strings[ ]Platform roles satisfied by this import ("cni", "dns", "loadBalancer", "metricsApi", "storageClasses", etc.). Not inherited from from.meta.roles.
crdslist of { group, kind, plural, version, servedVersions?, crdScope?, factBehavior?, readiness?, usesAtLeast?, holdsData? }[ ]Pre-installed CRDs provided by this import (version is required on each entry). Wrapped as CRD reference handles, emitted as CRD ref markers while the import is active, and exposed to consumers at dep.out.crds.<Kind>.
annotationDomainslist of strings[ ]Annotation domains read by controllers outside Kix (for example, "eks.amazonaws.com"). The architecture.annotationDomainOwnership rule allows annotations under these domains on any instance without requiring a dependency on this import. If a managed package also declares the domain in meta.annotationDomains, the managed package takes precedence and consumers must depend on it. Declaring the same domain on two imports fails evaluation.
dnsPeerslist or nullnullDNS endpoints allowed on UDP and TCP port 53 by generated network policies when this import claims the "dns" role. Each entry is { namespace?; podSelector; } (namespace defaults to the import’s namespace) or { cidr; } (rejected by the cilium enforcer). When null, policies allow pods labeled k8s-app: kube-dns in kube-system. See DNS peers.
scope"cluster" | "namespace""cluster"Which namespaces resolve a dependency to this import by name. The default offers it to every namespace, unlike a managed package with meta.scope unset; "namespace" keeps it to its own namespace, even against ref. When several imports answer one name, name the one you mean with deps.<arg> = ref.<namespace>.<instance>.

Referencing instances in out and namespace scope

Section titled “Referencing instances in out and namespace scope”

In a cluster definition, out may contain ref.<namespace>.<instance> at any depth of plain attribute sets. Write { ref, ... }: in the cluster module header so ref is in scope. Kix replaces each ref with that instance (so expressions such as dep.out.credentials.out.keyRef "password" work in the consumer without consumer changes) and adds the referenced instance to the import marker’s dependencies, so kix deploy applies the secret before the import.

A ref in out does not activate an optional instance. A ref to an inactive instance, or to the import itself, fails the build.

A pod reads Secrets only from its own namespace, and Kix refuses a Secret from another namespace at build time. Because of this, an import that carries a login in out.credentials (such as an external RDS or Cloud SQL database matching kix.contracts.postgresDatabase, an authenticated smtp server, or an external oidc provider) sits in the consumer’s namespace beside its secret, with scope = "namespace". An import without a login can keep the default scope = "cluster" and serve every namespace. When several namespaces connect to the same external service with their own secrets, a Nix let binding can share the common settings across the per-namespace imports.

  1. Direct out import (out = { ... }): Provide the exact .out contract expected by consumers (such as host, port, database, and credentials for an external database, or storageClassName = "gp3" with roles = [ "storageClasses" ]).
  2. Package-derived import (from = packages.experimental.coredns; roles = [ "dns" ];): Evaluates the referenced Kix package in an import scope to extract its default .out surface and root kind/apiVersion while discarding its deployment manifests. Pass roles or crds explicitly when the import should also claim platform roles or expose CRD ref markers. In this import scope, scope provides instanceName, namespaceName, namespace, selectorLabels, labelStyle, fail, rbac, the resource and workload builders (mkResource, mkClusterResource, mkCR, mkDeployment, mkStatefulSet, mkDaemonSet, mkJob, mkCronJob), mkServiceRef, and mkSecretRef. If the package reads any other scope attribute (such as scope.mkSecret, scope.mkCRD, scope.mkCRDRef, or scope.helm), Kix stops the build with an error. For those packages, omit from and set out (and crds, if needed) directly.
  3. Hybrid import (from = packages.experimental.coredns; roles = [ "dns" ]; out = { ... };): Starts from from’s default .out surface and overrides specific output fields in out.

When a cluster flavor defines a pre-installed capability using kix.mkImport:

  • An import instance with optional = true (such as platform-dns on cloud flavors) activates only when at least one active instance in the cluster depends on it through a required build argument (by name, alias, or role) or an explicit deps.<arg> = ref.<namespace>.<instance>. Providing a core platform role does not by itself activate an optional = true import; imports that must always be active (such as platform-storage) set optional = false.
  • If the cluster operator explicitly instantiates a managed Kix package that provides the same role (for example, deploying a managed cilium or coredns instance), the managed instance automatically shadows and deactivates the flavor’s "shadowable" import instance so the two never conflict.