Users.users.<name>.packages vs home-manager packages

(Original post, feel free to answer there.)

Is there any practical difference between

users.users.default.packages = [
  pkgs.foo
];

and

home-manager = {
  users.default = {
    config,
    pkgs,
    nixpkgs,
    lib,
    specialArgs,
    options,
    modulesPath,
    nixosConfig,
    osConfig,
  }: {
    home = {
      packages = [
        pkgs.foo
      ];
    };

  };
  useGlobalPkgs = true;
};
2 Likes

If you set home-manager.useUserPackages = true; then no, otherwise yes, a little.

home-manager installs its packages in ~/.nix-profile by default, whereas users.users.<username>.packages puts them in /etc/profiles/per-user/<username>.

1 Like

What’s the practical and material impact of this difference?

1 Like

Not much. The priority order and/or collision properties with other ways of getting things into PATH, primarily.

nix-env will clash with home-manager packages providing the same binary without useUserPackages, with it, home-manager will clash with users.users.<username>.packages instead. ~/.nix-profile is higher in the search order, so it would override /etc/profiles/per-user/<username>. Things like that.

3 Likes

Hi folks,

I’m a bit of a Nix Noob, but trying to dive in deep by daily driving NixOs. Overall, I’m so impressed, i think I’ll be going Nix Everywhere.

So, I find myself asking the exact same question as OP. Having read the replies, can I confirm a couple (2) of other practical differences pls?

  1. Firstly, I’m hopeful that I’ll one day use nix as a package manager on OSX ( and who knows, maybe WSL as well). As a happy nix-os user, maybe one of the reasons to learn home-manager will be in preparation for nix package management on those other platforms?

  2. I’ve read all the warnings/advice about letting home-manager control my user profile (there will be some work involved in turning all the old .bashrc and so forth into nix config source.) This work seems worth doing, as I hope to be dropping NixOS and my daily driver config onto various environments, in search of mastering nix’s philosophy and having a truly portable ‘workstation’. My presumption is… that’s a key practical difference between Users.users..packages and home-manager packages (the management of profile by home-manager). Is my presumption correct?

Thanks in advance.

1 Like

Yes and yes, though they’re kind of the same question. If you want your environment to be largely shared across nixos and non-nixos environments, then that’s definitely a reason to install most things through home-manager, rather than using the per-user nixos options.