I am struggling to set up home-manager

The nixos wiki gives a whole load of instructions about using fetchTarball from nix-community and yet home-manager is listed in search.nixos.org packages as a package that can be installed using configuration.nix. I’ve also been on to the home-manager github and there is a difference.

Im really confused as to what i should do. I would have thought that using the package from the channel would be right instead when doing home-manager init it tells me it cant find a profile.

I would recommend installing the home-manager channel then using it as a module in your configuration.nix.

imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      <home-manager/nixos>
    ];
home-manager.users.yourUserName = { pkgs, ... }: {
    # stateVersion determines stable/unstable
     home.stateVersion = "23.11";
     home.packages = with pkgs; [
     
     ];
};

The documentation to follow Home Manager Manual

Can you elaborate on why you recommend this? How did you decide to use it instead of the other method offered by the manual, why do you think the example in the wiki uses fetchTarball instead of a channel, and what do you understand to be the purpose of pkgs.home-manager?

1 Like

Sorry for the lack of context.

I should have also provided that the original method is fine.
I added what I’ve used and what was working for me.

As for the wiki it also links to the Home Manager Manual.

I haven’t recently tried using the fetchTarball but, I believe it should work. Also as for the package home-manager I personally don’t know.

The benefit of using home-manager as a nixos module is you can just run sudo nixos-rebuild switch rather than also having to run home-manager switch.

While there are possible issues from using home-manager as a module I would start with this approach and if any conflicts arise then switch to using home-manager as standalone.

The wiki is an unofficial dumping ground of random information that is barely maintained. Follow the official home-manager docs @Kyle linked.

You can grab nix repos with fetchTarball, but:

  • In this case fetchFromGitHub would be more appropriate
  • Updating is tedious, so users don’t, hence it should not be recommended
  • If you use a different method for grabbing nixpkgs (and you probably do, because there are many better alternatives, with channels being the default), the update process is different from the rest of your update process, which exacerbates the above
  • It’s easy to forget/not know that you should specify a hash, which will make you update every time you re-evaluate your config and the cache TTL has lapsed (so ~hourly)

Doesn’t mean you can’t use a fetch* to download home-manager if you know what you’re doing, but if you did you wouldn’t be asking how to do it.

Use flakes, channels or niv. If you’re a newbie still struggling with basics, channels should probably be recommended at the moment, so you don’t have to fight the schism between official manuals and stuff written by the larger community as much initially.

The wiki probably recommends this because there is a subset of users who:

  1. Don’t like channels (most of us don’t like them, but they’re status quo)
    • They’re also a bit harder to document for, because you can’t just dump code and need to give CLI instructions
  2. Think niv is a pointless abstraction over manually managing fetch*
  3. Don’t like flakes (they’re still controversial for a variety of reasons)

That, or the article was written before the alternatives had sufficient mindshare to be considered, and has not been significantly refactored since.

This one is more subjective, but using the NixOS module significantly reduces the amount of learning you need to do, since it doesn’t introduce a wholly separate command to learn to use (and separate installation to maintain).

I’d therefore recommend it to new users who want to manage home configuration in a NixOS system, there’s enough stuff to learn as-is, you can consider making things standalone when you’re more comfortable.

Even then I don’t recommend having a standalone home-manager on NixOS, frankly, unless you have a specific use case. It’s just easier to control it with one command.

It’s for when you want to use home-manager standalone on NixOS. You can still follow the method recommended by the home-manager docs, but I think using the home-manager command installed by that package is preferable because it is always guaranteed to work with the version of nixpkgs you have.

Either way, I still think that a user who does not understand the difference between this standalone method and the standalone method from the home-manager docs should steer clear of both initially. Using the NixOS module is easier and clearer, until you have a very specific use case.

2 Likes