Skip to content
Install the CLI

Reference Clusters and instances

Instances and composition

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

Once you have a cluster module, you populate it by declaring package instances under instances.<namespace>.<name>. Reach for this page when you are adding an application or database to a cluster, passing configuration values to a package, wiring a service to a dependency in another namespace, or sharing common configuration across staging and production environments.

Each entry under instances.<namespace>.<name> places a managed package instance or an external resource marker (kix.mkImport) into <namespace> with the instance name <name>.

{ packages, ref, ... }:
{
instances.apps.web = {
package = packages.web;
config = {
replicas = 3;
ingress.host = "web.example.com";
};
deps.database = ref.data.postgres;
};
}
FieldTypeDefaultMerge behavior across modulesPurpose
packageraw function or attrsetrequiredsingle definition (conflict on duplicate)Package function, evaluated package attribute set, or kix.mkImport marker.
configdeferredModule{ }NixOS module merge (lib.mkDefault, lib.mkForce)Values evaluated against the package’s options.
depsattrsOf anything{ }collision on same key is an errorExplicit dependency bindings (ref.<ns>.<inst>, list of refs, or direct values) keyed by build argument name.
aliasesnullOr (listOf str)nulllist mergeDependency-resolution names for this instance. A list replaces meta.defaultAliases.
optionalboolfalseboolean mergeKeeps the instance dormant unless an active instance transitively depends on it.
availabilitynull | "none" | "pod" | "node" | "zone"nullsingle definitionOverrides cluster.availability.default for this instance.
partsOverlayslistOf raw[ ]lists concatenate in module orderPost-build functions (scope: self: base: attrset) that modify, add, or remove rendered parts.
labelStyle"kix" | "helm""kix"single definitionSelector and metadata label convention: "kix" (app.kubernetes.io/*) or "helm" (app and release).
selectorLabelsnullOr (attrsOf str)nullattribute set mergeExplicit spec.selector.matchLabels override for adopting workloads with immutable live selectors.
extraDepslistOf raw[ ]lists concatenateAdditional deployment-ordering dependencies (ref.<ns>.<inst> or resource values) on a kix.mkImport instance’s marker.
platformIntentsattrsOf anything{ }attribute set mergeNetwork connectivity intents for a kix.mkImport instance’s pre-installed pods.
versionnullOr strnullsingle definitionStates the version the instance runs. Overrides the package’s out.version and meta.version.

package, labelStyle, selectorLabels, extraDeps, platformIntents, and version

Section titled “package, labelStyle, selectorLabels, extraDeps, platformIntents, and version”
  • package: Required for every instance. Takes a package function ({ scope, lib, kix, ... }: { ... }), an inline package attribute set ({ meta?; options?; build = ...; }), or a kix.mkImport marker. Built-in packages from packages (such as packages.harbor or packages.experimental.coredns) work like package functions and also carry a package ID (.id), which Kix writes to spec.package on the instance’s PackageInstance resource. Do not redefine package when writing an override module for an instance declared in another module; set only config, deps, aliases, or partsOverlays.
  • labelStyle and selectorLabels: Kubernetes forbids changing spec.selector.matchLabels on an existing Deployment or StatefulSet. When adopting a live workload that was installed with Helm (app and release labels), set labelStyle = "helm". When the live workload uses custom selector keys, set selectorLabels to the exact label map from the cluster.
  • extraDeps and platformIntents: Valid only on kix.mkImport instances. Setting extraDeps on a managed instance fails evaluation. Each entry in extraDeps is a Kix resource or ref.<namespace>.<instance>; when the import is active, ref entries must point to active instances (an extraDeps reference does not activate a dormant optional instance). platformIntents uses the same schema as networkPolicy.platformIntents and attaches the generated policies as dependencies of the import marker.
  • version: States the version the instance runs. Kix writes it onto the PackageInstance resource and checks it in the meta.compatibleWith constraints of the packages that depend on the instance. Without it, Kix uses the out.version the package builds, which most packages read from the image tag, and then the package’s meta.version. Set it when the instance runs an image whose tag names no version, such as latest or a tag of your own build. See The version an instance reports.

A package is stable or experimental. A stable package breaks only in a minor release. An experimental package may break in any release, including a patch release, and the break may be one that shows no error. CHANGELOG.md lists these breaks under the heading “Breaking in experimental packages and contracts”.

The name you write in package shows the level:

instances.apps.cache.package = packages.valkey;
instances.apps.cache-2.package = packages.stable.valkey;
instances.apps.photos.package = packages.experimental.immich;
  • packages.<name>: A stable package. packages.stable.<name> is the same package.
  • packages.experimental.<name>: An experimental package. Writing packages.<name> for an experimental package fails with [K0549] and gives packages.experimental.<name>. kix list packages shows it as experimental.<name>.
  • Reserved names: No package can be named stable or experimental.
  • A package that becomes stable: packages.experimental.<name> then fails with the error “packages.experimental.<name> is stable now. Write packages.<name>.”
  • A removed package: packages.experimental.<name> and packages.<name> fail with an error that gives the change record’s id and what to do instead.
  • A shared name: An experimental package may have the same name as a stable package. It is then a rework of that package, and replaces it in a minor release.
  • Contracts: A stable package reads only stable dependency contracts. An experimental package may read both stable and experimental contracts.
  • Modules: All cluster modules are experimental (kix/modules/experimental/): kix.modules.experimental.monitoring, kix.modules.experimental.irsa-webhook, and kix.modules.experimental.azure-workload-identity-webhook. kix.modules.monitoring fails with [K0549].
  • Automatic instances: availablePackages = packages offers only the stable packages. Name each experimental package that Kix may add.

These packages are stable: cnpg-cluster, cnpg-operator, echo-server, grafana, harbor, kube-state-metrics, node-exporter, persistent-volume-claim, priority-class, secret, secret-ref, storage-classes, valkey, victoria-metrics-agent, victoria-metrics-alert, victoria-metrics-cluster, and victoria-metrics-operator. Every other package is experimental. A package becomes stable once it has run in production long enough to settle.

instances.<namespace>.<name>.config sets values for the options declared in the package’s options block.

instances.apps.web = {
package = packages.web;
config = {
replicas = 3;
ingress.host = "web.example.com";
};
};

Because config has type deferredModule, multiple cluster modules can contribute configuration to the same instance. Kix evaluates four layers together using lib.evalModules:

Priority (lower number wins)SourceNotes
50 (lib.mkForce)Any module using lib.mkForceOverrides normal definitions and defaults.
100 (normal definition)Instance config and dependency config injections (deps.<arg>.config)Conflicting plain definitions fail evaluation with file attribution.
1000 (lib.mkDefault)Instance config or dependency injection using lib.mkDefaultWins over package-level defaults.
1250 (packageDefaultPriority)lib.mkDefault inside the package’s own config blockReplaces option defaults (1500) while yielding to any instance or injected value.
1500 (option default)default in the package’s options declarationsBase fallback value.

An instance config block can also be written as a module function taking { config, clusterConfig, lib, ... }:

instances.apps.web.config = { config, clusterConfig, lib, ... }: {
ingress.host = lib.mkDefault "web.${clusterConfig.cluster.domain}";
};

Locking fields against dependency injection (kix.mkLocked)

Section titled “Locking fields against dependency injection (kix.mkLocked)”

A package can inject configuration into one of its dependencies via deps.<arg>.config (for example, a database consumer injecting required PostgreSQL extensions into the database cluster). To prevent any consumer from injecting into a top-level option on an instance, wrap the value in kix.mkLocked:

instances.data.postgres.config.extensions = kix.mkLocked [ "pg_stat_statements" ];

If a consumer attempts to inject extensions into data/postgres, evaluation fails and names the consumer that tried to inject the locked field.

instances.<namespace>.<name>.deps overrides automatic dependency resolution for specific build arguments of the package.

Every key in deps must match a dependency declared by the instance’s package, even on inactive optional = true instances. If the package renamed that dependency (deps.<arg>.renamedFrom), evaluation fails with the rename’s change ID and gives the new name. Any other unknown key fails with [K3646]. Because a kix.mkImport instance takes no dependencies, setting any deps key on an import also fails with [K3646]; use extraDeps to order an import after another instance.

{ packages, ref, ... }:
{
instances.apps.web = {
package = packages.web;
deps = {
database = ref.data.postgres-primary;
cache = ref.apps.valkey;
};
};
}

Every cluster module receives ref in its module arguments. Writing ref.<namespace>.<instance> points a dependency argument directly at that instance:

  • Single instance: deps.database = ref.data.postgres; resolves database to the package view of instances.data.postgres.
  • List of instances: deps.registryLogins = [ ref.apps.operator-logins ref.apps.extra-logins ]; resolves the argument to a list of instance handles in the given order. Mixing ref pointers with non-ref values in the same list fails evaluation.
  • Full dependency checks: A ref-wired dependency receives the same validation and wiring as an auto-resolved dependency: meta.scope = "namespace" boundaries are enforced, meta.compatibleWith version constraints are checked, deps.<arg>.config injections are forwarded to the target instance, and pointing ref at an optional = true instance activates it.
  • Namespace rule: Kix fills a package argument from the consumer’s own namespace. It uses an instance in another namespace only when the cluster definition names it with ref, or when the provider’s package serves the whole cluster (by setting meta.scope = "cluster", claiming a role in meta.roles, or declaring a cluster: entry in meta.conflictsWith). Stand-ins created with kix.mkImport also serve the whole cluster unless they set scope = "namespace"; when several imports match one name, select one with ref. An instance that Kix creates from availablePackages or enables via optional = true to satisfy a dependency also binds from any namespace, because the cluster definition chose where it lives. When the only match for a required argument is in another namespace and does not serve the whole cluster, evaluation fails and the error prints the deps line to add. When several instances in other namespaces answer the name, the error lists a deps line for each. An optional argument (x ? null) in that situation takes its default, and Kix prints a warning that names the instance and the deps line to add.
  • Any value that is not a ref (or a list of refs) is passed as-is to the build argument without package view wrapping, compatibility checks, or config injection. The package’s assertions also receive it in deps.
  • Setting deps.<arg> = null; behaves the same as leaving deps.<arg> unset: Kix falls back to automatic resolution or the build argument’s default value.
  • Explicitly wiring deps.<arg> suppresses availablePackages auto-instantiation for that argument.
  • An instance cannot depend on itself. Automatic resolution skips the instance when its own name, aliases, or roles match <arg>, and referencing the instance itself with ref in deps.<arg> fails evaluation. Because managed instances take priority over imports, a managed instance that matches <arg> does not automatically fall back to a kix.mkImport of that name; point deps.<arg> to the import with ref to use it.

Packages that call AWS, Google Cloud, or Azure APIs can accept a cloud identity instead of a Secret instance on the same dependency. external-dns accepts AWS, Google Cloud, and Azure identities on deps.providerCredentials. velero accepts one in deps.cloudCredentials (see Deploy Velero). tempo accepts an AWS IAM role (kix.cloudIdentity.aws) on deps.storageCredentials for an external S3 bucket. cnpg-cluster accepts an AWS IAM role on deps.storageCredentials for S3 backups. tempo and cnpg-cluster configure only S3 storage, so they do not support Google Cloud or Azure identities yet. For example:

Every package that accepts a cloud identity has been tested on a live Amazon EKS cluster with both IAM roles for service accounts (IRSA) and EKS Pod Identity. On Google Cloud, live-cluster tests cover every supported package on GKE Standard (both with a Google service account and with IAM roles granted directly to the Kubernetes ServiceAccount) and external-dns on GKE Autopilot. These tests ran on 25 and 26 November 2026. Each test verified that the package can call the cloud API, that the cloud API rejects an identity without permissions, and that changing the identity restarts pods (except when an operator creates the pods; see below). Azure cloud identities (Microsoft Entra Workload ID on AKS) have not been tested on a live cluster yet. Only unit tests and checks on the rendered Kubernetes manifests cover them so far.

instances.external-dns.route53 = {
package = packages.experimental.external-dns;
deps.providerCredentials = kix.cloudIdentity.aws {
roleArn = "arn:aws:iam::111122223333:role/external-dns";
};
# Or pass a Secret instance on the same dependency:
# deps.providerCredentials = ref.external-dns.aws-keys;
};

On AWS, workload identity injects AWS_REGION into the pod automatically, whereas static access keys in a Secret do not. Packages that use the AWS SDK with a Secret may therefore require an explicit region: for example, external-dns with provider = "aws" or "aws-sd" fails evaluation unless AWS_REGION or AWS_DEFAULT_REGION is set in config.env or provided by the Secret.

ConstructorFieldsWhat Kix writes on the ServiceAccount and pods
kix.cloudIdentity.awsroleArn (IAM role ARN)<annotationPrefix>/role-arn (eks.amazonaws.com/role-arn by default) on the ServiceAccount. With cluster.flavor.eks.cloudIdentity = "pod-identity", Kix omits this annotation because EKS Pod Identity links the ServiceAccount to an IAM role through an AWS association that you create outside Kix. Set that AWS association to the same roleArn; Kix records roleArn in kix.run/cloud-identity (shown by kix list resources), but pods receive whichever role the AWS association specifies.
kix.cloudIdentity.gcpoptional serviceAccount (Google service account email)iam.gke.io/gcp-service-account on the ServiceAccount when serviceAccount is set. kix.cloudIdentity.gcp { } omits the Google annotation when IAM roles are granted directly to the Kubernetes ServiceAccount.
kix.cloudIdentity.azureclientId, optional tenantId (GUIDs)azure.workload.identity/client-id (and azure.workload.identity/tenant-id when set) on the ServiceAccount, plus label azure.workload.identity/use: "true" on the pods.

When a package runs a shared controller and attaches static credentials to individual custom resources, the controller’s dependency accepts only a cloud identity and rejects Secret instances. For example, packages.experimental.external-secrets takes a cloud identity on deps.controllerCredentials for the controller’s ServiceAccount:

instances.external-secrets.external-secrets = {
package = packages.experimental.external-secrets;
deps.controllerCredentials = kix.cloudIdentity.aws {
roleArn = "arn:aws:iam::111122223333:role/external-secrets";
};
};

Each SecretStore or ClusterSecretStore then chooses how it authenticates:

  • Controller cloud identity: Leave auth unset on AWS (aws) and Google Cloud (gcpsm) stores, or set authType = "WorkloadIdentity" without serviceAccountRef on Azure (azurekv) stores. out.mkSecretStore and out.mkClusterSecretStore fail evaluation if the store’s cloud does not match deps.controllerCredentials. Because every store configured this way shares the controller’s role, any namespace allowed to create a SecretStore can read whatever secrets that cloud role can access.
  • Static Secret: Reference a Secret in the store’s spec (such as auth.secretRef on AWS and Google Cloud, or authSecretRef on Azure).
  • Per-store ServiceAccount: Reference a dedicated ServiceAccount on the store (auth.jwt.serviceAccountRef on AWS, auth.workloadIdentity on Google Cloud, or serviceAccountRef on Azure), which External Secrets recommends when multiple teams share one controller. Because no pod runs under that ServiceAccount, the controller reads its annotations and requests a token for it directly, so kix.cloudIdentity does not apply. Set the annotation External Secrets expects directly on that ServiceAccount (eks.amazonaws.com/role-arn on AWS, iam.gke.io/gcp-service-account on Google Cloud, or azure.workload.identity/client-id and optional azure.workload.identity/tenant-id on Azure). The eks, gke, gke-autopilot, and aks flavors already allow their cloud’s annotation domain; on other clusters, add the domain to scorecard.knownAnnotationDomains to avoid a scorecard warning.

The cluster’s cloudIdentity role provider controls how Kix renders the identity. The eks, gke, gke-autopilot, and aks flavors declare this provider automatically (Flavors and capabilities). Kix also writes kix.run/cloud-identity (containing the identity and mechanism as JSON) on the ServiceAccount, orders the ServiceAccount after the cloudIdentity provider, and adds checksum/cloud-identity to every pod template referencing that ServiceAccount so changing the identity restarts the pods.

On AWS and Azure, kix deploy verifies that new pods of a Deployment, StatefulSet, or DaemonSet actually receive their cloud identity. When a cloud webhook grants an identity to a pod, it injects environment variables into every container: AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE for IRSA, AWS_CONTAINER_CREDENTIALS_FULL_URI and AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE for EKS Pod Identity, and AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_FEDERATED_TOKEN_FILE for Microsoft Entra Workload ID. Kix records the expected variables (and any configured role ARN, client ID, or tenant ID) in the workload’s kix.run/cloud-identity-env annotation. While waiting for rollout, kix deploy checks every pod of the new revision and fails the workload with CloudIdentityNotApplied if a variable is missing or has a different value. This catches an inactive webhook, a missing EKS Pod Identity association, or an EKS Pod Identity association that overrides IRSA. If a container receives EKS Pod Identity instead of IRSA (or IRSA instead of EKS Pod Identity), the error names the mechanism the cluster applied. Cloud webhooks do not overwrite a container’s existing environment variables. If a container sets AWS_ROLE_ARN, AZURE_CLIENT_ID, or a configured AZURE_TENANT_ID to a different value (or valueFrom), the error reports what the container set and the expected value. Remove that variable from the container’s env, or exclude the container with the skip-containers annotation below.

Kix skips containers excluded by a pod’s skip-containers annotation: eks.amazonaws.com/skip-containers (comma-separated, or <annotationPrefix>/skip-containers when irsaWebhook.annotationPrefix is set) on AWS, and azure.workload.identity/skip-containers (semicolon-separated) on Azure. AWS documents eks.amazonaws.com/skip-containers only for IRSA, but in testing on a live EKS cluster, containers listed in this annotation received no EKS Pod Identity environment variables or token mount. Kix does not run this check on GKE (which injects no environment variables), on Jobs or CronJobs, on init or ephemeral containers, or on pods created by an operator.

When one package owns the ServiceAccount and another configures the cloud provider, set the cloud identity on the package that owns the ServiceAccount. For example, pass the cloud identity to deps.controllerIdentity on cert-manager, and leave the credential fields out of the Route 53, Cloud DNS, or Azure DNS solver on cluster-issuer so it uses the controller’s credentials. Static keys still go to deps.issuerCredentials on cluster-issuer. If a solver without credential fields targets a different cloud than deps.controllerIdentity, evaluation fails. When deps.controllerIdentity is unset, the controller uses whatever default credentials the cluster gives the pod. On GKE with Workload Identity Federation, the pod runs as its Kubernetes ServiceAccount principal, which has no IAM roles unless you grant them (matching kix.cloudIdentity.gcp { }). On EKS and AKS, the pod uses the node’s identity if the node allows access to the instance metadata service, and otherwise has no cloud credentials. See Configure cert-manager issuers.

Kix does not create cloud IAM resources; create them in your cloud account for each ServiceAccount with a cloud identity. Run kix list resources <cluster> to view these ServiceAccounts under “Cloud identities”, or kix list resources <cluster> -o json to read the cloudIdentities array (namespace, serviceAccount, cloud, mechanism, identity, subject, subjectPlaceholders, kubernetesSubject, and trustPrincipal) from tools such as Terraform.

In cloudIdentities, kubernetesSubject is always system:serviceaccount:<namespace>:<serviceaccount>, and subject holds the cloud-specific identifier (or null for EKS Pod Identity, which takes namespace and serviceAccount as separate fields). On Google Cloud, subject contains <project-id> (and <project-number> for gcp { }) because Kix does not know the Google Cloud project for the cluster’s workload identity pool. subjectPlaceholders lists any placeholders in subject; replace each one before using subject. For EKS Pod Identity, trustPrincipal is pods.eks.amazonaws.com, the AWS service principal the IAM role must trust; for all other mechanisms, it is null. Each cloud formats the ServiceAccount identifier differently:

Cloud and mechanismWhat to createServiceAccount identifier
AWS, IRSAIAM role trust policy conditioned on the cluster’s OIDC providersystem:serviceaccount:<namespace>:<serviceaccount> in the sub condition
AWS, EKS Pod IdentityEKS Pod Identity association linking the ServiceAccount to roleArn, and an IAM role trust policy allowing pods.eks.amazonaws.comSeparate namespace and serviceAccount fields on the association
Google Cloud, gcp { serviceAccount = "..."; }roles/iam.workloadIdentityUser binding on the Google service accountserviceAccount:<project-id>.svc.id.goog[<namespace>/<serviceaccount>]
Google Cloud, gcp { }IAM role bindings granted directly to the Kubernetes ServiceAccountprincipal://iam.googleapis.com/projects/<project-number>/locations/global/workloadIdentityPools/<project-id>.svc.id.goog/subject/ns/<namespace>/sa/<serviceaccount>
Azure, Entra Workload IDFederated identity credential on the managed identity or app registration for the cluster’s OIDC issuersystem:serviceaccount:<namespace>:<serviceaccount> as the subject

kix list resources includes only ServiceAccounts that Kix renders directly. When an operator creates a ServiceAccount at runtime from a custom resource (such as <cluster>-patroni for stackgres-cluster), check the package’s guide for the ServiceAccount name.

Kix cannot verify whether the cloud provider accepts an identity. If an IAM role is missing permissions, or its trust policy or binding names the wrong ServiceAccount, most pods still start and pass their probes. Both kix deploy and kix status then report them ready while their cloud API calls fail. Missing cloud access fails the deploy only when a workload exits at startup (such as tempo) or a custom resource fails its readiness check (such as a BackupStorageLocation in velero that its controller marks Unavailable). After deploying a cloud identity, check the pod logs for errors such as AccessDenied or 403. See What readiness does not show.

Always set the cloud identity on the instance whose pods call the cloud API. When a separate instance configures the cloud service (such as backup storage), enable pod credentials or pass a static Secret on that instance instead. For example, to back up StackGres with a cloud identity, enable useIAMRole or fetchCredentialsFromMetadataService on stackgres-object-storage (with no Secret) and set deps.backupIdentity on each stackgres-cluster instance (see Back up with a cloud identity). When an operator creates the ServiceAccount and pods from a custom resource, as StackGres does, Kix cannot restart running pods automatically when the identity changes.

Evaluation fails when:

  • an identity has an unknown, missing, or malformed field;
  • the cluster has no cloudIdentity provider;
  • the identity’s cloud does not match the cluster’s cloudIdentity provider or the cloud API the package calls;
  • the package does not accept that dependency ([K3646]); or
  • a workload with hostNetwork: true uses a ServiceAccount with a GKE identity ([K2669]), because GKE does not grant Workload Identity to host-network pods and runs them as the node’s service account. This check runs in the workload builders (scope.mkDeployment, mkStatefulSet, mkDaemonSet, mkJob, and mkCronJob), including when a partsOverlays entry rebuilds a workload with one of them. An overlay that patches hostNetwork onto an already built workload (such as base.deployment // { spec = ...; }) is not checked.

When an operator creates the ServiceAccount and pods (as CloudNativePG does for cnpg-cluster), changing a cloud identity does not restart those pods automatically. Kix writes the cloud identity annotations to the operator’s custom resource (spec.serviceAccountTemplate on the Cluster) and cannot add checksum/cloud-identity to the pods. Restart the pods after deploying the change (for cnpg-cluster, run kubectl cnpg restart <cluster>). With cnpg-cluster’s default settings, CloudNativePG recreates the primary pod last without switching over to a replica, so the database is unavailable until the new primary pod is ready.

If a package does not yet accept kix.cloudIdentity, add the cloud’s annotation to its ServiceAccount with partsOverlays. The cloud flavors declare their annotation domains, so the scorecard allows the annotation without warning. Changing a ServiceAccount annotation in partsOverlays does not restart pods automatically:

partsOverlays = [
(scope: self: base: {
serviceAccount = scope.mkResource {
apiVersion = "v1";
kind = "ServiceAccount";
name = base.serviceAccount.name;
annotations."eks.amazonaws.com/role-arn" = "arn:aws:iam::111122223333:role/report-uploader";
};
})
];

On a self-managed cluster running a workload identity webhook, add the matching module alongside the cluster flavor:

modules = [
kix.flavors.kubeadm
kix.modules.experimental.irsa-webhook # runs amazon-eks-pod-identity-webhook
# Only when the webhook runs with another --annotation-prefix:
{ irsaWebhook.annotationPrefix = "irsa.example.com"; }
];

Use kix.modules.experimental.azure-workload-identity-webhook on self-managed clusters running the Azure Workload Identity webhook. Kix does not yet include a module for Google Cloud identities outside GKE.

To share a workload definition across clusters that use cloud identities and clusters that use Secrets, set deps.providerCredentials in each cluster file. See Keep credentials in the cluster file.

instances.<namespace>.<name>.aliases sets the dependency-resolution aliases for an instance.

instances.apps.valkey-cache = {
package = packages.valkey;
aliases = [ "cache" "redis" ];
};
  • The instance’s own <name> (valkey-cache above) and any roles in the package’s meta.roles are always registered as resolution keys.
  • When aliases is unset (the default), Kix registers the package’s meta.defaultAliases.
  • When aliases is set, it replaces meta.defaultAliases. Include any default alias the instance should still answer. aliases = [ ] gives the instance no aliases, so it answers only its instance name and the package’s meta.roles.

When multiple instances in a cluster provide the same service (such as two PostgreSQL clusters or two ingress controllers), prefer wiring deps.<arg> = ref.<namespace>.<instance> on the consumer rather than inventing per-instance aliases.

Setting optional = true keeps a declared instance dormant unless an active instance transitively requires it.

instances.data.clickhouse = {
package = packages.experimental.clickhouse-cluster;
optional = true;
config.shards = 2;
};

Kix starts from all non-optional instances (optional = false) and walks the dependency graph to find all transitively required instances. An optional instance becomes active when an active instance reaches it through:

  1. a required build argument (one with no ? null default) that matches the optional instance’s name, aliases, meta.defaultAliases, or meta.roles; or
  2. an explicit deps.<arg> = ref.<namespace>.<instance> (or an entry in a deps ref list).

An optional build argument ({ prometheus ? null, ... }) never activates a dormant optional instance, and a dormant optional instance or import never answers an optional build argument (the argument receives null unless an active instance matches). Note that extraDeps or a ref in out on a kix.mkImport instance also does not activate an optional instance.

When activated, the instance is stamped with kix.run/optional-activated: "true" on its PackageInstance record and deployed normally. When dormant, it emits no manifests, skips dependency resolution, and injects no deps.<arg>.config into other instances, so an unmet dependency on a dormant instance does not fail evaluation.

instances.<namespace>.<name>.availability overrides cluster.availability.default for a single instance.

instances.apps.preview = {
package = packages.web;
availability = "none";
};
PropertyValue
Typenull | "none" | "pod" | "node" | "zone"
Defaultnull (inherits cluster.availability.default)
Maximum allowedcluster.availability.substrate

An instance can request a higher or lower availability level than cluster.availability.default, as long as it does not exceed cluster.availability.substrate. If the package declares meta.availability.max (or a workload builder declares availability.max) below the requested level, Kix caps the effective level at that ceiling and emits a warning.

instances.<namespace>.<name>.partsOverlays transforms, adds, or removes resources in an instance’s evaluated parts tree without modifying the package definition.

instances.apps.web = {
package = packages.web;
partsOverlays = [
(scope: self: base: {
# Modify an existing resource part:
deployment = base.deployment // {
spec = lib.recursiveUpdate base.deployment.spec {
template.spec.priorityClassName = self.highPriority.out.name;
};
};
# Add a new resource part:
highPriority = scope.mkClusterResource {
apiVersion = "scheduling.k8s.io/v1";
kind = "PriorityClass";
name = "web-high-priority";
extra.value = 1000;
};
})
];
};

Kix evaluates an instance’s parts inside a single lib.fix fixed point in this order:

  1. All build entries in the package run and merge (duplicate part names across build entries are an error).
  2. Cluster-wide globalPartsOverlays run in order.
  3. The instance’s partsOverlays run in order.

Each overlay function has signature scope: self: base: attrset and its return value is merged onto base with //:

  • scope: the instance’s resource builder scope.
  • self: the final fixed point after all overlays have run. Read self.<part>.out.* when referencing another part so dependencies are tracked.
  • base: the parts attribute set produced before the current overlay ran. Read base.<part> when wrapping or modifying an existing part so you do not create an infinite recursion on self.<part>.
  • Setting a non-root part to null removes it from the emitted manifests (root itself must remain a valid resource).

kix.mkEnv stamps a reusable set of instances into environment-prefixed namespaces (<envName>-<setName>).

kix.mkEnv envName envConfig instanceSets
ArgumentTypeMeaning
envNamestrEnvironment prefix prepended to each instance set key ("${envName}-${setName}").
envConfig.configattrs (optional, default { })Environment-wide parameters passed to each set function as env.config.
envConfig.overridesattrs (optional, default { })Per-set, per-instance overrides (overrides.<setName>.<instName>.{ config?, parts? }).
instanceSetsattrsOf ({ ref, env } -> attrsOf instanceDef)Functions returning instance definitions for each logical namespace suffix <setName>.
let
appSet = { env, ... }: {
api = {
package = packages.api;
config = {
replicas = env.config.replicas;
ingress.host = "api.${env.name}.example.com";
};
};
};
in
{
instances =
(kix.mkEnv "staging" {
config.replicas = 1;
} { app = appSet; })
// (kix.mkEnv "prod" {
config.replicas = 3;
overrides.app.api.config.replicas = 5;
} { app = appSet; });
}

Key behaviors of kix.mkEnv:

  • The example above produces instances."staging-app".api and instances."prod-app".api.
  • Because dependency resolution prefers instances in the same namespace, services stamped into "staging-app" resolve dependencies in "staging-app" first.
  • overrides.<setName>.<instName>.config is shallow-merged (//) onto the instance’s config attribute set. If you need deep module merging for nested options, define an additional module targeting instances."<envName>-<setName>".<instName>.config instead.
  • All environments stamped into one cluster share a single Activation record and deploy together. For environments that must deploy independently, build separate cluster definitions that import a shared base module.

kix.mergeFragments combines cluster fragments authored by different teams into a single namespaces and instances configuration while rejecting collisions.

kix.mergeFragments {
fragments = [
(import ./teams/checkout.nix)
(import ./teams/search.nix)
];
namespacePolicies = {
checkout.podSecurity = "restricted";
search.podSecurity = "restricted";
};
}
FieldTypeDefaultBehavior
fragmentslistOf { namespaces?, instances? }requiredEach fragment’s instances may be an attribute set or a function args: attrset. Defining the same instances.<namespace>.<name> in more than one fragment throws an evaluation error.
namespacePoliciesattrsOf attrs{ }Deep-merged with the fragments’ namespaces definitions. Any conflicting leaf attribute across fragments or namespacePolicies throws an evaluation error.