Finally fixed hibernation

This commit is contained in:
Aleksandr Lebedev 2025-08-17 03:37:51 +02:00
parent 86eafdc904
commit 466cdb10b3
8 changed files with 20 additions and 418 deletions

View file

@ -28,8 +28,8 @@ in {
"mem_sleep_default=deep"
]
#https://github.com/nix-community/disko/issues/651#issuecomment-2383741717
++ optional (!config.boot.initrd.systemd.enable) "resume_offset=${builtins.toString cfg.swapFileOffset}";
inherit (cfg) resumeDevice;
++ optional (cfg.swapFileOffset != null) "resume_offset=${builtins.toString cfg.swapFileOffset}";
resumeDevice = mkDefault cfg.resumeDevice;
};
services.logind = {
lidSwitch = mkDefault "suspend-then-hibernate";

View file

@ -31,25 +31,25 @@ in {
description = "Watch for tablet mode changes";
serviceConfig = {
ExecStart = "${pkgs.writeShellScript "tablet-mode-eventd" ''
in_tablet_mode=$(${pkgs.coreutils}/bin/cat "${cfg.path}" 2>/dev/null || $(echo 0 > "${cfg.path}" && echo 0))
in_tablet_mode=$(${pkgs.coreutils}/bin/cat "${cfg.path}" 2>/dev/null || $(echo 0 > "${cfg.path}" && echo 0))
stdbuf -oL -eL ${lib.getExe pkgs.libinput} debug-events --device "${cfg.inputDevice}" | while read -r line; do
if [[ "$line" =~ switch\ tablet-mode\ state\ ([01]) ]]; then
d="''${BASH_REMATCH[1]}"
if [ "$d" -ne "$in_tablet_mode" ]; then
in_tablet_mode=$d
if [ "$d" -eq 1 ]; then
systemctl start tablet-on.target
echo "Tablet mode ON"
echo 1 > "${cfg.path}"
else
systemctl start tablet-off.target
echo "Tablet mode OFF"
echo 0 > "${cfg.path}"
fi
fi
fi
done
stdbuf -oL -eL ${lib.getExe pkgs.libinput} debug-events --device "${cfg.inputDevice}" | while read -r line; do
if [[ "$line" =~ switch\ tablet-mode\ state\ ([01]) ]]; then
d="''${BASH_REMATCH[1]}"
if [ "$d" -ne "$in_tablet_mode" ]; then
in_tablet_mode=$d
if [ "$d" -eq 1 ]; then
systemctl start tablet-on.target
echo "Tablet mode ON"
echo 1 > "${cfg.path}"
else
systemctl start tablet-off.target
echo "Tablet mode OFF"
echo 0 > "${cfg.path}"
fi
fi
fi
done
''}";
Restart = "always";
};