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.

  1. Enable experimental features nix-command and flakes.

    • If using NixOS, add the following to your configuration.nix and rebuild your system.

      nix.settings.experimental-features = "nix-command flakes";
      
    • If not using NixOS,

      1. Add the following to nix.conf (located at ~/.config/nix/ or /etc/nix/nix.conf).

        experimental-features = nix-command flakes
      2. Restart the Nix daemon.

        sudo systemctl restart nix-daemon.service`
  2. Verify that the experimental features nix-command and flakes are enabled.

nix config show | grep flakes
nix config show | grep nix-command

Standalone Setup

  1. To prepare an initial Home Manager configuration for your logged in user, you can run the Home Manager init command 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 using nix run temporarily).

    • 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.nix and a home.nix file in ~/.config/home-manager, creating the directory if it does not exist.

  2. You can validate the Home Manager installation by running: home-manager --help.

  3. After initialization, we can see the files created by the Home Manager:

ls ~/.config/home-manager
 
# flake.lock  flake.nix  home.nix
  1. After the initial activation has completed successfully then building and activating your flake-based configuration is as simple as:
home-manager switch
  1. 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 ~/hmconf

If 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.