Skip to content

Users and homes

A person uses several machines. Some run NixOS, some only home-manager. In yen the person is data, and their home is one aspect that is active in both places.

modules/fleet.nix
# Hosts build NixOS and hold their users. Homes are standalone home-manager configurations.
{
yen,
lib,
inputs,
...
}:
let
inherit (yen.lib) same is;
in
{
yen.kinds.fleet = {
spawns = {
host = _: yen.host;
home = _: yen.home;
};
sinks.out.reduce = yen.lib.reduce.merge;
};
yen.kinds.host = {
spawns.user = s: lib.filterAttrs (_: u: lib.any (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 = is lib.isList;
sinks.homeManager.nixos =
{ user, homeManager, ... }:
{
home-manager.users.${user.name}.imports = homeManager;
};
};
yen.kinds.home = {
fields = {
user = yen.kinds.user;
system = lib.types.str;
};
sinks.homeManager.out =
{ home, homeManager, ... }:
{
homeConfigurations.${home.name} = inputs.home-manager.lib.homeManagerConfiguration {
pkgs = inputs.nixpkgs.legacyPackages.${home.system};
modules = homeManager;
};
};
};
yen.aspects.home-manager = {
at = yen.lib.has yen.kinds.user;
nixos = {
imports = [ inputs.home-manager.nixosModules.home-manager ];
home-manager.useGlobalPkgs = true;
};
};
yen.fleet.main = { };
yen.flake = { out, ... }: out;
}
  • A user lives under each host in its hosts. Its homeManager sink forwards into the host’s NixOS.
  • A home lives under the fleet. Its homeManager sink builds homeConfigurations.<name>.
modules/alice.nix
# alice: an account on the server, and a standalone home for her laptop (any Linux, no NixOS).
{ yen, ... }:
let
alice = yen.user.alice;
# her own scopes, and every home that belongs to her
hers = [
alice
(s: s.kind == "home" && yen.lib.same s.user alice)
];
in
{
yen.user.alice.hosts = [ yen.host.server ];
yen.home."alice@laptop" = {
user = alice;
system = "x86_64-linux";
};
yen.aspects.alice-account = {
at = alice;
nixos.users.users.alice = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
};
yen.aspects.alice-home = {
at = hers; # one home config, in NixOS and standalone
homeManager = {
programs.git = {
enable = true;
userName = "Alice";
};
home.stateVersion = "25.05";
};
};
yen.aspects.standalone = {
at = yen.kinds.home;
homeManager =
{ home, ... }:
{
home.username = home.user.name;
home.homeDirectory = "/home/${home.user.name}";
};
};
}
modules/machines.nix
{ yen, ... }:
{
yen.host.server = { };
yen.aspects.server = {
at = yen.host.server;
nixos = {
networking.hostName = "server";
boot.loader.grub.device = "nodev";
fileSystems."/" = {
device = "/dev/sda1";
fsType = "ext4";
};
nixpkgs.hostPlatform = "x86_64-linux";
system.stateVersion = "25.05";
};
};
}

alice-home is active at alice’s user scope and at her home:

result
{
"fleet:main" = false;
"fleet:main/home:alice@laptop" = true;
"fleet:main/host:server" = false;
"fleet:main/host:server/user:alice" = true;
}
flowchart TD
  n6c4c773b6d["fleet main"]
  n9d2d1287a1["home alice@laptop"]
  n04467a35ae["host server"]
  ne7d28e0cc9["user alice"]
  n6c4c773b6d --> n9d2d1287a1
  n6c4c773b6d --> n04467a35ae
  n04467a35ae --> ne7d28e0cc9
Terminal window
sudo nixos-rebuild switch --flake .#server
home-manager switch --flake '.#alice@laptop'
Contribute Community Sponsor