chore[work]: improve suspend behaviour

This commit is contained in:
Leon Schwarzäugl 2025-10-21 13:13:27 +02:00
parent 9da6bd15ab
commit e07b3c2b6e
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84
9 changed files with 221 additions and 75 deletions

View file

@ -1988,8 +1988,8 @@ My work machine. Built for more security, this is the gold standard of my config
# ''; # '';
boot = { boot = {
# kernelPackages = lib.mkDefault pkgs.kernel.linuxPackages; kernelPackages = lib.mkDefault pkgs.kernel.linuxPackages;
kernelPackages = lib.mkDefault pkgs.linuxPackages_latest; # kernelPackages = lib.mkDefault pkgs.linuxPackages_latest;
binfmt.emulatedSystems = [ "aarch64-linux" ]; binfmt.emulatedSystems = [ "aarch64-linux" ];
initrd = { initrd = {
availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "cryptd" "usbhid" "sd_mod" "r8152" ]; availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "cryptd" "usbhid" "sd_mod" "r8152" ];
@ -2005,7 +2005,8 @@ My work machine. Built for more security, this is the gold standard of my config
kernelModules = [ "kvm-amd" ]; kernelModules = [ "kvm-amd" ];
kernelParams = [ kernelParams = [
"mem_sleep_default=deep" # deep sleep is discontinued by amd
# "mem_sleep_default=deep"
# supposedly, this helps save power on laptops # supposedly, this helps save power on laptops
# in reality (at least on this model), this just generate excessive heat on the CPUs # in reality (at least on this model), this just generate excessive heat on the CPUs
# "amd_pstate=passive" # "amd_pstate=passive"
@ -10536,9 +10537,16 @@ This holds configuration that is specific to framework laptops.
boot = { boot = {
kernelParams = [ kernelParams = [
"resume_offset=${builtins.toString config.swarselsystems.hibernation.offset}" "resume_offset=${builtins.toString config.swarselsystems.hibernation.offset}"
# "mem_sleep_default=deep"
]; ];
inherit (config.swarselsystems.hibernation) resumeDevice; inherit (config.swarselsystems.hibernation) resumeDevice;
}; };
systemd.services."systemd-suspend-then-hibernate".aliases = [ "systemd-suspend.service" ];
powerManagement.enable = true;
systemd.sleep.extraConfig = ''
HibernateDelaySec=120m
SuspendState=freeze
'';
}; };
} }
#+end_src #+end_src
@ -10778,6 +10786,7 @@ Options that I need specifically at work. There are more options at [[#h:f0b2ea9
}; };
}; };
# ACTION=="remove", ENV{PRODUCT}=="3/1050/407/110", RUN+="${pkgs.kanshi}/bin/kanshictl switch laptoponly"
udev.extraRules = '' udev.extraRules = ''
# lock screen when yubikey removed # lock screen when yubikey removed
ACTION=="remove", ENV{PRODUCT}=="3/1050/407/110", RUN+="${pkgs.systemd}/bin/systemctl suspend" ACTION=="remove", ENV{PRODUCT}=="3/1050/407/110", RUN+="${pkgs.systemd}/bin/systemctl suspend"
@ -11737,7 +11746,53 @@ This section is for programs that require no further configuration. zsh Integrat
sioyek.enable = true; sioyek.enable = true;
swayr.enable = true; swayr.enable = true;
timidity.enable = true; timidity.enable = true;
wlogout.enable = true; wlogout ={
enable = true;
layout = [
{
label = "lock";
action = "loginctl lock-session";
text = "Lock";
keybind = "l";
circular = true;
}
{
label = "hibernate";
action = "systemctl hibernate";
text = "Hibernate";
keybind = "h";
circular = true;
}
{
label = "logout";
action = "loginctl terminate-user $USER";
text = "Logout";
keybind = "u";
circular = true;
}
{
label = "shutdown";
action = "systemctl poweroff";
text = "Shutdown";
keybind = "p";
circular = true;
}
{
label = "suspend";
action = "systemctl suspend";
text = "Suspend";
keybind = "s";
circular = true;
}
{
label = "reboot";
action = "systemctl reboot";
text = "Reboot";
keybind = "r";
circular = true;
}
];
};
yt-dlp.enable = true; yt-dlp.enable = true;
zoxide = { zoxide = {
enable = true; enable = true;
@ -14299,7 +14354,10 @@ Currently, I am too lazy to explain every option here, but most of it is very se
in in
{ {
name = "lidopen"; name = "lidopen";
exec = [ "${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/standwp.png --mode ${config.stylix.imageScalingMode}" ]; exec = [
"${pkgs.swaybg}/bin/swaybg --output '${config.swarselsystems.sharescreen}' --image ${config.swarselsystems.wallpaper} --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/standwp.png --mode ${config.stylix.imageScalingMode}"
];
outputs = [ outputs = [
{ {
criteria = config.swarselsystems.sharescreen; criteria = config.swarselsystems.sharescreen;
@ -14854,6 +14912,18 @@ This service changes the screen hue at night. I am not sure if that really does
config = lib.mkIf config.swarselmodules.${moduleName} { config = lib.mkIf config.swarselmodules.${moduleName} {
services.${moduleName} = { services.${moduleName} = {
enable = true; enable = true;
extraArgs = [
"-W"
" Consider charging the battery"
"-C"
" Battery is low; plug in charger now"
"-D"
" Device will lose power in a few seconds"
"-c"
"10"
"-d"
"5"
];
}; };
}; };
@ -14893,7 +14963,7 @@ This service changes the screen hue at night. I am not sure if that really does
let let
brightnessctl = "${lib.getExe pkgs.brightnessctl}"; brightnessctl = "${lib.getExe pkgs.brightnessctl}";
swaylock = "${lib.getExe pkgs.swaylock-effects}"; swaylock = "${lib.getExe pkgs.swaylock-effects}";
suspend = "${pkgs.systemd}/bin/systemctl"; suspend = "${pkgs.systemd}/bin/systemctl suspend";
in in
{ {
enable = true; enable = true;
@ -14908,6 +14978,7 @@ This service changes the screen hue at night. I am not sure if that really does
]; ];
events = [ events = [
# { event = "before-sleep"; command = "${lib.getExe pkgs.swaylock-effects} -f --screenshots --clock --effect-blur 7x5 --effect-vignette 0.5:0.5 --fade-in 0.2"; } # { event = "before-sleep"; command = "${lib.getExe pkgs.swaylock-effects} -f --screenshots --clock --effect-blur 7x5 --effect-vignette 0.5:0.5 --fade-in 0.2"; }
# { event = "after-resume"; command = "${swaylock} -f "; }
{ event = "before-sleep"; command = "${swaylock} -f "; } { event = "before-sleep"; command = "${swaylock} -f "; }
{ event = "lock"; command = "${swaylock} -f "; } { event = "lock"; command = "${swaylock} -f "; }
]; ];
@ -15416,6 +15487,7 @@ The rest of the settings is at [[#h:bbf2ecb6-c8ff-4462-b5d5-d45b28604ddf][work]]
profile = { profile = {
name = "lidopen"; name = "lidopen";
exec = [ exec = [
"${pkgs.swaybg}/bin/swaybg --output '${config.swarselsystems.sharescreen}' --image ${config.swarselsystems.wallpaper} --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output 'HP Inc. HP 732pk CNC4080YL5' --image ${self}/files/wallpaper/botanicswp.png --mode ${config.stylix.imageScalingMode}" "${pkgs.swaybg}/bin/swaybg --output 'HP Inc. HP 732pk CNC4080YL5' --image ${self}/files/wallpaper/botanicswp.png --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output 'Hewlett Packard HP Z24i CN44250RDT' --image ${self}/files/wallpaper/op6wp.png --mode ${config.stylix.imageScalingMode}" "${pkgs.swaybg}/bin/swaybg --output 'Hewlett Packard HP Z24i CN44250RDT' --image ${self}/files/wallpaper/op6wp.png --mode ${config.stylix.imageScalingMode}"
]; ];
@ -15450,6 +15522,7 @@ The rest of the settings is at [[#h:bbf2ecb6-c8ff-4462-b5d5-d45b28604ddf][work]]
{ {
name = "lidopen"; name = "lidopen";
exec = [ exec = [
"${pkgs.swaybg}/bin/swaybg --output '${config.swarselsystems.sharescreen}' --image ${config.swarselsystems.wallpaper} --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/navidrome.png --mode ${config.stylix.imageScalingMode}" "${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/navidrome.png --mode ${config.stylix.imageScalingMode}"
"${pkgs.kanshare}/bin/kanshare ${config.swarselsystems.sharescreen} '${monitor}'" "${pkgs.kanshare}/bin/kanshare ${config.swarselsystems.sharescreen} '${monitor}'"
]; ];

View file

@ -22,8 +22,8 @@
# ''; # '';
boot = { boot = {
# kernelPackages = lib.mkDefault pkgs.kernel.linuxPackages; kernelPackages = lib.mkDefault pkgs.kernel.linuxPackages;
kernelPackages = lib.mkDefault pkgs.linuxPackages_latest; # kernelPackages = lib.mkDefault pkgs.linuxPackages_latest;
binfmt.emulatedSystems = [ "aarch64-linux" ]; binfmt.emulatedSystems = [ "aarch64-linux" ];
initrd = { initrd = {
availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "cryptd" "usbhid" "sd_mod" "r8152" ]; availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "cryptd" "usbhid" "sd_mod" "r8152" ];
@ -39,7 +39,8 @@
kernelModules = [ "kvm-amd" ]; kernelModules = [ "kvm-amd" ];
kernelParams = [ kernelParams = [
"mem_sleep_default=deep" # deep sleep is discontinued by amd
# "mem_sleep_default=deep"
# supposedly, this helps save power on laptops # supposedly, this helps save power on laptops
# in reality (at least on this model), this just generate excessive heat on the CPUs # in reality (at least on this model), this just generate excessive heat on the CPUs
# "amd_pstate=passive" # "amd_pstate=passive"

View file

@ -7,6 +7,18 @@ in
config = lib.mkIf config.swarselmodules.${moduleName} { config = lib.mkIf config.swarselmodules.${moduleName} {
services.${moduleName} = { services.${moduleName} = {
enable = true; enable = true;
extraArgs = [
"-W"
" Consider charging the battery"
"-C"
" Battery is low; plug in charger now"
"-D"
" Device will lose power in a few seconds"
"-c"
"10"
"-d"
"5"
];
}; };
}; };

View file

@ -53,7 +53,10 @@
in in
{ {
name = "lidopen"; name = "lidopen";
exec = [ "${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/standwp.png --mode ${config.stylix.imageScalingMode}" ]; exec = [
"${pkgs.swaybg}/bin/swaybg --output '${config.swarselsystems.sharescreen}' --image ${config.swarselsystems.wallpaper} --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/standwp.png --mode ${config.stylix.imageScalingMode}"
];
outputs = [ outputs = [
{ {
criteria = config.swarselsystems.sharescreen; criteria = config.swarselsystems.sharescreen;

View file

@ -25,7 +25,53 @@
sioyek.enable = true; sioyek.enable = true;
swayr.enable = true; swayr.enable = true;
timidity.enable = true; timidity.enable = true;
wlogout.enable = true; wlogout = {
enable = true;
layout = [
{
label = "lock";
action = "loginctl lock-session";
text = "Lock";
keybind = "l";
circular = true;
}
{
label = "hibernate";
action = "systemctl hibernate";
text = "Hibernate";
keybind = "h";
circular = true;
}
{
label = "logout";
action = "loginctl terminate-user $USER";
text = "Logout";
keybind = "u";
circular = true;
}
{
label = "shutdown";
action = "systemctl poweroff";
text = "Shutdown";
keybind = "p";
circular = true;
}
{
label = "suspend";
action = "systemctl suspend";
text = "Suspend";
keybind = "s";
circular = true;
}
{
label = "reboot";
action = "systemctl reboot";
text = "Reboot";
keybind = "r";
circular = true;
}
];
};
yt-dlp.enable = true; yt-dlp.enable = true;
zoxide = { zoxide = {
enable = true; enable = true;

View file

@ -9,7 +9,7 @@ in
let let
brightnessctl = "${lib.getExe pkgs.brightnessctl}"; brightnessctl = "${lib.getExe pkgs.brightnessctl}";
swaylock = "${lib.getExe pkgs.swaylock-effects}"; swaylock = "${lib.getExe pkgs.swaylock-effects}";
suspend = "${pkgs.systemd}/bin/systemctl"; suspend = "${pkgs.systemd}/bin/systemctl suspend";
in in
{ {
enable = true; enable = true;
@ -24,6 +24,7 @@ in
]; ];
events = [ events = [
# { event = "before-sleep"; command = "${lib.getExe pkgs.swaylock-effects} -f --screenshots --clock --effect-blur 7x5 --effect-vignette 0.5:0.5 --fade-in 0.2"; } # { event = "before-sleep"; command = "${lib.getExe pkgs.swaylock-effects} -f --screenshots --clock --effect-blur 7x5 --effect-vignette 0.5:0.5 --fade-in 0.2"; }
# { event = "after-resume"; command = "${swaylock} -f "; }
{ event = "before-sleep"; command = "${swaylock} -f "; } { event = "before-sleep"; command = "${swaylock} -f "; }
{ event = "lock"; command = "${swaylock} -f "; } { event = "lock"; command = "${swaylock} -f "; }
]; ];

View file

@ -299,6 +299,7 @@ in
profile = { profile = {
name = "lidopen"; name = "lidopen";
exec = [ exec = [
"${pkgs.swaybg}/bin/swaybg --output '${config.swarselsystems.sharescreen}' --image ${config.swarselsystems.wallpaper} --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output 'HP Inc. HP 732pk CNC4080YL5' --image ${self}/files/wallpaper/botanicswp.png --mode ${config.stylix.imageScalingMode}" "${pkgs.swaybg}/bin/swaybg --output 'HP Inc. HP 732pk CNC4080YL5' --image ${self}/files/wallpaper/botanicswp.png --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output 'Hewlett Packard HP Z24i CN44250RDT' --image ${self}/files/wallpaper/op6wp.png --mode ${config.stylix.imageScalingMode}" "${pkgs.swaybg}/bin/swaybg --output 'Hewlett Packard HP Z24i CN44250RDT' --image ${self}/files/wallpaper/op6wp.png --mode ${config.stylix.imageScalingMode}"
]; ];
@ -333,6 +334,7 @@ in
{ {
name = "lidopen"; name = "lidopen";
exec = [ exec = [
"${pkgs.swaybg}/bin/swaybg --output '${config.swarselsystems.sharescreen}' --image ${config.swarselsystems.wallpaper} --mode ${config.stylix.imageScalingMode}"
"${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/navidrome.png --mode ${config.stylix.imageScalingMode}" "${pkgs.swaybg}/bin/swaybg --output '${monitor}' --image ${self}/files/wallpaper/navidrome.png --mode ${config.stylix.imageScalingMode}"
"${pkgs.kanshare}/bin/kanshare ${config.swarselsystems.sharescreen} '${monitor}'" "${pkgs.kanshare}/bin/kanshare ${config.swarselsystems.sharescreen} '${monitor}'"
]; ];

View file

@ -17,8 +17,15 @@
boot = { boot = {
kernelParams = [ kernelParams = [
"resume_offset=${builtins.toString config.swarselsystems.hibernation.offset}" "resume_offset=${builtins.toString config.swarselsystems.hibernation.offset}"
# "mem_sleep_default=deep"
]; ];
inherit (config.swarselsystems.hibernation) resumeDevice; inherit (config.swarselsystems.hibernation) resumeDevice;
}; };
systemd.services."systemd-suspend-then-hibernate".aliases = [ "systemd-suspend.service" ];
powerManagement.enable = true;
systemd.sleep.extraConfig = ''
HibernateDelaySec=120m
SuspendState=freeze
'';
}; };
} }

View file

@ -208,6 +208,7 @@ in
}; };
}; };
# ACTION=="remove", ENV{PRODUCT}=="3/1050/407/110", RUN+="${pkgs.kanshi}/bin/kanshictl switch laptoponly"
udev.extraRules = '' udev.extraRules = ''
# lock screen when yubikey removed # lock screen when yubikey removed
ACTION=="remove", ENV{PRODUCT}=="3/1050/407/110", RUN+="${pkgs.systemd}/bin/systemctl suspend" ACTION=="remove", ENV{PRODUCT}=="3/1050/407/110", RUN+="${pkgs.systemd}/bin/systemctl suspend"