NixOS, macOS, Kubernetes & Terraform
With Yen, Linux servers, macOS laptops, standalone Home Manager profiles, Kubernetes manifests, and Terraform JSON can all live under one typed inventory and one set of whole-fleet checks. Because Yen core has zero NixOS dependencies, every target emits cleanly from the same model.
1. NixOS, macOS, and standalone Home Manager (std.modules.all)
Section titled “1. NixOS, macOS, and standalone Home Manager (std.modules.all)”std.modules.machines gives you host (Linux), mac (macOS), guest (MicroVM/container), user, and walled standalone home.
Shared settings emitted to os forward automatically to both nixos and darwin:
{ yen, std, ...}:{ imports = [ std.modules.all ];
yen.user.alice.email = "alice@example.org";
yen.host.workstation = { system = yen.system.x86_64-linux; addr = "198.51.100.10"; users = [ yen.user.alice ]; };
yen.mac.book = { system = yen.system.aarch64-darwin; addr = "198.51.100.20"; users = [ yen.user.alice ]; };
# Standalone walled Home Manager profile on `workstation`. yen.home."alice@workstation" = { user = yen.user.alice; on = yen.host.workstation; };
# Shared across Linux (`host`) AND macOS (`mac`) via `os`. yen.aspects.common-os = { at = yen.kinds.machine; os = { machine, ... }: { networking.hostName = machine.name; }; };
# Linux-only kernel option. yen.aspects.linux-only = { at = yen.kinds.host; nixos.boot.loader.systemd-boot.enable = true; };
# macOS-only Homebrew option. yen.aspects.mac-only = { at = yen.kinds.mac; darwin.homebrew.enable = true; };
# Standalone Home Manager profile (`wall = true` keeps OS sinks out). yen.aspects.standalone-git = { at = yen.kinds.home; hm.programs.git.enable = true; };}{ darwin = { book = { homebrew = { enable = true; }; networking = { hostName = "book"; }; }; }; home = { "alice@workstation" = { programs = { git = { enable = true; }; }; }; }; nixos = { workstation = { boot = { loader = { systemd-boot = { enable = true; }; }; }; networking = { hostName = "workstation"; }; }; };}Wire those sinks to real flake outputs with std.lib.nixos, std.lib.darwin, and std.lib.homeManager, then activate with standard commands:
sudo nixos-rebuild switch --flake .#workstationdarwin-rebuild switch --flake .#bookhome-manager switch --flake .#alice@workstation2. Beyond NixOS: Kubernetes and Terraform together
Section titled “2. Beyond NixOS: Kubernetes and Terraform together”Add any cloud kind (yen.kinds.service), emit both a Kubernetes Deployment and a Terraform security group from the exact same typed record, and enforce a production HA rule (replicas >= 2):
{ yen, types, reduce, ...}:{ yen.kinds.tier = { }; yen.tier.prod = { }; yen.tier.dev = { };
yen.kinds.service = { fields = { tier = yen.kinds.tier; image = types.str; inherit (types) port; replicas = types.opt types.int 1; }; sinks = { k8s = { reduce = reduce.merge; into.out = { service, k8s, ... }: { k8s.${service.name} = k8s; }; }; tf = { reduce = reduce.merge; into.out = { service, tf, ... }: { tf.resource.aws_security_group.${service.name} = tf; }; }; }; };
yen.kinds.root.spawns.service = _: yen.service;
yen.service.api = { tier = yen.tier.prod; image = "ghcr.io/example/api:1.4"; port = 443; replicas = 3; };
# One aspect emits BOTH a Kubernetes Deployment AND a Terraform Security Group yen.aspects.deploy-service = { at = yen.kinds.service; k8s = { service, ... }: { apiVersion = "apps/v1"; kind = "Deployment"; spec = { inherit (service) replicas; template.spec.containers = [ { inherit (service) name image; ports = [ { containerPort = service.port; } ]; } ]; }; }; tf = { service, ... }: { ingress = { from_port = service.port; to_port = service.port; protocol = "tcp"; }; }; };
yen.aspects.prod-tls = { at = yen.kinds.service.where { tier = yen.tier.prod; }; k8s.metadata.annotations."tls.example.com/mode" = "strict"; };
# Same Datalog verification enforces production HA across K8s and Terraform yen.invariants.prod-ha = { S, R }: { bad = S; pos = [ (yen.facts.service.tier S yen.tier.prod) (yen.facts.service.replicas S R) ]; when = [ (R.lt 2) ]; };}Apply both directly from your terminal — if any production service drops below 2 replicas, Yen refuses to emit either manifest:
nix eval .#yen.oknix eval --json .#k8s.api | kubectl apply -f -nix eval --json .#tf > main.tf.json && terraform plan{ k8s = { api = { apiVersion = "apps/v1"; kind = "Deployment"; metadata = { annotations = { "tls.example.com/mode" = "strict"; }; }; spec = { replicas = 3; template = { spec = { containers = [ { image = "ghcr.io/example/api:1.4"; name = "api"; ports = [ { containerPort = 443; } ]; } ]; }; }; }; }; }; tf = { resource = { aws_security_group = { api = { ingress = { from_port = 443; protocol = "tcp"; to_port = 443; }; }; }; }; };}Built-in target builders in std.lib
Section titled “Built-in target builders in std.lib”| Builder | Target output |
|---|---|
std.lib.nixos / std.lib.darwin |
nixosConfigurations and darwinConfigurations |
std.lib.homeManager / std.lib.hmIntoHost |
Standalone homeConfigurations or embedded home-manager.users.<name> |
std.lib.microvmGuest |
Embeds guest nixos modules into parent host microvm.vms.<guest> |
std.lib.k8s / std.lib.terranix / std.lib.nvf |
Kubernetes (nixidy), Terraform (terranix), and Neovim (nvf) |
std.lib.deployRs / std.lib.colmena |
Remote fleet deployment nodes |
std.lib.firewallModule / std.lib.persistModule / std.lib.nixpkgsModule |
Converts resource sinks into real NixOS modules |
All builders and their arguments are listed in Std Library Reference.
Next, see how user-level unfree, firewall ports, secrets, and persistence bubble automatically in Bubbling unfree, Firewall, Secrets & Persist.