Immediate resume after suspend

After running a nixos-rebuild from kernel 7.0.2 → 7.0.5, my computer no longer stays asleep when suspending. Rolling back to my previous 7.0.2 generation fixes the sleep issue, but not moving to 6.12.x, 6.18.33, or 7.0.10 (I had issues attempting to pin to 7.0.2).

Current system information:

NixOS 26.05
Kernel 6.18.33
Nvidia graphics (open driver 595)
Gigabyte X570 motherboard

Relevant system logs:

May 31 21:00:43 kernel: PM: suspend exit
May 31 21:00:42 kernel: random: crng reseeded on system resumption
May 31 21:00:42 kernel: efivarfs: finished resyncing variable state
May 31 21:00:42 kernel: efivarfs: resyncing variable state
May 31 21:00:42 kernel: Restarting tasks: Done
May 31 21:00:42 kernel: Restarting tasks: Starting
May 31 21:00:42 kernel: OOM killer enabled.
May 31 21:00:42 kernel: usb 6-2.1: reset SuperSpeed USB device number 5 using xhci_hcd
May 31 21:00:42 kernel: usb 5-2.3.3: reset full-speed USB device number 10 using xhci_hcd
May 31 21:00:42 kernel: usb 5-2.3.5: reset high-speed USB device number 11 using xhci_hcd
May 31 21:00:42 kernel: usb 5-2.3.1: reset full-speed USB device number 8 using xhci_hcd
May 31 21:00:42 kernel: usb 5-2.3.2: reset full-speed USB device number 9 using xhci_hcd
May 31 21:00:42 kernel: usb 6-2: reset SuperSpeed USB device number 4 using xhci_hcd
May 31 21:00:42 kernel: ata10.00: Entering active power mode
May 31 21:00:42 kernel: ata10.00: configured for UDMA/133
May 31 21:00:42 kernel: ata4.00: Entering active power mode
May 31 21:00:42 kernel: ata4.00: configured for UDMA/133
May 31 21:00:42 kernel: sd 9:0:0:0: [sdd] Starting disk
May 31 21:00:42 kernel: sd 3:0:0:0: [sdb] Starting disk
May 31 21:00:42 kernel: ata3.00: configured for UDMA/133
May 31 21:00:42 kernel: sd 2:0:0:0: [sda] Starting disk
May 31 21:00:42 kernel: ata9.00: configured for UDMA/133
May 31 21:00:42 kernel: ata5.00: Entering active power mode
May 31 21:00:42 kernel: ata5.00: configured for UDMA/133
May 31 21:00:42 kernel: sd 4:0:0:0: [sdc] Starting disk
May 31 21:00:42 kernel: ata9: SATA link up 1.5 Gbps (SStatus 113 SControl 300)
May 31 21:00:42 kernel: ata4: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
May 31 21:00:42 kernel: ata5: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
May 31 21:00:42 kernel: ata10: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
May 31 21:00:42 kernel: ata3: SATA link up 6.0 Gbps (SStatus 133 SControl 300)
May 31 21:00:42 kernel: usb 5-2.3: reset high-speed USB device number 6 using xhci_hcd
May 31 21:00:42 kernel: ata6: SATA link down (SStatus 0 SControl 300)
May 31 21:00:42 kernel: nvme nvme0: 12/0/0 default/read/poll queues
May 31 21:00:42 kernel: nvme nvme0: D3 entry latency set to 10 seconds
May 31 21:00:42 kernel: ACPI: PM: Waking up from system sleep state S3
May 31 21:00:42 kernel: Non-boot CPUs are not disabled
May 31 21:00:42 kernel: Wakeup pending. Abort CPU freeze
May 31 21:00:42 kernel: Disabling non-boot CPUs ...
May 31 21:00:42 kernel: ACPI: PM: Saving platform NVS memory
May 31 21:00:42 kernel: ACPI: PM: Preparing to enter system sleep state S3
May 31 21:00:42 kernel: ata10.00: Entering standby power mode
May 31 21:00:42 kernel: ata4.00: Entering standby power mode
May 31 21:00:42 kernel: ata5.00: Entering standby power mode
May 31 21:00:42 kernel: sd 9:0:0:0: [sdd] Synchronizing SCSI cache
May 31 21:00:42 kernel: sd 2:0:0:0: [sda] Synchronizing SCSI cache
May 31 21:00:42 kernel: sd 3:0:0:0: [sdb] Synchronizing SCSI cache
May 31 21:00:42 kernel: sd 4:0:0:0: [sdc] Synchronizing SCSI cache
May 31 21:00:42 kernel: printk: Suspending console(s) (use no_console_suspend to debug)
May 31 21:00:42 kernel: Freezing remaining freezable tasks completed (elapsed 0.000 seconds)
May 31 21:00:42 kernel: Freezing remaining freezable tasks
May 31 21:00:42 kernel: OOM killer disabled.
May 31 21:00:42 kernel: Freezing user space processes completed (elapsed 0.001 seconds)
May 31 21:00:42 kernel: Freezing user space processes
May 31 21:00:37 kernel: Filesystems sync: 0.014 seconds
May 31 21:00:37 kernel: PM: suspend entry (deep)
May 31 21:00:37 systemd-sleep[19289]: Performing sleep operation 'suspend'...
May 31 21:00:37 systemd[1]: user@1000.service: Unit now frozen-by-parent.
May 31 21:00:37 systemd[1]: user-1000.slice: Unit now frozen-by-parent.
May 31 21:00:37 systemd-sleep[19289]: Successfully froze unit 'user.slice'.
May 31 21:00:37 systemd[1]: user.slice: Unit now frozen.
May 31 21:00:37 systemd[1]: user-175.slice: Unit now frozen-by-parent.
May 31 21:00:37 systemd[1]: session-2.scope: Unit now frozen-by-parent.
May 31 21:00:37 systemd[1]: Starting System Suspend...
May 31 21:00:37 systemd[1]: Reached target Sleep.
May 31 21:00:37 systemd[1]: Finished Sleep Actions.
May 31 21:00:37 systemd[1]: Starting Sleep Actions...

Have a look at this section of the arch wiki, it covers figuring out the cause.

The section right after also has workarounds for specific hardware, but I imagine most of those are very outdated and won’t apply to this instance.

Thanks for the reply! After taking a closer look at the wiki and adding this to my configuration.nix:

  services.udev.extraRules = ''
    ACTION=="add", SUBSYSTEM=="pci", DRIVER=="pcieport", ATTR{power/wakeup}="disabled"
  '';

I still had XHC0 and PS2K enabled in /proc/acpi/wakeup and I was getting

$ sudo dmidecode -t system | grep -P '\tWake-up Type\: '
        Wake-up Type: PCI PME#

After disabling XHC0 with the recommended command (echo XHC0 > /proc/acpi/wakeup), sleep worked again!

The problem is, after removing the extra udev rules and restarting, XHC0 is enabled again, but sleep is still working. So I have no idea why that worked, but at least I have something working!