From configuration.nix
You have one machine and one configuration.nix. This page moves it to yen. The result builds the
same system: the docs check that both give one toplevel drvPath.
# /etc/nixos/configuration.nix, as nixos-generate-config leaves it, plus a few edits.{ pkgs, ... }:{ imports = [ ./hardware-configuration.nix ];
boot.loader.systemd-boot.enable = true; networking.hostName = "laptop"; time.timeZone = "Europe/Berlin"; i18n.defaultLocale = "en_US.UTF-8"; nix.settings.experimental-features = [ "nix-command" "flakes" ];
services.openssh.enable = true; users.users.alice = { isNormalUser = true; extraGroups = [ "wheel" ]; }; environment.systemPackages = with pkgs; [ git vim ];
system.stateVersion = "25.05";}# Generated by nixos-generate-config. yen never edits it.{ boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "usb_storage" ]; fileSystems."/" = { device = "/dev/disk/by-label/nixos"; fsType = "ext4"; }; fileSystems."/boot" = { device = "/dev/disk/by-label/boot"; fsType = "vfat"; }; nixpkgs.hostPlatform = "x86_64-linux";}What changes
Section titled “What changes”A configuration.nix mixes three things: data (the host name, the users), features (ssh, tools),
and generated hardware. yen keeps them apart:
| In configuration.nix | In yen |
|---|---|
networking.hostName = "laptop" | the instance yen.host.laptop: the name is data |
users.users.alice = … | the instance yen.user.alice, and one account aspect for every user |
services.openssh.enable = true | an aspect, active at every host |
imports = [ ./hardware-configuration.nix ] | machines/<name>/hardware-configuration.nix, found by name |
-
Get the template, and copy your two files over the ones in
machines/laptop/:Terminal window nix flake init -t github:vic/yen#from-configuration-nix -
Declare the fleet. A host builds NixOS from its
nixossink. A user lives under the hosts it logs in to.modules/fleet.nix # The fleet spawns hosts and the users that log in to them.{yen,lib,inputs,...}:{yen.kinds.fleet = {spawns.host = _: yen.host;sinks.out.reduce = yen.lib.reduce.merge;};yen.kinds.host = {spawns.user = s: lib.filterAttrs (_: u: lib.any (yen.lib.same s) u.hosts) yen.user;sinks.nixos.out ={ host, nixos, ... }:{nixosConfigurations.${host.name} = inputs.nixpkgs.lib.nixosSystem { modules = nixos; };};};yen.kinds.user.fields = {hosts = yen.lib.is lib.isList;groups = yen.lib.opt (yen.lib.is lib.isList) [ ];};yen.fleet.main = { };yen.flake = { out, ... }: out;} -
Declare your machine and your people as data:
modules/laptop.nix # The machine and its people: data, not configuration.{ yen, ... }:{yen.host.laptop = { };yen.user.alice = {hosts = [ yen.host.laptop ];groups = [ "wheel" ];};} -
Move each part of
configuration.nixto an aspect. Each one is active at every host:modules/features/machine.nix # What every host gets: its generated hardware file, its name, and the boot and locale basics.{ yen, ... }:{yen.aspects.machine = {at = yen.kinds.host;nixos ={ host, ... }:{imports = [ (../../machines + "/${host.name}/hardware-configuration.nix") ];networking.hostName = host.name;boot.loader.systemd-boot.enable = true;time.timeZone = "Europe/Berlin";i18n.defaultLocale = "en_US.UTF-8";nix.settings.experimental-features = ["nix-command""flakes"];system.stateVersion = "25.05";};};}modules/features/ssh.nix { yen, ... }:{yen.aspects.ssh = {at = yen.kinds.host;nixos.services.openssh.enable = true;};}modules/features/tools.nix # `pkgs` stays open: NixOS fills it.{ yen, ... }:{yen.aspects.tools = {at = yen.kinds.host;nixos ={ pkgs, ... }:{environment.systemPackages = with pkgs; [gitvim];};};} -
Give accounts from user data. A user has no
nixossink, so the account goes up to the host:modules/features/accounts.nix # Each user gives its account. A user has no `nixos` sink, so the account goes up to the host.{ yen, ... }:{yen.aspects.account = {at = yen.kinds.user;nixos ={ user, ... }:{users.users.${user.name} = {isNormalUser = true;extraGroups = user.groups;};};};} -
Switch:
Terminal window sudo nixos-rebuild switch --flake .#laptop
Your second machine
Section titled “Your second machine”Add yen.host.desktop = { };, its machines/desktop/hardware-configuration.nix, and yen.host.desktop
to the hosts of each user. Every aspect above is active there too. Continue with From a flake.