Like kubenix, but easier
Find a file
lillecarl 724859ec1b fmt
2026-01-21 17:23:32 +00:00
apiResources Initial commit 2025-10-13 16:25:19 +02:00
demo Oops, stringdata is for secrets 2025-10-21 16:09:02 +02:00
lib fix mkNumberedList 2025-11-24 01:17:30 +01:00
pkgs fmt 2026-01-21 17:23:32 +00:00
tmp Implement convertLists for Helm and importyaml 2025-10-20 10:10:50 +02:00
assertions.nix Add assertions module 2025-10-23 15:44:52 +02:00
default.nix Add assertions module 2025-10-23 15:44:52 +02:00
helm.nix helm: better tracing when importing broken manifests 2026-01-20 08:07:06 +00:00
importyaml.nix importyaml: align with Helm 2026-01-20 08:07:43 +00:00
internal.nix runCommandLocal -> runCommand 2025-11-23 18:57:51 +01:00
kluctl.nix kluctl: add skipDeleteIfTags globally 2026-01-20 06:55:40 +00:00
kubernetes.nix fmt 2026-01-21 17:23:32 +00:00
README.md Add info about none namespace quirk 2025-10-14 16:28:42 +02:00
TODO.md Add TODO 2025-10-19 15:05:35 +02:00
validation.nix Implement kubeconform validation 2025-10-21 16:09:15 +02:00

easykubenix

Note that a lot of this text is AI slop(because i write like a toddler), don't judge the book by it's cover though!

easykubenix uses the NixOS module system to generate Kubernetes manifests. It avoids generating Nix types for the entire Kubernetes API, resulting in faster evaluations and a simpler user experience compared to alternatives.

Manifest validation is performed by a script that applies the generated resources against an ephemeral etcd and kube-apiserver instance. This approach uses the Kubernetes API server as the single source of truth for validation.

Usage

Define your resources using the NixOS module system. The top-level attribute is kubernetes, followed by the resource kind, then the resource name.

Try the demo

Evaluate the demo YAML and apply it to an ephemeral apiserver

nix run --file . validationScript

Check the generated YAML

cat $(nix build --print-out-paths --file . manifestYAMLFile)

Modules API

{
  kubernetes.namespace.ConfigMap.my-awesome-configmap = {
    stringData."config.json" = builtins.toJSON { key = "value"; };
  };

  kubernetes.namespace.Deployment.my-app = {
    spec.replicas = 3;
  };
}

How to create an easykubenix instance (probably)

{ pkgs ? import <nixpkgs> {}}:
let
  easykubenix = import (
    builtins.fetchTree {
      type = "github";
      owner = "lillecarl";
      repo = "easykubenix";
    }
  );
in
easykubenix {
  inherit pkgs;
  modules = [
    ./my-modules.nix
  ];
}

To generate the final YAML manifests, import your modules into the provided eval function.

# default.nix
{ pkgs ? import <nixpkgs> {} }:
(import <easykubenix> {
  inherit pkgs;
  modules = [ ./my-modules.nix ];
}).eval

Quirks:

The namespace "none" in kubernetes.resources.none.kind.name is reserved for not setting any namespace. If you create resources in the none namespace you must set metadata.namespace yourself.

Features

Manifest Validation

To validate your manifests against a real Kubernetes API server without affecting a live cluster, run the validation script.

nix run --file . validationScript

This command builds your manifests, spins up a temporary API server, and applies the configuration to it, reporting any errors from kubectl.

Helm Chart Rendering

easykubenix can render Helm charts and import their resources into the NixOS module system. This allows you to override values from rendered charts using standard module system functions like lib.mkForce.

The import is performed via Import From Derivation (IFD), which is necessary as it requires running helm template during Nix evaluation.

See the demo for examples

Kluctl Integration

kluctl is a CLI and GitOps tool that deploys manifests. It's distinctive feature is that it adds a label (discriminator) to every resource deployed which means when applying manifests with --prune it scans the watch-cache for resources with this label and removes them if they're not in the manifest we're applying.

Essentially kubectl apply --prune -l on steroids. It also integrates SOPS which can be used to keep secrets out of the Nix store.

easykubenix supports generating a minimal kluctl project and deployment script.