Hibernation & battery-life optimization on Framework 13 (AMD) running NixOS
I was struggling somewhat with battery life when idle on my Framework 13 (AMD AI-300) running NixOS. Honestly the battery life wasn’t that bad, but it was very annoying that my laptop would randomly be dead after not using it for two days.
I didn’t find a clear guide for improving the battery life on NixOS, and trying to turn on things like deep-sleep:
boot.kernelParams = [ "mem_sleep_default=deep" ];
don’t work and actually break suspend.
Furthermore, from AMD systems using power-profiles-daemon is recommended, which doesn’t have much tweaking available, and thus no room for improvement.
All that can be done to improve is to enable hibernation.
I added this to my system config:
{ config, lib, pkgs, inputs, ... }: {
...
# Swap file setup
boot.initrd.systemd.enable = true;
swapDevices = [{
device = "/var/lib/swapfile";
size = 1024 * 16;
}];
...
systemd.sleep.extraConfig = ''
HibernateDelaySec=1h
SuspendState=mem
'';
}
Note here the HibernateDelaySec as this is the time-delay to start hibernation. The default value for this is 2h, and hibernation will kick in when either this time has past, or if battery drops to 5% or lower (docs).
We can now test if hibernation is working properly by running:
systemctl hibernate
Then to actually start using it automatically, I simply change out systemctl suspend with systemctl suspend-then-hibernate in my Hyprland keybinds:
# === Lock screen config ===
$screenLockCmd = noctalia-shell ipc call lockScreen lock
$suspendCmd = systemctl suspend-then-hibernate
$lockAndSuspendCmd = $screenLockCmd && $suspendCmd
bind = $mainMod, Z, exec, $lockAndSuspendCmd
And that’s it! I now can not use my laptop for a day or two, and still have enough charge to do whatever I needed.