Building Composable Kits & Assemblies
A kit (yen.kits.<name>) is a generic, parameterized multi-role blueprint with zero hardcoded hostnames or personal settings.
An assembly (yen.assemblies.<name>) wires that kit onto concrete machines — and separate assemblies of the same kit stay completely isolated so peers.server.one in daily never mixes with offsite.
1. Define a kit and bundle it with parts
Section titled “1. Define a kit and bundle it with parts”Here backup defines a server role (exporting its IP via exports.repoHost) and a client role (configuring a BorgBackup job from peers.server.one).
Then managed-backup composes backup and std.kits.sshd together using parts with zero glue code:
{ yen, std, types, ...}:{ imports = [ std.modules.all std.kits.sshd ];
# 1. A two-role backup kit: server exports its endpoint; clients pull it from `peers.server.one`. yen.kits.backup.roles = { server = { min = 1; max = 1; exports.repoHost = types.str; emit = { host, ... }: { exports.repoHost = host.addr; }; persist.directories = [ "/srv/backups" ]; }; client = { min = 1; settings.schedule = types.opt types.str "daily"; nixos = { assembly, settings, peers, ... }: { services.borgbackup.jobs.${assembly.name} = { repo = "borg@${peers.server.one.exports.repoHost}:/srv/backups"; startAt = settings.schedule; }; }; }; };
# 2. Bundle kit: compose `backup` + `sshd` using `parts` with zero boilerplate! yen.kits.managed-backup = { roles = { vault = { min = 1; max = 1; }; node.min = 1; }; parts = { roles, ... }: { ssh = yen.kits.sshd { server.at = [ roles.vault.at roles.node.at ]; }; borg = yen.kits.backup { server.at = roles.vault.at; client.at = roles.node.at; }; }; };}2. Stamp out two isolated assemblies
Section titled “2. Stamp out two isolated assemblies”Notice web participates in both daily (backing up to nas1 with SSH included) and offsite (backing up weekly to nas2).
Each assembly resolves its own peers.server.one cleanly:
{ yen, ... }:{ yen.host.nas1.addr = "198.51.100.10"; yen.host.nas2.addr = "198.51.100.20"; yen.host.web.addr = "198.51.100.30";
# Assembly 1: managed backup + SSH to `nas1` (composed via `parts`). yen.assemblies.daily = yen.kits.managed-backup { vault.at = yen.host.nas1; node.at = yen.host.web; };
# Assembly 2: a completely isolated second backup assembly targeting `nas2` weekly! yen.assemblies.offsite = yen.kits.backup { server.at = yen.host.nas2; client = { at = yen.host.web; settings.schedule = "weekly"; }; };}Inspect what web received in NixOS:
{ services = { borgbackup = { jobs = { "daily/borg" = { repo = "borg@198.51.100.10:/srv/backups"; startAt = "daily"; }; offsite = { repo = "borg@198.51.100.20:/srv/backups"; startAt = "weekly"; }; }; }; openssh = { enable = true; }; };}Kit superpowers at a glance
Section titled “Kit superpowers at a glance”- Cardinality bounds (
min/max): settingmin = 1; max = 1;onserverguarantees every assembly has exactly one server (missing or duplicate servers fail closed). - Typed
exportsandpeers: roles publish facts (exports), and peer roles readpeers.<role>.one,peers.<role>.maybe, orpeers.<role>.all. - Composable
parts: higher-level stack kits (homelab,managed-backup) wire smaller kits together declaratively.
Next, explore all 9 ready-to-use kits shipped in std in Built-In Kits Catalog.