Skip to content

Commit

Permalink
Turn off the display when system is suspended on lid close
Browse files Browse the repository at this point in the history
This patch is adding two systemd services.
On suspend we turn off the display of gui-vm and on
resume we turn on the display back. This will help to
save system power when system system is suspended or lid
is closed.

Signed-off-by: Vunny Sodhi <vunny.sodhi@unikie.com>
  • Loading branch information
vunnyso committed Sep 11, 2024
1 parent c54e0f4 commit dad14d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
3 changes: 0 additions & 3 deletions modules/hardware/common/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ in
ghaf.qemu.guivm = optionalAttrs (hasAttr "hardware" config.ghaf) {
microvm.qemu.extraArgs =
[
# Button
"-device"
"button"
# Battery
"-device"
"battery"
Expand Down
25 changes: 24 additions & 1 deletion modules/host/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Modules that should be only imported to host
#
{ lib, ... }:
{ lib, pkgs, ... }:
{
networking.hostName = lib.mkDefault "ghaf-host";

Expand All @@ -15,4 +15,27 @@
# To push logs to central location
../common/logging/client.nix
];

# Adding below systemd services to save power by turning off display when system is suspended / lid close
systemd.services.display-suspend = {
enable = true;
description = "Display Suspend Service";
serviceConfig = {
Type = "oneshot";
ExecStart = ''${pkgs.sshpass}/bin/sshpass -p ghaf ${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no ghaf@gui-vm-debug WAYLAND_DISPLAY=/run/user/1000/wayland-0 wlopm --off \* '';
};
wantedBy = [ "sleep.target" ];
before = [ "sleep.target" ];
};

systemd.services.display-resume = {
enable = true;
description = "Display Resume Service";
serviceConfig = {
Type = "oneshot";
ExecStart = ''${pkgs.sshpass}/bin/sshpass -p ghaf ${pkgs.openssh}/bin/ssh -o StrictHostKeyChecking=no ghaf@gui-vm-debug WAYLAND_DISPLAY=/run/user/1000/wayland-0 wlopm --on \* '';
};
wantedBy = [ "suspend.target" ];
after = [ "suspend.target" ];
};
}

0 comments on commit dad14d1

Please sign in to comment.