$ show hall/kubenix
Kubenix is a Nix-based framework for declarative Kubernetes management. It uses the NixOS module system to define Kubernetes resources, Helm charts, Docker images, and custom resources in a type-safe, composable manner. The project provides a CLI tool for applying manifests with diffing, pruning, and secret injection via vals. At its core, kubenix is a set of Nix library functions and modules that evaluate user configuration to produce Kubernetes YAML/JSON. It supports submodules (nested composable configurations), testing frameworks (including kubetest), and code generation from Kubernetes OpenAPI specs. The architecture is purely functional, leveraging Nix's lazy evaluation to merge and validate resources at build time. This is a hybrid project combining a library (Nix modules and functions) with an application (CLI tool), but it is classified as an application because its primary deliverable is a deployable package and CLI.
The LLM identified 5 files worth highlighting for reuse:
This file provides the evalModules function as a plain importable function of pkgs, enabling module evaluation without flake machinery. It encapsulates the kubenix special argument (lib, evalModules, modules) and uses lib.evalModules with recursiveUpdate to support both 'module' and 'modules' attributes. It's a clean, reusable entry point that decouples the evaluator from the flake structure, making it suitable for use in nixpkgs or other non-flake contexts.
Converts a Helm chart (fetched as a derivation) to a JSON representation of its templated resources. It runs 'helm template' with configurable parameters (values, namespace, kubeVersion, includeCRDs, noHooks, apiVersions) and then uses yq to clean null values and convert to JSON. The function is pure, deterministic, and parameterized, making it reusable for any Helm chart. It separates the YAML and JSON steps into derivations for debuggability.
Implements a multi-versioned, feature-tagged submodule system on top of NixOS module system. Allows importing submodule 'prototypes' and instantiating them with arguments, with support for version matching (exact or regex), default propagation via features/tags, passthru of configs to parent, and nested submodule support. It demonstrates advanced Nix module composition techniques and can be extracted for other projects needing reusable, versioned configuration units.
Exports `copyDockerImages`, a function that generates a `writeShellApplication` script for pushing multiple Docker images to registries using skopeo. It handles tarball vs executable images, optional vals expansion for dynamic URIs, and per-image registry overrides. The script is self-contained and customizable (args, useVals), demonstrating a reusable pattern for generating deployment tooling from Nix.
Generates Nix module option declarations from a Kubernetes OpenAPI specification (swagger.json). It produces a complete Nix file with typed options for all Kubernetes resources, including CRDs handling, patch merge keys, list-to-attribute coercion, and alias creation for latest API versions. This is a sophisticated metaprogramming component that could be adapted to generate type-safe Nix modules from any OpenAPI schema, not just Kubernetes.