Unable to start X after update to 25.05, nvidia open drivers

Hi, so I use Hyprland, and I just did a system update, and noticed that apps using Xwayland would not start. Investigating further, they were all seemingly crashing because $DISPLAY was not set. Could not figure out why this was, so I tried rebuilding with an X wm (budgie) to see if I could start it and startx failed with the following error:

[   687.111] (EE) modeset(0): Failed to create pixmap
[   687.111] (EE) 
Fatal server error:
[   687.111] (EE) failed to create screen resources(EE)

I have scoured the internet and cannot find out what the root cause of this is. Here is the last working config I started with:

    hardware.graphics = { # Changed from hardware.opengl
      enable = true;
      enable32Bit = true;
    };

    nixpkgs.config.cudaSupport = true;
    nixpkgs.config.rocmSupport = true;

    services.xserver.videoDrivers = [ "nvidia" ];

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

    environment.variables = {
      "__GLX_VENDOR_LIBRARY_NAME" = "nvidia";
    };

And here is the current state of my nvidia module:

    hardware.graphics = {
      enable = true;
      enable32Bit = true;
    };

    nixpkgs.config.cudaSupport = true;
    nixpkgs.config.rocmSupport = true;

    services.xserver.videoDrivers = [ "nvidia" ];

    hardware.nvidia = {
      package = config.boot.kernelPackages.nvidiaPackages.mkDriver {
        version = "565.77";
        sha256_64bit = "sha256-CnqnQsRrzzTXZpgkAtF7PbH9s7wbiTRNcM0SPByzFHw=";
        sha256_aarch64 = lib.fakeHash;
        openSha256 = "sha256-Fxo0t61KQDs71YA8u7arY+503wkAc1foaa51vi2Pl5I=";
        settingsSha256 = "sha256-VUetj3LlOSz/LB+DDfMCN34uA4bNTTpjDrb6C6Iwukk=";
        persistencedSha256 = lib.fakeHash;
      };

      modesetting.enable = true;
      powerManagement.enable = true;
      # powerManagement.enable = false;
      # powerManagement.finegrained = false;
      open = true;
      nvidiaSettings = true;
    };

    boot = {
      kernelPackages = lib.mkForce pkgs.linuxKernel.packages.linux_xanmod;

      extraModprobeConfig = "options nvidia " + lib.concatStringsSep " " [
        # nvidia assume that by default your CPU does not support PAT,
        # but this is effectively never the case in 2023
        "NVreg_UsePageAttributeTable=1"
        # This is sometimes needed for ddc/ci support, see
        # https://www.ddcutil.com/nvidia/
        #
        # Current monitor does not support it, but this is useful for
        # the future
        "NVreg_RegistryDwords=RMUseSwI2c=0x01;RMI2cSpeed=100"
      ];
    };

    environment.variables = {
      # Required to run the correct GBM backend for nvidia GPUs on wayland
      "GBM_BACKEND" = "nvidia-drm";
      "__GLX_VENDOR_LIBRARY_NAME" = "nvidia";
    };

Which I got from here, as at this point I’m just trying anything to see if it makes any difference. Other options I have tried:

  • open = false; and open = true;
  • package = config.boot.kernelPackages.nvidiaPackages with .stable, .beta and .production

The one thing I have not tried is services.xserver.videoDrivers = [ "modesetting" ]; as none of the other threads on things that seemed similar to this suggested it for Nvidia, only for intel & amd, and when I look through the Xorg log, the error mentions modeset, and earlier it attempts to find drivers and settles on modesetting anyways, which I’d assume is from hardware.nvidia.modesetting.enable but I’m not totally sure.

Help is appreciated, thank you!

EDIT: Forgot to mention an important detail, I do not have an integrated GPU and don’t have any of the prime stuff enabled.

I had the exact same error as you. In my case, I was using Hyprland with greetd and tried installing xfce4 and starting it via startxfce4 gave me the exact same Xorg errors as you had.

After some thinking about this, I tried enabling startx as option, rather than just installing the xorg.xinit package. And voila, it worked. This makes sense as enabling an option in NixOS does some extra stuff, like in this case creating a couple of Xorg configuration, instead of just installing a binary and its libraries.

The correct option to use (in NixOS 24.11) is

services.xserver.displayManager.startx.enable = true;