Dualmonitor setup with Nvidia & Intel HELP

Hello, I’m new to NixOS, I’m using i3 and I don’t get both monitors to run at the same time.
One monitor is connected to the Intel GPU and the other one directly to my Nvidia GPU.
If I only install either Nvidia or Intel drivers, only one monitor works.
Usually I would just install both drivers and both monitors would work from my experience, but when I do so, no monitor works anymore and I just get a black screen.
I set up Prime, I configured X11 and I’m out of ideas.
Does anyone have an idea?
I’m thankful for any help.

My configuration.nix:

{ config, pkgs, lib, ... }:

let
  isNvidia = true;
  isIntel = true;
  enablePrime = true;
in

{
  imports =
    [
      ./hardware-configuration.nix
    ];


  ##### Driver #####

  services.xserver.videoDrivers = []
  ++ lib.optional isNvidia "nvidia"
  ++ lib.optional isIntel "modesetting";

  # Intel
  hardware.graphics = {
    enable = isIntel;
    extraPackages = with pkgs; [
      vpl-gpu-rt
    ];
  };

  # Nvidia
  hardware.nvidia = if isNvidia then {
    modesetting.enable = true;
    powerManagement = {
      enable = true;
      finegrained = false;
    };
    open = false;
    nvidiaSettings = true;
    package = config.boot.kernelPackages.nvidiaPackages.stable;

    # Prime
    prime = if enablePrime then {
      # Sync
      sync.enable = false;

      # Offload
      offload.enable = true;
      offload.enableOffloadCmd = true;

      # Tip: sudo lshw -c display
      intelBusId = "PCI:0@0:2:0";
      nvidiaBusId = "PCI:1@0:0:0";
      # amdgpuBusId = "PCI:0:0:0";
    } else {};
  } else {};

  hardware.nvidia-container-toolkit.enable = isNvidia;

...

  services.xserver = {
    enable = true;
    desktopManager = {
      xterm.enable = false;
    };
    displayManager = {
      lightdm.enable = true;
      defaultSession = "none+i3";
    };
    windowManager.i3 = {
      enable = true;
      extraPackages = with pkgs; [
        dmenu
        i3status
        i3lock
        i3blocks
      ];
      package = pkgs.i3-gaps;
    };
    xkb = {
      layout = "us";
      variant = "";
    };
  };

My xorg.conf:

Section "ServerLayout"
	Identifier     "Main Layout"
	Screen       0 "Screen0" Absolute 0
	Screen       1 "Screen1" LeftOf "Screen0"
	InputDevice    "Mouse0" "CorePointer"
	InputDevice    "Keyboard0" "CoreKeyboard"
EndSection

Section "Files"
	ModulePath   "/nix/store/sgzwfb9k14myjfdxmz7zg6wqhb7mi0d9-xorg-server-21.1.14/lib/xorg/modules"
	FontPath     ""
EndSection

Section "Module"
	Load  "nvidia"
	Load  "glx"
EndSection

Section "InputDevice"
	Identifier  "Keyboard0"
	Driver      "kbd"
EndSection

Section "InputDevice"
	Identifier  "Mouse0"
	Driver      "mouse"
	Option	    "Protocol" "auto"
	Option	    "Device" "/dev/input/mice"
	Option	    "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
	Identifier   "DP-1"
	VendorName   "Vendor"
	ModelName    "Model"
	Option       "Primary" "true"
	Option       "PreferredMode" "2560x1440"
	Option       "Postion" "1920 0"
	Option 	     "RightOf" "HDMI-0"
EndSection

Section "Monitor"
	Identifier   "HDMI-0"
	VendorName   "Vendor"
	ModelName    "Model"
	Option       "PreferredMode" "1920x1080"
EndSection

Section "Device"
	Option	    "PrimaryGPU" "true"
	Identifier  "Card0"
	Driver      "modesetting"
	BusID       "PCI:0@0:2:0"
EndSection

Section "Device"
	Identifier  "Card1"
	Driver      "nvidia"
	BusID       "PCI:1@0:0:0"
EndSection

Section "Screen"
	Identifier "Screen1"
	Device     "Card1"
	Monitor    "HDMI-1"
	Depth      32
	Mode       "1920x1080"
EndSection

Section "Screen"
	Identifier "Screen0"
	Device     "Card0"
	Monitor    "DP-1"
	Depth 	   32
	Mode       "2560x1440"
EndSection

You’ll most likely need a prime setup on this device if you’re running into this problem. This is usually the case when each GPU is physically connected to one of the ports and they exchange data through a mux, instead of having them render into a shared memory space (though on some devices you might be able to switch to a different mode in BIOS; check BIOS either way, it’s quite possible you’ve put your laptop in a one-or-the-other mode somehow).

I have a couple of notes:

For a prime setup you explicitly do not want the modesetting driver in there.

This is useless without also adding intel-media-driver or intel-vaapi-driver (not both, the former is the one for newer GPUs), it’s just a shared library for those two packages.

The open driver is the one suggested by nvidia, you should be setting this to true unless you have some very special requirement.


If any of that helps in this case, it might be removing the modesetting driver. If not, it would be helpful to see logs from a boot in which the screens didn’t turn on. You can get that conveniently after booting back into a working generation with journalctl --boot -1.

Thanks, removing modesetting really did the trick.

1 Like