Home-manager config per machine context

I’m using home-manager home.nix with the boilerplate flake.nix and I want to manage a single home-manager repo across machines (work, home, servers etc). If I break my home.nix into modular files, is there a way that home-manager can detect which host I’m on and import the appropriate home-work.nix or home-person.nix file?

I’m assuming flakes could do it but I’m not sure how the flake.lock file would work.

This is how I do it: dotfiles/flake.nix at 3bf0fea960f8c565b4d36e3e24a313e9b11fc8eb · TLATER/dotfiles · GitHub

There’s a lot of indirection there to save me some boilerplate, you don’t have to over-engineer things to that extent, so don’t be intimidated. If you need help understanding I’d be happy to explain, but the main point is using homeConfigurations.

The docs for that are here: Home Manager Manual. They don’t contain this note, though, which allows some automatic hostname resolution things: home-manager: Add --flake option to home-manager by ant-arctica · Pull Request #1856 · nix-community/home-manager · GitHub

Maybe I should figure out the details of that and fix up the docs.

1 Like

The way I do this in my flake is to check in host-specific and host-independent locations for home-manager configuration (see mkUser).

1 Like

Thanks @TLATER and @reckenrode from your replies. I did end up getting a workable solution from your ideas. I have the flake decide what to do based on the user

1 Like