Suspend-then-hibernate not working with Nvidia card

My Zephyrus GA401 laptop cannot suspend-then-hibernate. Using journalctl, I have pinpointed the issue to Nvidia card not calling the nvidia.suspend etc. scripts. This issue doesn’t occur when using systemctl suspend or systemctl hibernate. It is only relevant to suspend-then-hibernate.

I have found this nvidia forum post, which seems to be covering the issue somewhat. The question is, how can I change the systemd files in Nix to accommodate the fix? I am new to NixOS, and I can’t find a way to do this.

Relevant dmesg

[ 4466.412106] PM: suspend entry (s2idle)
[ 4466.428808] Filesystems sync: 0.016 seconds
[ 4466.585470] Freezing user space processes
[ 4466.587146] Freezing user space processes completed (elapsed 0.001 seconds)
[ 4466.587153] OOM killer disabled.
[ 4466.587156] Freezing remaining freezable tasks
[ 4466.588663] Freezing remaining freezable tasks completed (elapsed 0.001 seconds)
[ 4466.588673] printk: Suspending console(s) (use no_console_suspend to debug)
[ 4466.617900] 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.
[ 4466.617907] nvidia 0000:01:00.0: PM: pci_pm_suspend(): nv_pmops_suspend+0x0/0x30 [nvidia] returns -5
[ 4466.618280] nvidia 0000:01:00.0: PM: dpm_run_callback(): pci_pm_suspend+0x0/0x160 returns -5
[ 4466.618291] nvidia 0000:01:00.0: PM: failed to suspend async: error -5
[ 4467.065790] PM: Some devices failed to suspend, or early wake event detected
[ 4467.067520] [drm] PCIE GART of 1024M enabled.
[ 4467.067525] [drm] PTB located at 0x000000F41FC00000
[ 4467.067557] amdgpu 0000:04:00.0: amdgpu: SMU is resuming...
[ 4467.068033] amdgpu 0000:04:00.0: amdgpu: dpm has been disabled
[ 4467.069024] amdgpu 0000:04:00.0: amdgpu: SMU is resumed successfully!
[ 4467.079157] nvme nvme0: Shutdown timeout set to 10 seconds
[ 4467.083584] nvme nvme0: 16/0/0 default/read/poll queues
[ 4467.274457] [drm] VCN decode and encode initialized successfully(under DPG Mode).
[ 4467.274887] [drm] JPEG decode initialized successfully.
[ 4467.274895] amdgpu 0000:04:00.0: amdgpu: ring gfx uses VM inv eng 0 on hub 0
[ 4467.274900] amdgpu 0000:04:00.0: amdgpu: ring gfx_low uses VM inv eng 1 on hub 0
[ 4467.274903] amdgpu 0000:04:00.0: amdgpu: ring gfx_high uses VM inv eng 4 on hub 0
[ 4467.274905] amdgpu 0000:04:00.0: amdgpu: ring comp_1.0.0 uses VM inv eng 5 on hub 0
[ 4467.274908] amdgpu 0000:04:00.0: amdgpu: ring comp_1.1.0 uses VM inv eng 6 on hub 0
[ 4467.274910] amdgpu 0000:04:00.0: amdgpu: ring comp_1.2.0 uses VM inv eng 7 on hub 0
[ 4467.274912] amdgpu 0000:04:00.0: amdgpu: ring comp_1.3.0 uses VM inv eng 8 on hub 0
[ 4467.274914] amdgpu 0000:04:00.0: amdgpu: ring comp_1.0.1 uses VM inv eng 9 on hub 0
[ 4467.274916] amdgpu 0000:04:00.0: amdgpu: ring comp_1.1.1 uses VM inv eng 10 on hub 0
[ 4467.274918] amdgpu 0000:04:00.0: amdgpu: ring comp_1.2.1 uses VM inv eng 11 on hub 0
[ 4467.274920] amdgpu 0000:04:00.0: amdgpu: ring comp_1.3.1 uses VM inv eng 12 on hub 0
[ 4467.274922] amdgpu 0000:04:00.0: amdgpu: ring kiq_0.2.1.0 uses VM inv eng 13 on hub 0
[ 4467.274924] amdgpu 0000:04:00.0: amdgpu: ring sdma0 uses VM inv eng 0 on hub 8
[ 4467.274926] amdgpu 0000:04:00.0: amdgpu: ring vcn_dec uses VM inv eng 1 on hub 8
[ 4467.274928] amdgpu 0000:04:00.0: amdgpu: ring vcn_enc0 uses VM inv eng 4 on hub 8
[ 4467.274930] amdgpu 0000:04:00.0: amdgpu: ring vcn_enc1 uses VM inv eng 5 on hub 8
[ 4467.274932] amdgpu 0000:04:00.0: amdgpu: ring jpeg_dec uses VM inv eng 6 on hub 8
[ 4467.311674] OOM killer enabled.
[ 4467.311678] Restarting tasks ... done.
[ 4467.315327] random: crng reseeded on system resumption
[ 4467.332658] PM: suspend exit

I’d be grateful for any advice.

More then welcome to browse through and grabb some ideas. I have zero issues with nvidia suspending for days on end and wakes without an issue.

https://github.com/tolgaerok/nixos-kde/blob/0a3541eb07c183a8c1979e024abe3bebcbfd8fe2/core%2Fgpu%2Fnvidia%2Fnvidia-stable-opengl%2Fdefault.nix

Thank you, I’ll look through it.

The problem, however, isn’t suspending or hibernating. Both of these options work well. The issue pops up, when I try to use suspend-then-hibernate only.