Suspend then hibernate

Looking for a script/module/service that I can use to put nixos to first suspend and after a given time to hibernate.

Something along the lines of this nixos config should work

  # suspend to RAM (deep) rather than `s2idle`
  boot.kernelParams = [ "mem_sleep_default=deep" ];
  # suspend-then-hibernate
  systemd.sleep.extraConfig = ''

@ericgundrum Thanks buddy, but didnt work for me :sweat_smile:

This worked :grin::grin:: Suspend and then hibernate after 60 minutes · GitHub

Excellent! Thanks for posting a working solution. Probably I should test if my config really is doing what I intend. :slight_smile:

1 Like

@ericgundrum I will be interested to know more with regards to your solution as it’s more cleaner. Might be an issue with my config. Let me know if it’s working on your side :smile:

This is all the code my desktop needs to hibernate:

boot.kernelParams = [
  "resume=LABEL=BTRFS_ROOT" # findmnt -o LABEL --noheadings /swap/
  "resume_offset=36709632" # btrfs inspect-internal map-swapfile -r /swap/swapfile
systemd.sleep.extraConfig = ''
  HibernateDelaySec=30s # very low value to test suspend-then-hibernate
  SuspendState=mem # suspend2idle is buggy :(

I tested suspend-then-hibernate and hybrid-sleep, both work:

systemctl hybrid-sleep
systemctl suspend-then-hibernate

I have a swapfile inside an encrypted btrfs subvolume, I don’t think my chances could be any worse, yet things seem to just work fine :person_shrugging:

1 Like

@lelgenio In that case there might be a specific issue with my setup. Will try again and see what happens.