Nvidia Drivers - Failed to start X11 Server

Nvidia Drivers - Failed to start X11 Server

I’m attempting to install nvidia drivers by following the wiki entry here.

I’ve used the exact configuration from the wiki:

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

{

  # Make sure opengl is enabled
  hardware.opengl = {
    enable = true;
    driSupport = true;
    driSupport32Bit = true;
  };

  # Tell Xorg to use the nvidia driver (also valid for Wayland)
  services.xserver.videoDrivers = [ "nvidia" ];

  hardware.nvidia = {

    # Modesetting is needed for most Wayland compositors
    modesetting.enable = true;

    # Use the open source version of the kernel module
    # Only available on driver 515.43.04+
    open = false;

    # Enable the nvidia settings menu
    nvidiaSettings = true;

    # Optionally, you may need to select the appropriate driver version for your specific GPU.
    package = config.boot.kernelPackages.nvidiaPackages.stable;
  };
}

On 23.05 I get this on startup:

On unstable I get this on startup:

In journalctl I can see this:

Jul 24 23:59:45 will-desktop systemd-modules-load[64959]: Failed to find module 'nvidia-uvm'
Jul 24 23:59:45 will-desktop systemd-modules-load[64959]: Failed to find module 'nvidia'
Jul 24 23:59:45 will-desktop systemd-modules-load[64959]: Failed to find module 'nvidia_modeset'
Jul 24 23:59:45 will-desktop systemd-modules-load[64959]: Failed to find module 'nvidia_drm'

Previously I was on Fedora and had the proprietary drivers installed and they worked fine.

The GPU I’m using (from lspci):

09:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1070] (rev a1)

The monitors were set incorrectly with xrandr, because the nvidia drivers change the id’s of your monitors. I was using the wrong id’s in my configuration here:

  # Setup displays
  services.xserver.displayManager.setupCommands =
    let
      monitor-center = "DP-2";
      monitor-left = "DP-3";
    in
    ''
      ${pkgs.xorg.xrandr}/bin/xrandr --output ${monitor-center} --primary --mode 1920x1080 --rate 144.00 --rotate normal --output ${monitor-left} --mode 1920x1080 --rate 144.00 --rotate right --left-of ${monitor-center}
    '';