What are the advantages of using home manager with flake as opposed just flakes with NixOS?

I have moved my dotfiles for NixOS to flakes, having just copied over my configuration.nix and hardward-configuration.nix files. It builds successfully with sudo nixos-rebuild switch --flake .#. When looking online, I see that a lot of people are using home manager as well. My questions are:

  1. What are the advantages of this over how I am doing it?
  2. What should be put in home manager and what should go in the nixosConfiguration-part?
  3. Should I use two separate commands to build nixConfiguration and homeManagerConfiguration (nix build .#homeManagerConfiguration.hertop.activationPackage; ./result/activate), or is it normal to have homeManagerConfiguration build as a part of the sudo nixos-rebuild switch -- .#?
1 Like

NixOS isn’t really built to manage anything in your home directory. If you want to work hard enough it’s possible, but home-manager already did the work for you. For, say, configuring emacs, it’s a better tool.

Generally anything that’s really only inhrerent to your user should be in home-manager (unless it can’t be, such as your choice of login shell). For me, I’ve ended up putting almost everything in home-manager, so if another user logs in on my machine, it’s a nearly vanilla experience.

Both ways of using home-manager are possible. “home-manager standalone” uses a home-manager CLI command to do the analogous thing that nixos-rebuild does for nixos. “home-manager as a nixos module” causes home-manager to be updated as part of nixos-rebuild.

The main upside of the module approach is that there’s only one set of generations for your system, not 2 interacting ones, which might be incompatible in odd ways, and all the other stateful nonsense that comes with that.

The main downside of the module approach is that you need to use sudo to enact user-specific changes to configuration.


Thank you very much for the detailed and informative answer. Would you be able to quickly point me to some resource for how I could build both NixOS and home manager from inside them same flake with the same command?


1 Like