How to make home-manager available on the CLI in NixOS?

I have followed Misterio77’s minimal config example to configure my system (flake & home-manager). Initially, I expected home-manager to get installed when running nixos-rebuild switch -v --show-trace -L --flake /etc/nixos#hostname. That did not happen.

According to the Home Manager Manual:

[When using flake.nix] The Home Manager configuration is then part of the NixOS configuration and is automatically rebuilt with the system when using the appropriate command for the system, such as nixos-rebuild switch --flake .


The following is written in the template config:

Standalone home-manager configuration entrypoint
Available through ‘home-manager --flake .#your-username@your-hostname’

But, nixos-rebuild switch does not install home-manager, so trying to run the above mentioned command only returns home-manager: command not found.

Should not home-manager get installed following the above template? If not, how should one declarative install home-manager?

That flake creates two separate things:

  • A NixOS configuration usable through e.g. nixos-rebuild
  • A Home Manager configuration usable through home-manager switch

At high-level glance, the NixOS configuration does not use Home Manager at all, so it is not installed.

If you want home-manager enabled in your NixOS configuration, you would need to:

  1. Import home-manager system module (doc)
  2. Enable programs.home-manager.enable. In the HM doc example, that would be done under home-manager.users.jdoe, say, inside home.nix.

However, proper answer comes down to what your use case for home manager is:

  • If you have a single machine NixOS where you want to use both NixOS options and Home Manager ones, you don’t need the homeConfigurations output at all.

  • If you have machine A on NixOS and machine B on a different OS but you want to use same user config across all machines – you would need to reuse the modules(same home.nix as an example) in homeConfigurations output by importing them in the flake.nix.

1 Like

Thank you for providing a great answer, and describing the use cases. Based on your input I ended up doing the following:

    nixosConfigurations = {
      laptopOne = nixpkgs.lib.nixosSystem {
        specialArgs = {inherit inputs outputs;};
        # > Our main nixos configuration file <
        modules = [
            ./hosts/laptopOne/configuration.nix

        home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.dob = import ./home-manager/home.nix;
          }

        ];
      };
    };

Instead of what was done in the template:

    nixosConfigurations = {
      # FIXME replace with your hostname
      your-hostname = nixpkgs.lib.nixosSystem {
        specialArgs = {inherit inputs outputs;};
        # > Our main nixos configuration file <
        modules = [./nixos/configuration.nix];
      };
    };

    # Standalone home-manager configuration entrypoint
    # Available through 'home-manager --flake .#your-username@your-hostname'
    homeConfigurations = {
      # FIXME replace with your username@hostname
      "your-username@your-hostname" = home-manager.lib.homeManagerConfiguration {
        pkgs = nixpkgs.legacyPackages.x86_64-linux; # Home-manager requires 'pkgs' instance
        extraSpecialArgs = {inherit inputs outputs;};
        # > Our main home-manager configuration file <
        modules = [./home-manager/home.nix];
      };
    };