Nixos Rebuild Fails to switch if performed after resume from hibernate

Good Evening,

About a month ago, I changed the default sleep implementation on my laptop to “suspend-then-hibernate”, which has drastically improved my battery life. However, I’m now running into problems when running nixos-rebuild if I don’t run from a clean reboot.

The error is as follows:

restarting sysinit-reactivation.target
reloading the following units: firewall.service, reload-systemd-vconsole-setup.service
the following new units were started: run-credentials-systemd\x2dtmpfiles\x2dresetup.service.mount, sysinit-reactivation.target, systemd-tmpfiles-resetup.service
warning: the following units failed: systemd-hibernate-clear.service
× systemd-hibernate-clear.service - Clear Stale Hibernate Storage Info
     Loaded: loaded (/etc/systemd/system/systemd-hibernate-clear.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Thu 2024-11-07 23:26:06 GMT; 363ms ago
 Invocation: 53deb1c7f66146d394cec96b6c5687ce
       Docs: man:systemd-hibernate-clear.service(8)
    Process: 180870 ExecStart=/nix/store/xg6f0c5pchmc2jq84s4np19j1rnn90mn-systemd-256.6/lib/systemd/systemd-hibernate-resume --clear (code=exited, status=1/FAILURE)
   Main PID: 180870 (code=exited, status=1/FAILURE)
         IP: 0B in, 0B out
   Mem peak: 1.7M
        CPU: 6ms

Nov 07 23:26:06 UnknownDevice systemd[1]: Starting Clear Stale Hibernate Storage Info...
Nov 07 23:26:06 UnknownDevice systemd-hibernate-resume[180870]: Failed to get EFI variable HibernateLocation: Input/output error
Nov 07 23:26:06 UnknownDevice systemd[1]: systemd-hibernate-clear.service: Main process exited, code=exited, status=1/FAILURE
Nov 07 23:26:06 UnknownDevice systemd[1]: systemd-hibernate-clear.service: Failed with result 'exit-code'.
Nov 07 23:26:06 UnknownDevice systemd[1]: Failed to start Clear Stale Hibernate Storage Info.
warning: error(s) occurred while switching to the new configuration

It seems that the hibernation resume is not properly clearing the efi variables, which nixos-rebuild must check before switching. How can I fix this?

That’s a good one. Seems pretty weird!

Are you able to run efibootmgr -v after a resume?

These kernel docs might help: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-power
Maybe try /sys/power/pm_debug_messages.

Can you try manually running the hibernate-clear command with debug logging? sudo env SYSTEMD_LOG_LEVEL=debug /run/current-system/systemd/lib/systemd/systemd-hibernate-resume --clear

FWIW: It is switching, it’s just that it’s also trying to start this failed systemd unit as part of the switch, and that unit simply fails again.

1 Like