Stream: nix

Topic: per-host home-manager implementation.


view this post on Zulip Arul Agrawal (Apr 25 2024 at 07:32):

Hi, firstly, thanks for all the resources, I've got a nixos-flake based setup (essentially copied from srid/nixos-config) for my desktop and macbook.

I want to extend my flake to some servers and was reading about per-host configs here: https://github.com/srid/nixos-flake/issues/19, but didn't quite grasp the workaround mentioned in the last 2 comments. I want to avoid pulling-in the gui related home-manager configs for the servers obviously. (as an aside, some of my gui configs like for wayland are split across the nixos/ and home/ folders, is there a way to unify them?)

Has anyone got per-home config with a similar setup? here's my config for reference if needed: https://github.com/arulagrawal/nix.

view this post on Zulip Srid (Apr 25 2024 at 08:17):

@Arul Agrawal I suggest forking nixos-flake and modifying this writeShellApplication.

Make it so that it uses HOSTNAME instead of USER (but still fallback to USER if the former doesn't exist in homeConfigurations). You may first have to do a nix flake show --json on the flake, so as to see if homeConfigurations.$HOSTNAME does in fact exist.

Once you get something working to satisfaction, open a PR on nixos-flake repo!

Happy to help through your contribution here.

view this post on Zulip Arul Agrawal (Apr 25 2024 at 09:19):

so the idea is, instead of doing this, the home-manager config would instead be called in flake.nix under flake -> homeConfigurations (where the darwinConfigurations and nixosConfigurations currently reside)?

view this post on Zulip Srid (Apr 25 2024 at 09:21):

No, the idea is to fork nixos-flake and do the aforementioned change.

Then change this line in your flake to point to your fork, and run nix run.

view this post on Zulip Arul Agrawal (Apr 25 2024 at 09:27):

https://github.com/arulagrawal/nixos-flake/commit/2b8fc0f521db121d1f48d32e1cbc57732ede91a4

Something like this? (will cleanup the commit message)

I did this and pointed my flake to the branch and ran nix run. The question I asked now was to ask where to put the per-host config.

view this post on Zulip Srid (Apr 25 2024 at 09:31):

legacyPackages.homeConfigurations.HOSTNAME

See https://github.com/srid/nixos-flake/blob/7b19503e7f8c7cc0884fc2fbd669c0cc2e05aef5/examples/home/flake.nix#L25C11-L25C58

view this post on Zulip Srid (Apr 25 2024 at 09:31):

And run nix run .#activate-home

view this post on Zulip Srid (Apr 25 2024 at 09:32):

I'm assuming you are doing this in non-NixOS, since that issue is all about home-manager only config.

view this post on Zulip Srid (Apr 25 2024 at 09:32):

So, try to get this working on macOS first.

One little step at a time.

view this post on Zulip Srid (Apr 25 2024 at 09:33):

You can put the config in homeModules, and import if from two places (to as to share between nixos & macos)

view this post on Zulip Srid (Apr 25 2024 at 09:33):

Srid said:

You can put the config in homeModules, and import if from two places (to as to share between nixos & macos)

Example, https://github.com/srid/nixos-flake/blob/master/examples/both/flake.nix

view this post on Zulip Arul Agrawal (Apr 25 2024 at 10:10):

Okay I think I was going about this the wrong way (for what I need). I didn't test the server config yet (the device I was going to use died on me or smth) but I think something like this suffices: https://github.com/arulagrawal/nix/compare/main...separate-linux-configs

view this post on Zulip Arul Agrawal (Apr 25 2024 at 10:11):

apologies for the confusion

view this post on Zulip Pratham Patel (Apr 28 2024 at 17:27):

@Arul Agrawal this post prompted me to write #nix > Dynamic NixOS configuration, using flakes. Feel free to "take inspiration" from it ;)


Last updated: Nov 15 2024 at 13:04 UTC