Why does home manager also have an option to install user packages?

I just installed home manager as a NixOS module. Now I have an additional option to install user packages. But why?

What is the difference between

users.users.tiez = {
  packages = [pkgs.vlc pkgs.mpv];
};

and

home-manager.users.tiez = { pkgs, ... }: {
  home.packages = [ pkgs.vlc pkgs.mpv ];
};

Why would I want to specify packages with home manager, if I can just put them in configuration.nix?

Under NixOS, there’s probably not much of a difference. However, if you put all the user-specific packages under home-manger control, they will be available if you decide to use home-manager on a non-NixOS system. I use this quite extensively at work and it’s a breeze if you tend to regularly obtain new machines.

5 Likes

I’m a Nix(OS) newbie, but I assume the home-manager approach avoids “polluting” the search path, etc., of any other users (and system services)? On a typical single-user machine it’s probably not a major consideration, but it is arguably more elegant.

nah they basically do the same, the home-manager nixos module implementation actually just passes it to users.users.<name>.packages but as mentioned in the comment above it’s quite nice to have the option if you use home-manager on non nixos machines and also be able to add scripts and stuff in to the users path from inside the home-manager config, I for example use that hear: Home-Manager toggle between themes