Skip to content

Home Environments

Den supports several Home Nix classes:

  • homeManager
  • hjem
  • maid
  • user

All Home integrations are opt-in and must be enabled explicitly, except for user which is the built-in user environment on NixOS and nix-Darwin.

# Per user
den.hosts.x86_64-linux.igloo.users.tux.classes = [ "homeManager" "hjem" ];
# As default for all users, unless they specify other classes.
den.schema.user.classes = lib.mkDefault [ "homeManager" ];

Home integration contexts, like den.ctx.hm-host only activate when at least one host user has homeManager in their classes. If so, the integration imports the HomeManager OS module, and forwards each user’s homeManager class into home-manager.users.<userName>.

Same details regarding home-manager apply to other home types like hjem and maid.

  • inputs.home-manager must exist in your flake inputs or have custom host.home-manager.module.
  • At least one user must have homeManager in their classes.
flowchart TD
  host["den.ctx.host"] -->|"into.hm-host"| hmhost["den.ctx.hm-host"]
  hmhost -->|"imports HM module"| mod["home-manager.nixosModules"]
  hmhost -->|"into.hm-user (per user)"| hmuser["den.ctx.hm-user"]
  hmuser -->|"forward homeManager class"| target["home-manager.users.alice"]
  1. hm-os.nix detects hosts with HM-enabled users and supported OS class.
  2. It produces den.ctx.hm-host, which imports the HM OS-level module.
  3. hm-integration.nix creates den.ctx.hm-user per HM user, forwarding the homeManager class into home-manager.users.<userName>.
den.aspects.alice = {
homeManager = { pkgs, ... }: {
home.packages = [ pkgs.htop ];
programs.git.enable = true;
};
};

The homeManager class contents are forwarded to the OS-level home-manager.users.alice automatically.

Override the HM module per host if needed:

den.hosts.x86_64-linux.laptop = {
users.vic.classes = [ "home-manager" ];
home-manager.module = inputs.home-manager-unstable.nixosModules.home-manager;
};

For machines without root access:

den.homes.x86_64-linux.tux = { };

This produces a homeConfigurations.tux that can be built with the home-manager CLI.

To associate a home with a specific host, name the home using the following format:

den.homes.x86_64-linux."tux@igloo" = { };

This will output homeConfigurations."tux@igloo". Given a system where the following is true:

Terminal window
$ whoami
tux
$ hostname
igloo

The home-manager CLI will automatically select homeConfigurations."tux@igloo" as the output.

You can configure the home using the aspect named after the user:

den.aspects.tux = { }; # user configuration for tux that should apply on any hosts

Den will correctly set <home>.userName so that batteries like define-user work.

Note: igloo here does not need to be a host managed by den (e.g. den.hosts.<system>.igloo), it can also represent the hostname of an externally managed machine outside of your control.

Host-specific standalone home configuration

Section titled “Host-specific standalone home configuration”

To create host-specific configurations for your standalone home, you can use the den.provides.mutual-provider battery:

den.homes.x86_64-linux."tux@igloo" = { };
den.ctx.user.includes = [ den._.mutual-provider ];

You can then configure it using the following aspect:

den.aspects.tux.provides.igloo = { }; # user configuration for tux that should only apply on igloo

This pattern allows you to manage your host and user separately:

den.hosts.x86_64-linux.igloo.users.tux = { };
den.homes.x86_64-linux."tux@igloo" = { };

Unlike host-managed user configurations, the host and user configuration can be activated independently from each other.

This can speed up the rebuild process since you no longer need to rebuild both environments every time.

Tip: The host configuration can still be read by the user via the osConfig module argument

hjem is an alternative, lightweight home environment manager.

# Per host
den.hosts.x86_64-linux.laptop = {
users.alice.classes = [ "hjem" ];
};
# On all hosts
den.schema.host.hjem.enable = true;
  • inputs.hjem must exist.
  • Users must have hjem in their classes.
den.aspects.alice.hjem = { };

nix-maid is another user-environment manager for NixOS.

den.hosts.x86_64-linux.laptop = {
users.alice.classes = [ "maid" ];
};
  • inputs.nix-maid must exist.
  • Host class must be "nixos".
  • Users must have maid in their classes.
den.aspects.alice.maid = {
# nix-maid configuration
};

A user can participate in multiple environments:

den.hosts.x86_64-linux.laptop = {
users.alice.classes = [ "homeManager" "hjem" ];
home-manager.enable = true;
hjem.enable = true;
};

Both homeManager and hjem configurations from den.aspects.alice will be forwarded to their respective targets.

Contribute Community Sponsor