Adopting Yen Incrementally
You do not need a big-bang rewrite to move an existing NixOS flake to Yen.
Keep your current configuration.nix and nixosConfigurations working, move options over one feature at a time, and verify the resulting NixOS config matches byte-for-byte.
Before: a standard NixOS configuration.nix
Section titled “Before: a standard NixOS configuration.nix”Suppose you currently build laptop from a typical configuration.nix:
# Traditional NixOS configuration.nix (before moving to Yen){ pkgs, ... }:{ networking.hostName = "laptop"; time.timeZone = "UTC";
services.openssh.enable = true; networking.firewall.allowedTCPPorts = [ 22 ];
users.users.alice = { isNormalUser = true; extraGroups = [ "wheel" ]; };
environment.systemPackages = [ pkgs.git pkgs.curl ];
system.stateVersion = "25.05";}Step 1: Plug Yen into your existing flake.nix
Section titled “Step 1: Plug Yen into your existing flake.nix”Add Yen to flake.nix and include fleet.targets.host.laptop.module right next to ./configuration.nix.
Everything still builds through your existing nixpkgs.lib.nixosSystem call:
# Step 1: Keep your existing configuration.nix and plug Yen in beside it{ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; yen.url = "github:vic/yen"; yen-std.url = "github:vic/yen?dir=std"; };
outputs = inputs: let fleet = inputs.yen.eval { args.std = inputs.yen-std; modules = ./modules; }; in { nixosConfigurations.laptop = inputs.nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ ./hardware-configuration.nix ./configuration.nix # Import migrated features from Yen one by one: fleet.targets.host.laptop.module ]; }; };}Step 2: Move options out of configuration.nix into Yen aspects
Section titled “Step 2: Move options out of configuration.nix into Yen aspects”Delete the sections you move from configuration.nix and place them in modules/migrated.nix.
Notice how every option (networking.hostName, time.timeZone, services.openssh, networking.firewall, users.users.alice, environment.systemPackages, system.stateVersion) is standard NixOS — and adding server immediately reuses all of it:
{ yen, std, ...}:{ imports = [ std.modules.all ];
# 1. Declare your existing user and hosts as typed data. yen.user.alice = { email = "alice@example.org"; groups = [ "wheel" ]; };
yen.host.laptop = { system = yen.system.x86_64-linux; workstation = true; users = [ yen.user.alice ]; };
# Adding a second host later immediately inherits `base-os` and `ssh`! yen.host.server = { system = yen.system.x86_64-linux; users = [ yen.user.alice ]; };
# 2. The exact NixOS options moved out of `configuration.nix`: yen.aspects.base-os = { at = yen.kinds.host; firewall.tcp = [ 22 ]; nixos = { host, pkgs, ... }: { networking.hostName = host.name; time.timeZone = "UTC"; services.openssh.enable = true; environment.systemPackages = [ pkgs.git pkgs.curl ]; system.stateVersion = "25.05"; }; };
yen.aspects.alice-user = { at = yen.user.alice; nixos = { user, ... }: { users.users.${user.name} = { isNormalUser = true; extraGroups = user.groups; }; }; };
# Convert collected `firewall` sink rules into `networking.firewall.allowedTCPPorts`. yen.kinds.host.sinks.firewall.into.nixos = std.lib.firewallModule { from = yen.kinds.machine.sinks.firewall; };}Inspect the exact NixOS configuration Yen builds for both laptop and server:
{ laptop = { environment = { systemPackages = [ "pkgs.git" "pkgs.curl" ]; }; networking = { firewall = { allowedTCPPorts = [ 22 ]; allowedUDPPorts = [ ]; }; hostName = "laptop"; }; services = { openssh = { enable = true; }; }; system = { stateVersion = "25.05"; }; time = { timeZone = "UTC"; }; users = { users = { alice = { extraGroups = [ "wheel" ]; isNormalUser = true; }; }; }; }; server = { environment = { systemPackages = [ "pkgs.git" "pkgs.curl" ]; }; networking = { firewall = { allowedTCPPorts = [ 22 ]; allowedUDPPorts = [ ]; }; hostName = "server"; }; services = { openssh = { enable = true; }; }; system = { stateVersion = "25.05"; }; time = { timeZone = "UTC"; }; users = { users = { alice = { extraGroups = [ "wheel" ]; isNormalUser = true; }; }; }; };}Step 3: Verify identical derivations, then retire configuration.nix
Section titled “Step 3: Verify identical derivations, then retire configuration.nix”Before switching, check that the NixOS system derivation path matches (or inspect the diff with nix store diff-closures):
nix eval --raw .#nixosConfigurations.laptop.config.system.build.toplevel.drvPathsudo nixos-rebuild switch --flake .#laptopOnce configuration.nix is empty, wire std.lib.nixos once and hand flake.nix directly to yen.mkFlake:
# Step 2: Once everything has moved out of configuration.nix, build nixosConfigurations directly# modules/outputs.nix{ inputs, yen, std, ...}:{ yen.kinds.host.sinks.nixos.into.out = std.lib.nixos { from = yen.kinds.host.sinks.nixos; builder = inputs.nixpkgs.lib.nixosSystem; };}
# flake.nix{ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; yen.url = "github:vic/yen"; yen-std.url = "github:vic/yen?dir=std"; };
outputs = inputs: inputs.yen.mkFlake { inherit inputs; std = inputs.yen-std; } ./modules;}Next, if you are coming from Den, see the 1:1 mapping in Coming From Den.