- Home Manager provides a basic system for managing a user environment or for the reproducible management of the contents of users’ home directories using the Nix package manager together with the Nix libraries found in Nixpkgs.
- It allows declarative configuration of user specific (non-global) packages and dotfiles. This includes programs, configuration files, environment variables and, well… arbitrary files.
- Unlike dotfiles repositories, Home Manager supports specifying programs, as well as their configurations.
- Link to Home Manager manual.
- Link to Home Manager wiki.
- An interesting repo that explains Home Manager and how to set it up.
Installation
Home Manager can be installed using either the legacy channel-based setup or the flake based one.
- If you open the links for any of the mentioned setups, there will be 3 choices depending on your OS. I would say choose the standalone option in either case.
- Since Nix Flakes is the modern choice, we will use that for the installation in this note.
Install Using Nix Flakes
Prerequisites
Here is the link to complete list of prerequisites if you need to read.
-
Enable experimental features
nix-commandandflakes.-
If using NixOS, add the following to your
configuration.nixand rebuild your system.nix.settings.experimental-features = "nix-command flakes"; -
If not using NixOS,
-
Add the following to
nix.conf(located at~/.config/nix/or/etc/nix/nix.conf).experimental-features = nix-command flakes -
Restart the Nix daemon.
sudo systemctl restart nix-daemon.service`
-
-
-
Verify that the experimental features
nix-commandandflakesare enabled.
nix config show | grep flakes
nix config show | grep nix-commandStandalone Setup
-
To prepare an initial Home Manager configuration for your logged in user, you can run the Home Manager
initcommand directly from its flake (what it means is, Home Manager is distributed as Nix Flakes repository. We don’t install it first but instead run it directly usingnix runtemporarily).-
Run the following command if you don’t want to switch or activate. This is useful if you want to inspect and edit the configuration before activating it:
nix run home-manager/master -- init # Edit files in ~/.config/home-manager nix run home-manager/master -- init --switch -
OR run the following command if you want to switch or activate too:
nix run home-manager/master -- init --switch
Both of these commands will generate a
flake.nixand ahome.nixfile in~/.config/home-manager, creating the directory if it does not exist. -
-
You can validate the Home Manager installation by running:
home-manager --help. -
After initialization, we can see the files created by the Home Manager:
ls ~/.config/home-manager
# flake.lock flake.nix home.nix- After the initial activation has completed successfully then building and activating your flake-based configuration is as simple as:
home-manager switch- It is possible to override the default configuration directory, if you want. For example,
nix run home-manager/master -- init --switch ~/hmconf
# And after the initial activation.
home-manager switch --flake ~/hmconfIf you want to read more details on standalone setup, go here.
Usage
Your use of Home Manager is centered around the configuration file, which is typically found at ~/.config/home-manager/home.nix in the standard installation or ~/.config/home-manager/flake.nix in a Nix flake based installation.
Once the Home Manager is installed, read this section on how to use it. Link to the usage section in the official manual.
