Reusable Libraries vs Personal Fleets
Most people want to share their best NixOS and Home Manager modules across work, personal machines, and teammates — without leaking their usernames, hostnames, or SSH keys, and without forcing everyone to fork the repo.
In Yen, splitting a reusable library (./yen-modules) from a personal fleet (./modules) takes zero custom option boilerplate:
- Library files declare default aspects (with
at), opt-in capabilities (withoutat), typedsettings, and reusablekits. - Any downstream flake imports
[ inputs.my-lib.yenModules ./modules ], declares its own hosts and users, opts in withuse, tunes parameters viasettings, and opts out of defaults withdropordrop.subtree.
1. The reusable library (zero personal data)
Section titled “1. The reusable library (zero personal data)”{ yen, std, types, ...}:{ imports = [ std.modules.all ];
# Reusable library modules contain ZERO personal hostnames, usernames, or SSH keys.
# 1. Default baseline feature (consumers can opt out per host with `drop`). yen.aspects.lib-ssh = { at = yen.kinds.host; settings.port = types.opt types.port 22; nixos = { settings, ... }: { services.openssh = { enable = true; ports = [ settings.port ]; }; }; };
# 2. Opt-in capability feature (no `at`: activates only where a consumer adds `use`). yen.aspects.lib-dev-rust = { hm.programs.cargo.enable = true; nixos.environment.variables.CARGO_INCREMENTAL = "1"; };
# 3. Baseline shell config consumers can drop or extend. yen.aspects.lib-shell-defaults = { at = yen.kinds.user; hm.programs.zsh.enable = true; };}Export that folder directly from your library’s flake.nix:
outputs = { ... }: { yenModules = ./yen-modules;};2. A downstream fleet consuming it with zero forks
Section titled “2. A downstream fleet consuming it with zero forks”Here a consumer brings their own users (alice and bob) and host (workstation).
Alice opts into lib-dev-rust, Bob drops lib-shell-defaults, and workstation tunes lib-ssh to port 2222:
{ yen, ... }:{ # Consumer's personal fleet: imports the shared library and adds only local hosts & choices. yen.user.alice = { email = "alice@example.org"; # Opt in to the library's Rust capability. use = [ yen.aspects.lib-dev-rust ]; };
yen.user.bob = { email = "bob@example.org"; # Opt out of the library's default zsh feature without forking the library. drop = [ yen.aspects.lib-shell-defaults ]; };
yen.host.workstation = { addr = "198.51.100.10"; users = [ yen.user.alice yen.user.bob ]; # Tune the library's SSH port for this host only. use = [ (yen.aspects.lib-ssh { port = 2222; }) ]; };}Inspect the evaluated NixOS and Home Manager outputs:
{ hm = { workstation = { alice = { programs = { cargo = { enable = true; }; zsh = { enable = true; }; }; }; }; }; nixos = { workstation = { environment = { variables = { CARGO_INCREMENTAL = "1"; }; }; services = { openssh = { enable = true; ports = [ 2222 ]; }; }; }; };}Why this scales cleanly
Section titled “Why this scales cleanly”- No
mkEnableOptionboilerplate: an aspect withoutatis automatically opt-in viause = [ yen.aspects.<name> ]. - Clean opt-out:
drop = [ yen.aspects.<name> ]disables a default on one host or user, whiledrop.subtree = [ ... ]disables it across a host and all its users. - Zero leaks: test your library standalone in CI with a synthetic test user to guarantee no personal hostnames or secrets ever creep into
./yen-modules.
Next, drive Linux, macOS, Kubernetes, and Terraform from one inventory in NixOS, macOS, Kubernetes & Terraform.