Skip to content

Wire cross-namespace dependencies explicitly

Use an explicit deps entry when a package consumes an instance in another namespace. The wiring remains visible beside the consuming instance, and the package still receives the dependency through its build argument.

This guide assumes the package already declares the dependency by naming it in a build function, such as { backend, ... }: ....

Define the module that contains the instances as a function with a ref argument:

cluster.nix
modules = [
(
{ ref, ... }:
{
# Namespace and instance configuration goes here.
}
)
];

ref mirrors the instances.<namespace>.<name> tree. Each leaf identifies one package instance.

Set deps.<argument-name> on the consuming instance. This tested example wires an application gateway to a backend in the platform namespace:

tutorials/08-namespace-deps/cluster.nix (L58–L63)
gateway = {
package = reverseProxyPackage;
# Explicit cross-namespace wiring keeps the boundary
# crossing visible at the call site.
deps.backend = ref.platform.backend;
};

View source on GitHub ↗

The left side, deps.backend, matches the package’s backend build argument. The right side, ref.platform.backend, selects the exact provider instance.

Add the provider instance under the referenced namespace as usual:

cluster.nix
instances.platform.backend = {
package = packages.echo-server;
config.message = "Hello from the platform backend";
};

Evaluate the cluster:

Run in kix-examples/
❱ kix check 08-namespace-deps
 TOOL         RESULT  DETAILS                                                       
 eval         pass    15 manifests evaluated                                        
 kubeconform  pass    skipped (this validation tool is not yet integrated with Kix) 
 pluto        pass    skipped (this validation tool is not yet integrated with Kix) 
 kyverno      pass    skipped (this validation tool is not yet integrated with Kix) 
 scorecard    pass    0 errors, 10 warnings, 2 info

A missing reference fails module evaluation. If the package declares another required build argument without a matching deps entry or resolvable provider, dependency resolution names the missing argument.