Sleep with NVidia + Wayland not working

Heya, for the past while sleep/suspend/hibernate hasn’t been working on my laptop. This has been an issue with both GNOME Wayland and Hyprland. I have an Nvidia dGPU with an Intel iGPU.

  • ddf459d
    • nvidia.prime sync and offload are both disabled (though this appears to make no different as I’ve tested with sync enabled too)
    • nvidia.open = false
    • nvidia.modesettings.enable = true
    • nvidia.powerManagement.enable = true
    • nvidiaPackages.beta
    • boot.kernalParams = [ "nvidia.NVreg_PreserveVideoMemoryAllocations=1" "nvidia.NVreg_TemporaryFilePath=/var/temp" ]
    • sudo systemctl suspend turns off the laptop, however the internal monitor does not turn back on after waking and the external monitor gets into a buggy state. Restarting is the only fix.
    • sudo systemctl sleep
      • Peripherals turn off, on, off, then on
      • Laptop screen turns off, then on. No change to external monitor
      • journalctl -xe contains the following lines
Jul 04 12:14:39 dooshii kernel: NVRM: GPU 0000:01:00.0: PreserveVideoMemoryAllocations module parameter is set. System Power Management attempted without driver procfs suspend interface. Please refer to the 'Configuring Power Management Support' section in the driver README.
Jul 04 12:14:39 dooshii kernel: nvidia 0000:01:00.0: PM: pci_pm_suspend(): nv_pmops_suspend [nvidia] returns -5
Jul 04 12:14:39 dooshii kernel: nvidia 0000:01:00.0: PM: dpm_run_callback(): pci_pm_suspend returns -5
Jul 04 12:14:39 dooshii kernel: nvidia 0000:01:00.0: PM: failed to suspend async: error -5
Jul 04 12:14:39 dooshii kernel: PM: Some devices failed to suspend, or early wake event detected
Jul 04 12:14:39 dooshii kernel: spd5118 0-0050: PM: dpm_run_callback(): spd5118_resume [spd5118] returns -6
Jul 04 12:14:39 dooshii kernel: spd5118 0-0050: PM: failed to resume async: error -6
  • 5a86fc6
    • Same config as above except nvidia.powerManagement.enable = false and boot.kernalParams = [ "nvidia.NVreg_PreserveVideoMemoryAllocations=0" ]
    • sudo systemctl sleep and sudo systemctl suspend
      • Laptop turns off
      • When powering back on, it flashes with the pre-sleep state of the screen, then I am logged out, all apps are closed, and the external monitor is a gray screen after logging in.
      • journalctl -xe logs

My output of inxi -G (trimming out a couple camera devices)

Graphics:
  Device-1: Intel Raptor Lake-S UHD Graphics driver: i915 v: kernel
  Device-2: NVIDIA AD106M [GeForce RTX 4070 Max-Q / Mobile] driver: nvidia
    v: 575.64
  Display: wayland server: X.org v: 1.21.1.16 with: Xwayland v: 24.1.8
    compositor: Hyprland v: 0.49.0 driver: X: loaded: modesetting,nvidia
    gpu: i915,nvidia,nvidia-nvswitch resolution: 1: 1920x1080~120Hz
    2: 3840x2160~144Hz
  API: EGL v: 1.5 drivers: iris,swrast
    platforms: gbm,wayland,x11,surfaceless,device
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: nvidia mesa v: 575.64
    renderer: NVIDIA GeForce RTX 4070 Laptop GPU/PCIe/SSE2
  Info: Tools: api: eglinfo,glxinfo gpu: nvidia-settings,nvidia-smi
    wl: wlr-randr x11: xprop,xrandr

Thanks for any help

i regret buying an nvidia card for this thing

Have your first checked the forum? there are lot of posts on issues with Nvidia GPU’s and suspend
https://discourse.nixos.org/search?q=nvidia%20suspend

Enable that.

Try not using the beta branch. While the driver is infamous for its sleep breaking ways anyway, using beta drivers isn’t going to help. Just leave that unset.

The powermanagement flag does this for you if it’s needed. You should practically never touch the kernel args by hand on NixOS, since it breaks the module merging, use the provided high-level options.

From the error message, I would not be surprised if this actually breaks sleep. Try running without manually set kernel args, and without the powermanagement daemon.

This forces stuff into a memory-backed file system. I can imagine this royally screwing with sleep, since the nvidia powerdaemon is supposed to trigger during sleep init to dump the excess memory into the filesystem. If it dumps it into the memory-backed file system instead, and that is full because the GPU memory is larger than what the kernel will preserve during sleep, graphics glitches is what you’d expect.

You can read more about the power management daemon here, but again, use the high-level NixOS options, don’t try to manually implement this, at least not without reading the NixOS module in detail.

Yep. Situation has much improved compared to 5 years ago, though, at least.