Home Manager Hyprland monitor config nix for multiple hosts

Hello,

Technically, there are two issues. Not sure if I need to split these out.

Here is the hyprland nix config section:

{ inputs, config, lib, pkgs, modulesPath, homeManager, ... }:

{
  wayland.windowManager.hyprland = {
    enable = true;
    systemd.enable = true;
    settings = {
      env = [
        # Hint Electron apps to use Wayland
        "NIXOS_OZONE_WL,1"
        "XDG_CURRENT_DESKTOP,Hyprland"
        "XDG_SESSION_TYPE,wayland"
        "XDG_SESSION_DESKTOP,Hyprland"
        "QT_QPA_PLATFORM,wayland"
        "XDG_SCREENSHOTS_DIR,$HOME/screens"
      ];

      # if hostname = "bqnix"
      monitor = "DP-6,preferred,auto,auto";

      # if hostname = "tbnix"
      # monitor = "eDP-1,1920x1080@60,2560x0,1";
      # monitor = "DP-2,  2560x1440@60,0x0,1";

Issue #1: I would like to set up this nix file so that if the hostname = “bqnix”, use the first monitor config. If hostname = “tbnix”, use the commented out section.

I can probably take the easy way out and make duplicate files, one for “bqnix” and another for “tbnix”, but maybe there is a cleaner way to do this in line.

Issue #2: How do you specify multiple monitors in home manager hyprland config? If I comment out DP-6 monitor and uncomment eDP-1 and DP-2 I get this error:

       error: attribute 'monitor' already defined at /nix/store/z353hb367clnavz4hbzqfwhz28sqq3hg-source/modules/hyprland/main.nix:22:7
       at /nix/store/z353hb367clnavz4hbzqfwhz28sqq3hg-source/modules/hyprland/main.nix:23:7:
           22|       monitor = "eDP-1,1920x1080@60,2560x0,1";
           23|       monitor = "DP-2,  2560x1440@60,0x0,1";
             |       ^
           24|

Thanks!

my hyprland.nix like this

{ hostname, ... }:
{
~~~~
    monitor = 
      if ( hostname == "tbnix" )
      then [
       "eDP-1,1920x1080@60,2560x0,1"
       "DP-2, 2560x1440@60,0x0,1"
      ]
      else [
       "DP-6,preferred,auto,auto"
      ];
  }

Don’t use conditionals on hostname. Create separate main config files that each import some common config. Conditionals on hostname will become nightmarish quickly.

really?
i use flake and home-manager and include hostname in my flake’s specialArgs but without any issues

nixosConfigurations = {
    "foo" = nixpkgs.lib.nixosSystem {
        inherit system;
        modules = [./hosts/foo];
        specialArgs = {
          hostname = "foo";
          inherit self inputs username;
        };
      };
    "bar" = nixpkgs.lib.nixosSystem {
        inherit system;
        modules = [./hosts/bar];
        specialArgs = {
          hostname = "bar";
          inherit self inputs username;
        };
      };
    };

Imagine trying to juggle 17 different hosts and conditionals for each across all of your modules. You’ve already created separate files, just put the host specific config in those separate files?

i see. i’ll separate files by hostname, thanks.

Ok sounds like different files it is.

Also, for multiple monitors (issue #2) this is the config?:

monitor = [
       "eDP-1,1920x1080@60,2560x0,1"
       "DP-2, 2560x1440@60,0x0,1"
      ];

Thank you