I used to be able to run systemctl hibernate, but since I upgraded to 22.11 (and run nixos-generate-config) hibernation won’t work anymore.
It gives this error: Failed to hibernate system via logind: Sleep verb "hibernate" not supported
I have a swap partition that is 16gb and a RAM that is 32gb. But it was working. So in case there is a new restriction, I added a swap file of 32gb:
@alvatar Ah, TIL that the kernel knows how to resume from swapfiles. You do have to use the resume_offset= kernel param though, and you have to set the boot.resumeDevice NixOS option to the device of the file system containing the swap file, or else NixOS will default to the first swap device you have configured that starts with /dev.
Ok, so it finally works. But I’m not sure what was it. I did change a bunch of things in my config, related to power management, like enabling powertop. But I think this is what did the trick:
On my laptop I’ve also recently upgraded NixOS from the previous installation of 20.09 to 22.11 and the hibernate function is broken now. However, I never saw the error message mentioned by @alvatar. My power button is configured to hibernate (via Gnome Settings) and I use it a lot. Now, after booting back up, I have to login and all programs are closed, just like after a shutdown. It’s the same with systemctl hibernate (with or without sudo). I also have a big swap partition, but I already had it before the re-installation. I followed the advice to set security.protectKernelImage = false, but without luck. In the logs the only relevant lines seems to be the following:
In case this doesn’t fix it for you, some other options will have added nohibernate to boot.kernelParams. You can figure out where by looking at the definitions of boot.kernelParams:
$ nix repl
Welcome to Nix 2.13.3. Type :? for help.
nix-repl> nixos = import <nixpkgs/nixos> {}
nix-repl> :p nixos.config.boot.kernelParams
[ "nohibernate" "loglevel=4" ]
nix-repl> :p nixos.options.boot.kernelParams.definitionsWithLocations
[ { file = "/etc/nixpkgs/nixos/modules/tasks/filesystems/zfs.nix"; value = [ "nohibernate" ]; } { file = "/etc/nixpkgs/nixos/modules/system/boot/systemd.nix"; value = [ ]; } { file = "/etc/nixpkgs/nixos/modules/system/boot/kernel.nix"; value = [ "loglevel=4" ]; } ]
This shows that the zfs.nix file adds the "nohibernate" option.