Systemd's suspend-then-hibernate not working in NVIDIA Optimus laptop

I did this:

  1. created a unit in /usr/lib/systemd/system/nvidia-suspend-then-hibernate.service
[Unit]
Description=NVIDIA system suspend-then-hibernate actions
Before=systemd-suspend-then-hibernate.service

[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t suspend -s "nvidia-suspend-then-hibernate.service"
ExecStart=/usr/bin/nvidia-sleep.sh "hibernate"

[Install]
WantedBy=systemd-suspend-then-hibernate.service
  1. edit unit /usr/lib/systemd/system/nvidia-resume.service
[Unit]
Description=NVIDIA system resume actions
After=systemd-suspend.service
After=systemd-hibernate.service
After=systemd-suspend-then-hibernate.service

[Service]
Type=oneshot
ExecStart=/usr/bin/logger -t suspend -s "nvidia-resume.service"
ExecStart=/usr/bin/nvidia-sleep.sh "resume"

[Install]
WantedBy=systemd-suspend.service
WantedBy=systemd-hibernate.service
WantedBy=systemd-suspend-then-hibernate.service
  1. remove file /usr/lib/systemd/system-sleep/nvidia

#systemctl daemon-reload
#systemctl disable nvidia-resume.service
#systemctl enable nvidia-suspend.service
#systemctl enable nvidia-hibernate.service
#systemctl enable nvidia-suspend-then-hibernate.service
#systemctl enable nvidia-resume.service

for check

in /etc/systemd/sleep.conf set HibernateDelaySec=3min

warning, do not set the interval to less than 1 minute.

Command:

$systemctl suspend-then-hibernate

it works.

checked on debian 12 end gentoo systemd version 255 nvidia-drivers version 550.67