Install home-manager declaratively in /etc/nixos/configuration.nix?

Is there a way to install home-manager declaratively, ie just by editing /etc/nixos/configuration.nix?

Yes.

There is already a home-manager attribute, on top of that you can in theory modify NIX_PATH to a fetchFromGitHubed home-manager.

1 Like

So you just add home-manager to environment.systemPackages?

Why isn’t this the recommended install method? It seems more straightforward than the recommended one here: GitHub - nix-community/home-manager: Manage a user environment using Nix [maintainer=@rycee].

I just tried this out and it does sort of work. It def gets home-manager into $PATH. However, unlike the conventional install, I don’t get a default config file:

No configuration file found. Please create one at /home/asdf/.config/nixpkgs/home.nix

And I don’t know of a way with the CLI to init a default one.

I know that I could just manually create one, but what I’m really after is a way to do this all automatically somehow…

I think there’s no benefit of using the separate home-manager executable, especially since you can’t use nixos generations to revert back. You can source home-manager in configuration.nix, and update the whole system with nixos-rebuild.

Works all good on nixos (even +fish shell), but definitely struggling to get the macos machine working with fish.