What is the recommended way to use Home Manager in NixOS?

Flakes aside, is it to follow the Standalone Installation route, or as a NixOS module?

For context, I am the only person that uses my computer, but I have a couple of aux users when I need a certain level of isolation from my personal data.

TLDR: it doesn’t actually matter, maybe when you get really advanced with it you’ll develop a preference

Well, the choice you make is when you want the home-manager config activated.

  • Activate both at the same time, tied to NixOS: nixos-rebuild switch will both switch home-manager and the rest of the NixOS config → use HM as a NixOS module
  • Activate home-manager independently of NixOS: you’ll need to run home-manager switch to activate home-manager, and to activate the rest you’ll run nixos-rebuild switch as usual.

Also a slightly more advanced usecase is that when you use home-manager through the NixOS module you’ll get access to the osConfig special argument. It’ll allow you to do weird stuff like:

{ osConfig, ... }:
{
  programs.bash.enable = osConfig.security.sudo.enable;
}

This is a nonsensical example, but it enables bash in home-manager if the “parent” NixOS configuration has sudo enabled…

</pedantry>

1 Like

The one question you have to ask yourself:

Do you really want to have to use sudo to change your editors configuration?

If you can live with that, fine use the system integration, it allows for tighter coupling between the configs. If you don’t consider using sudo for user space changes valid, then you only have the standalone option.

3 Likes

There are some other difference too.

For example, it looks like the standalone installation does not support home-manager.backupFileExtension (you should instead run home-manager switch -b backup).

At least I couldn’t find a way to configure it in my home.nix file.