Home Environments
Enabling Homes
Section titled “Enabling Homes”Den supports several Home Nix classes:
homeManagerhjemmaiduser
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 userden.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.
Requirements
Section titled “Requirements”inputs.home-managermust exist in your flake inputs or have customhost.home-manager.module.- At least one user must have
homeManagerin theirclasses.
How it Works
Section titled “How it Works”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"]
hm-os.nixdetects hosts with HM-enabled users and supported OS class.- It produces
den.ctx.hm-host, which imports the HM OS-level module. hm-integration.nixcreatesden.ctx.hm-userper HM user, forwarding thehomeManagerclass intohome-manager.users.<userName>.
Configuring Home Manager
Section titled “Configuring Home Manager”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.
Custom HM Module
Section titled “Custom HM Module”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;};Standalone Homes (homeManager)
Section titled “Standalone Homes (homeManager)”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.
Standalone Homes bound to Host OS
Section titled “Standalone Homes bound to Host OS”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:
$ whoamitux
$ hostnameiglooThe 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 hostsDen 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 iglooSeparate host and user configuration
Section titled “Separate host and user configuration”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.
Enabling
Section titled “Enabling”# Per hostden.hosts.x86_64-linux.laptop = { users.alice.classes = [ "hjem" ];};
# On all hostsden.schema.host.hjem.enable = true;Requirements
Section titled “Requirements”inputs.hjemmust exist.- Users must have
hjemin theirclasses.
den.aspects.alice.hjem = { };nix-maid
Section titled “nix-maid”nix-maid is another user-environment manager for NixOS.
Enabling
Section titled “Enabling”den.hosts.x86_64-linux.laptop = { users.alice.classes = [ "maid" ];};Requirements
Section titled “Requirements”inputs.nix-maidmust exist.- Host class must be
"nixos". - Users must have
maidin theirclasses.
den.aspects.alice.maid = { # nix-maid configuration};Multiple User Environments
Section titled “Multiple User Environments”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.