From 949e55fde99398cc234196f9e69a3239c6c306a6 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Wed, 24 Feb 2021 12:38:07 -0500 Subject: feat(gs/system): Add config for laptop battery hibernate on low battery, and when the power button is pressed Change-Id: I6560fc770ee5707e59fb2763614de2b8000e156e Reviewed-on: https://cl.tvl.fyi/c/depot/+/2550 Reviewed-by: glittershark Tested-by: BuildkiteCI --- users/glittershark/system/system/machines/chupacabra.nix | 2 +- users/glittershark/system/system/machines/yeren.nix | 2 +- users/glittershark/system/system/modules/laptop.nix | 13 +++++++++++++ .../glittershark/system/system/modules/reusable/battery.nix | 4 ++-- 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 users/glittershark/system/system/modules/laptop.nix (limited to 'users') diff --git a/users/glittershark/system/system/machines/chupacabra.nix b/users/glittershark/system/system/machines/chupacabra.nix index d2060f9ab3..4f7f39ee5a 100644 --- a/users/glittershark/system/system/machines/chupacabra.nix +++ b/users/glittershark/system/system/machines/chupacabra.nix @@ -3,7 +3,7 @@ { imports = [ ../modules/common.nix - ../modules/reusable/battery.nix + ../modules/laptop.nix ../modules/tvl.nix ../modules/fcitx.nix ../modules/rtlsdr.nix diff --git a/users/glittershark/system/system/machines/yeren.nix b/users/glittershark/system/system/machines/yeren.nix index 7e55f68d0f..29dde88bbe 100644 --- a/users/glittershark/system/system/machines/yeren.nix +++ b/users/glittershark/system/system/machines/yeren.nix @@ -4,7 +4,7 @@ imports = [ (modulesPath + "/installer/scan/not-detected.nix") ../modules/common.nix - ../modules/reusable/battery.nix + ../modules/laptop.nix ../modules/xserver.nix ../modules/fonts.nix ../modules/sound.nix diff --git a/users/glittershark/system/system/modules/laptop.nix b/users/glittershark/system/system/modules/laptop.nix new file mode 100644 index 0000000000..8c09f3a442 --- /dev/null +++ b/users/glittershark/system/system/modules/laptop.nix @@ -0,0 +1,13 @@ +{ config, lib, pkgs, ... }: + +{ + imports = [ + ./reusable/battery.nix + ]; + + laptop.onLowBattery.enable = true; + + services.logind.extraConfig = '' + HandlePowerKey=hibernate + ''; +} diff --git a/users/glittershark/system/system/modules/reusable/battery.nix b/users/glittershark/system/system/modules/reusable/battery.nix index d7043bf549..ca92e0c3f6 100644 --- a/users/glittershark/system/system/modules/reusable/battery.nix +++ b/users/glittershark/system/system/modules/reusable/battery.nix @@ -7,7 +7,7 @@ with lib; thresholdPercentage = mkOption { description = "Threshold battery percentage on which to perform the action"; - default = 5; + default = 8; type = types.int; }; @@ -26,7 +26,7 @@ with lib; ''SUBSYSTEM=="power_supply", '' ''ATTR{status}=="Discharging", '' ''ATTR{capacity}=="[0-${toString cfg.thresholdPercentage}]", '' - ''RUN+="/${pkgs.systemd}/bin/systemctl ${cfg.action}"'' + ''RUN+="${pkgs.systemd}/bin/systemctl ${cfg.action}"'' ]; }; } -- cgit 1.4.1