dotfiles/modules/nixos/hardware/sleep.nix

30 lines
870 B
Nix
Raw Normal View History

2022-12-21 21:18:03 +00:00
{ config, pkgs, lib, ... }: {
2022-12-21 21:18:03 +00:00
config = lib.mkIf (config.physical && pkgs.stdenv.isLinux) {
# Prevent wake from keyboard
powerManagement.powerDownCommands = ''
2023-04-02 00:21:26 +00:00
set +e
2023-02-23 04:46:24 +00:00
2023-04-02 00:21:26 +00:00
for power in /sys/bus/i2c/devices/i2c-*/device/power; do echo disabled > ''${power}/wakeup || true; done
2023-04-02 12:22:28 +00:00
for power in /sys/bus/usb/devices/1-*/power; do echo disabled > ''${power}/wakeup || true; done
2023-04-02 00:21:26 +00:00
# Fix for Gigabyte motherboard
# /r/archlinux/comments/y7b97e/my_computer_wakes_up_immediately_after_i_suspend/isu99sr/
echo GPP0 > /proc/acpi/wakeup
2022-12-21 21:18:03 +00:00
2023-04-15 14:11:30 +00:00
# Possibly need to wait a beat for settings to kick in
sleep 2
2023-04-02 00:21:26 +00:00
set -e
'';
2023-02-23 04:46:24 +00:00
2023-04-02 12:22:28 +00:00
services.udev.extraRules = ''
ACTION=="add", SUBSYSTEM=="usb", DRIVER=="usb", ATTR{power/wakeup}="disabled"
ACTION=="add", SUBSYSTEM=="i2c", ATTR{power/wakeup}="disabled"
'';
2022-12-21 21:18:03 +00:00
};
}