Is it possible to hibernate with swap-file?

Hello everyone,

One one of my nixos installation I’m using swapfile and noticed that hibernation never works.
I made sure that resume=/var/swap-file and resume_offset=myoffset are present in my kernel boot args.
I did calculate resume_offset using filefrag -v /var/swapfile | awk '{if($1=="0:"){print $4}}' as per information that i found on arch wiki Power management/Suspend and hibernate - ArchWiki.

I also noticed that in init script following lines:

# Clear the resume device.
if test -n "$resumeDevice"; then
    mkswap "$resumeDevice" || echo 'Failed to clear saved image.'

Does this mean that swap device will be always flushed?

Here is relevant part of my configuration:

  boot.kernelParams = [  "resume=/var/swapfile" "resume_offset=450560" ];
  swapDevices = [ { device = "/var/swapfile"; size = 32768; } ];
  boot.resumeDevice = "/var/swapfile";

I’m currently using nixos-unstable channel with 5.0+ kernel version.

Any information would help me understand what is going on better.

Thank you very much in advance!


Ok, this was a problem on my end.

boot.resumeDevice = "/dev/mapper/myroot";

Is the correct option, no need for resume=/var/swapfile in boot.kernelParams also.
resumeDevice should be pointing at partition that swap file resides on.

More info can be found here: