Typed Inventory & Ref Enums
Tagging machines with checked Nix references (yen.gpu.nvidia, yen.gpu.amd, yen.gpu.apple) turns typos into immediate eval-time errors with spelling suggestions.
Declare a small empty kind (yen.kinds.gpu = { };) and list its valid values once — every module in your repo can reference them safely.
Sharing fields across Linux and macOS (extends)
Section titled “Sharing fields across Linux and macOS (extends)”In std.modules.all, both host (NixOS) and mac (nix-darwin) inherit from machine via extends = yen.kinds.machine;.
Adding one field to machine automatically gives every Linux host and MacBook that field.
{ yen, std, types, ...}:{ imports = [ std.modules.all ];
# Ref-typed enum kinds: typos fail at eval time instead of silently doing nothing. yen.kinds.gpu = { }; yen.gpu = { nvidia = { }; amd = { }; apple = { }; };
# Attach `gpu` to `machine`, so both `host` (Linux) and `mac` (macOS) inherit it. yen.kinds.machine.fields.gpu = types.maybe yen.kinds.gpu;}Now write one aspect on yen.kinds.machine for shared Nix settings (emitting to os, which forwards to both nixos and darwin), and a second aspect that fires only when gpu = yen.gpu.nvidia.
{ yen, ... }:{ yen.host.rig = { gpu = yen.gpu.nvidia; };
yen.mac.book = { gpu = yen.gpu.apple; };
# Targets every `machine` (`host` AND `mac`) via `extends` inheritance. yen.aspects.common-nix = { at = yen.kinds.machine; os = { machine, ... }: { networking.hostName = machine.name; nix.settings.experimental-features = [ "nix-command" "flakes" ]; }; };
# Targets only machines with the checked `yen.gpu.nvidia` reference. yen.aspects.nvidia-drivers = { at = yen.kinds.machine.where { gpu = yen.gpu.nvidia; }; nixos.services.xserver.videoDrivers = [ "nvidia" ]; };}Inspect both generated configs with nix eval:
nix eval .#yen.oknix eval .#nixos.rignix eval .#darwin.book{ darwin = { book = { networking = { hostName = "book"; }; nix = { settings = { experimental-features = [ "nix-command" "flakes" ]; }; }; }; }; nixos = { rig = { networking = { hostName = "rig"; }; nix = { settings = { experimental-features = [ "nix-command" "flakes" ]; }; }; services = { xserver = { videoDrivers = [ "nvidia" ]; }; }; }; };}Defining your own custom kinds
Section titled “Defining your own custom kinds”You are not limited to host and mac.
Any domain object (a cluster, a service, a router, or a team) can be a kind with its own fields and inheritance:
yen.kinds.cluster.fields.region = types.str;yen.kinds.gpuHost = { extends = yen.kinds.host; fields.vramGb = types.int;};- Compare references with
yen.lib.same a b, never raw string equality. - Zero string tags: use data-only kinds for environments, GPUs, form factors, and architectures so every typo fails closed.
Next, validate every field and redact secrets automatically in Validation, Defaults & Redacted Secrets.