How to install Nix home manager - kdaisho/Blog GitHub Wiki

This guide shows you how to install home-manager.

Prerequisite: nix

If you haven't installed nix, you may install it via nix-channel? I can't try anymore as I've installed nix different way -- Nix minimal setup

nix-channel --add https://nixos.org/channels/nixos-24.11 nixpkgs

If the command doesn't do the job see Nix minimal setup for installing nix. The article demonstrates how to set up nix shell using shell.nix, but I've learned using home-manager provides a lot better user experience. So once you installed nix, stop there and come back here. And also try to install nixpkgs version 24.11 to match home-manager version.

Install home manager (standalone installation)

Source: https://nix-community.github.io/home-manager/index.xhtml#sec-install-standalone

There are two options: unstabled (25.05?) and stabled (24.11) version as of Mar 2025. I pick 24.11.

Run:

nix-channel --add https://github.com/nix-community/home-manager/archive/release-24.11.tar.gz home-manager
nix-channel --update

nix-shell '<home-manager>' -A install

Now check what you just installed.

nix-channel --list

The output:

home-manager https://github.com/nix-community/home-manager/archive/release-24.11.tar.gz

Set up home.nix

Since you installed home-manager, you have home.nix at user root level ~/.config/home-manager/home.nix. All you need is to add packages you want to use in this file.

Delete a bunch of commented lines and replace everything with this.

{ config, pkgs, ... }:

{
  home.username = "jaeger";
  home.homeDirectory = "/home/jaeger";

  home.stateVersion = "24.11";

  home.packages = [
    pkgs.deno
    pkgs.nodejs_22
    pkgs.git
    pkgs.htop
    pkgs.ghc
    pkgs.haskellPackages.haskeline_0_8_2_1
    pkgs.autojump
  ];

  programs = {
    neovim.enable = true;
    home-manager.enable = true;

    zsh = {
      enable = true;
      autosuggestion.enable = true;
      oh-my-zsh = {
        enable = true;
        plugins = [ "git" "autojump" ];
        theme = "robbyrussell";
      };
    };
  };
}

Run home-manager:

home-manager switch

Troubleshooting

Existing .zshrc problem

If you see:

Existing file '/home/kali/.zshrc' is in the way of '/nix/store/hsii3fxmr0ncpkpsfhkz71kf3dq27khp-home-manager-files/.zshrc'                                                                                                                                   
Please do one of the following:
- Move or remove the above files and try again.                                                                                                                                                                                                              
- In standalone mode, use 'home-manager switch -b backup' to back up                                                                                                                                                                                         
  files automatically.                                                                                                                                                                                                                                       
- When used as a NixOS or nix-darwin module, set                                                                                                                                                                                                             
    'home-manager.backupFileExtension'                                                                                                                                                                                                                       
  to, for example, 'backup' and rebuild.       

Follow the instruction (run home-manager switch -b bkup) or you can even delete .zshrc, and try again.

Default shell problem

On Ubuntu, setting zsh that way won't immediately take effect as bash is always chosen to run. The easiest way to switch the default shell to zsh is to add this snippet to .bashrc.

if [ -x "/home/jaeger/.nix-profile/bin/zsh" ]; then
  exec /home/jaeger/.nix-profile/bin/zsh
fi