Hibernation? + battery widget fix for framework 12
This commit is contained in:
parent
cc32b7c14f
commit
873a9c562b
4 changed files with 47 additions and 13 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
{ device ? throw "Set this to your disk device, e.g. /dev/sda", ... }:
|
{device ? throw "Set this to your disk device, e.g. /dev/sda", ...}:
|
||||||
# IMPORTANT
|
# IMPORTANT
|
||||||
# Calculate offset using https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Acquire_swap_file_offset
|
# Calculate offset using https://wiki.archlinux.org/title/Power_management/Suspend_and_hibernate#Acquire_swap_file_offset
|
||||||
# AND create this config
|
# AND create this config
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
# resumeDevice = "/dev/disk/by-label/nixos";
|
# resumeDevice = "/dev/disk/by-label/nixos";
|
||||||
# };
|
# };
|
||||||
#}
|
#}
|
||||||
|
|
||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,12 @@
|
||||||
battery-path = "/sys/class/power_supply/${
|
battery-path = "/sys/class/power_supply/${
|
||||||
if hwconfig.hostname == "kylekrein-mac"
|
if hwconfig.hostname == "kylekrein-mac"
|
||||||
then "macsmc-battery"
|
then "macsmc-battery"
|
||||||
else "BAT0"
|
else
|
||||||
|
(
|
||||||
|
if hwconfig.hostname == "kylekrein-framework12"
|
||||||
|
then "BAT1"
|
||||||
|
else "BAT0"
|
||||||
|
)
|
||||||
}";
|
}";
|
||||||
get-battery-level = "${pkgs.writeShellScriptBin "get-battery-level" ''
|
get-battery-level = "${pkgs.writeShellScriptBin "get-battery-level" ''
|
||||||
cat ${battery-path}/capacity 2>/dev/null || echo "N/A"
|
cat ${battery-path}/capacity 2>/dev/null || echo "N/A"
|
||||||
|
|
@ -60,11 +65,27 @@
|
||||||
echo "$ICON"
|
echo "$ICON"
|
||||||
''}/bin/get-icon";
|
''}/bin/get-icon";
|
||||||
get-remaining-time = "${pkgs.writeShellScriptBin "get-remaining-time" ''
|
get-remaining-time = "${pkgs.writeShellScriptBin "get-remaining-time" ''
|
||||||
REMAINING_ENERGY=$(cat ${battery-path}/energy_now)
|
REMAINING_ENERGY=$(cat ${battery-path}/${
|
||||||
POWER_USAGE=$(cat ${battery-path}/power_now)
|
if hwconfig == "kylekrein-mac"
|
||||||
|
then "energy_now"
|
||||||
|
else "charge_now"
|
||||||
|
})
|
||||||
|
POWER_USAGE=$(cat ${battery-path}/${
|
||||||
|
if hwconfig.hostname == "kylekrein-mac"
|
||||||
|
then "power_now"
|
||||||
|
else "current_now"
|
||||||
|
})
|
||||||
if [[ -n "$REMAINING_ENERGY" && -n "$POWER_USAGE" && "$POWER_USAGE" -ne 0 ]]; then
|
if [[ -n "$REMAINING_ENERGY" && -n "$POWER_USAGE" && "$POWER_USAGE" -ne 0 ]]; then
|
||||||
TIME_LEFT=$((0 - (REMAINING_ENERGY / POWER_USAGE)))
|
TIME_LEFT=$((${
|
||||||
MINUTES_LEFT=$(((0 - ( (REMAINING_ENERGY * 60) / POWER_USAGE )) - (TIME_LEFT * 60)))
|
if hwconfig.hostname == "kylekrein-mac"
|
||||||
|
then "0 - "
|
||||||
|
else ""
|
||||||
|
}(REMAINING_ENERGY / POWER_USAGE)))
|
||||||
|
MINUTES_LEFT=$(((${
|
||||||
|
if hwconfig.hostname == "kylekrein-mac"
|
||||||
|
then "0 - "
|
||||||
|
else ""
|
||||||
|
}( (REMAINING_ENERGY * 60) / POWER_USAGE )) - (TIME_LEFT * 60)))
|
||||||
echo "$TIME_LEFT h $MINUTES_LEFT min"
|
echo "$TIME_LEFT h $MINUTES_LEFT min"
|
||||||
else
|
else
|
||||||
echo ""
|
echo ""
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,9 @@
|
||||||
(import ../../modules/libvirt/user.nix {username = "kylekrein";})
|
(import ../../modules/libvirt/user.nix {username = "kylekrein";})
|
||||||
|
|
||||||
../../users/tania
|
../../users/tania
|
||||||
|
|
||||||
|
./hibernation.nix
|
||||||
];
|
];
|
||||||
boot = {
|
|
||||||
# kernelParams = [
|
|
||||||
# "resume_offset=YOUR_OFFSET"
|
|
||||||
# ];
|
|
||||||
# resumeDevice = "/dev/disk/by-label/nixos";
|
|
||||||
};
|
|
||||||
|
|
||||||
sops.secrets."ssh_keys/${hwconfig.hostname}" = {};
|
sops.secrets."ssh_keys/${hwconfig.hostname}" = {};
|
||||||
services.fwupd.enable = true; #fwupdmgr update
|
services.fwupd.enable = true; #fwupdmgr update
|
||||||
|
|
|
||||||
18
nixos/hosts/kylekrein-framework12/hibernation.nix
Normal file
18
nixos/hosts/kylekrein-framework12/hibernation.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
{pkgs, ...}: {
|
||||||
|
boot = {
|
||||||
|
kernelParams = [
|
||||||
|
"resume_offset=533760"
|
||||||
|
"mem_sleep_default=deep"
|
||||||
|
];
|
||||||
|
resumeDevice = "/dev/disk/by-label/nixos";
|
||||||
|
};
|
||||||
|
services.logind = {
|
||||||
|
lidSwitch = "suspend-then-hibernate";
|
||||||
|
powerKey = "suspend-then-hibernate";
|
||||||
|
powerKeyLongPress = "poweroff";
|
||||||
|
};
|
||||||
|
systemd.sleep.extraConfig = ''
|
||||||
|
HibernateDelaySec=30m
|
||||||
|
SuspendState=mem
|
||||||
|
'';
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue