# Kubernetes manifests for the swarm services this host deploys, rendered by # ./render.nix from their systemd units. Rendering only: nothing here applies # them or changes a unit. docs/4-implementation/k8s/manifests.md has the # design. { pkgs, lib, config, ... }: let cfg = config.services.hyperhive.k8s; yaml = pkgs.formats.yaml { }; # The manifests name store paths that live in the images, not on the host, # so the YAML carries no string context: building it builds no image and # no daemon. withoutContext = v: builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.toJSON v)); rendered = import ./render.nix { inherit lib pkgs config; }; in { imports = [ ./host-services.nix ./node.nix ]; options.services.hyperhive.k8s = { enable = lib.mkOption { type = lib.types.bool; default = false; description = '' Render Kubernetes manifests for the in-cluster swarm services this host deploys (swarm-controller, swarm-notify-router and swarm-ci-metrics) into `system.build.k8sManifests`, one YAML file per object, and the images their pods run into `system.build.k8sImages`. The manifests reference their Secrets by name only. Rendering only: the host's units stay as they are, and nothing applies the manifests to a cluster. ''; }; namespace = lib.mkOption { type = lib.types.str; default = "hyperhive"; description = "The Kubernetes namespace the rendered objects live in."; }; }; config = lib.mkIf cfg.enable { # The images those pods run, for a node to load: ./node.nix. system.build.k8sImages = rendered.images; system.build.k8sManifests = pkgs.linkFarm "hyperhive-k8s-manifests" ( lib.mapAttrsToList (path: object: { name = "${path}.yaml"; path = yaml.generate "${baseNameOf path}.yaml" (withoutContext object); }) rendered.objects ); }; }