Skip to content

Commit

Permalink
display management in gui vm
Browse files Browse the repository at this point in the history
- Turn off the display when system is suspended and turn on when it
  resumes.

Signed-off-by: Ganga Ram <Ganga.Ram@tii.ae>
  • Loading branch information
gangaram-tii committed Oct 24, 2024
1 parent 5d5ae6d commit b4b747b
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 9 deletions.
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
};

givc = {
url = "github:tiiuae/ghaf-givc/68079deac890d19d84389becc37805310fc0107f";
url = "github:tiiuae/ghaf-givc/8bf77b04420c5c70478eba27b877f5e83e6b438d";
inputs = {
nixpkgs.follows = "nixpkgs";
flake-parts.follows = "flake-parts";
Expand Down
4 changes: 4 additions & 0 deletions modules/givc/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
inputs.givc.nixosModules.host
./common.nix
./host.nix
{
# Include givc overlay to import app
nixpkgs.overlays = [ inputs.givc.overlays.default ];
}
];
givc-guivm.imports = [
inputs.givc.nixosModules.sysvm
Expand Down
4 changes: 4 additions & 0 deletions modules/givc/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ in
port = "9000";
tls.enable = config.ghaf.givc.enableTls;
admin = config.ghaf.givc.adminConfig;
services = [
"display-suspend.service"
"display-resume.service"
];
};
};
}
3 changes: 0 additions & 3 deletions modules/hardware/common/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ in
ghaf.qemu.guivm = optionalAttrs (hasAttr "hardware" config.ghaf) {
microvm.qemu.extraArgs =
[
# Button
"-device"
"button"
# Battery
"-device"
"battery"
Expand Down
5 changes: 4 additions & 1 deletion modules/host/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
#
# Modules that should be only imported to host
#
{ lib, ... }:
{
lib,
...
}:
{
networking.hostName = lib.mkDefault "ghaf-host";

Expand Down
29 changes: 29 additions & 0 deletions modules/microvm/virtualization/microvm/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@ let
services.xdghandlers.enable = true;
};

# 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.wlopm}/bin/wlopm --off '*'
'';
Environment = ''
WAYLAND_DISPLAY=/run/user/1000/wayland-0
'';
};
};

systemd.services.display-resume = {
enable = true;
description = "Display Resume Service";
serviceConfig = {
Type = "oneshot";
ExecStart = ''
${pkgs.wlopm}/bin/wlopm --on '*'
'';
Environment = ''
WAYLAND_DISPLAY=/run/user/1000/wayland-0
'';
};
};

systemd.services."waypipe-ssh-keygen" =
let
keygenScript = pkgs.writeShellScriptBin "waypipe-ssh-keygen" ''
Expand Down
36 changes: 36 additions & 0 deletions modules/microvm/virtualization/microvm/microvm-host.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
}:
let
cfg = config.ghaf.virtualization.microvm-host;
manageDisplay =
config.ghaf.givc.enable
&& config.ghaf.virtualization.microvm.adminvm.enable
&& config.ghaf.virtualization.microvm.guivm.enable;

inherit (builtins) replaceStrings;
cliArgs = replaceStrings [ "\n" ] [ " " ] ''
--name ${config.ghaf.givc.adminConfig.name}
--addr ${config.ghaf.givc.adminConfig.addr}
--port ${config.ghaf.givc.adminConfig.port}
${lib.optionalString config.ghaf.givc.enableTls "--cacert /run/givc/ca-cert.pem"}
${lib.optionalString config.ghaf.givc.enableTls "--cert /run/givc/ghaf-host-cert.pem"}
${lib.optionalString config.ghaf.givc.enableTls "--key /run/givc/ghaf-host-key.pem"}
${lib.optionalString (!config.ghaf.givc.enableTls) "--notls"}
'';
in
{
imports = [
Expand Down Expand Up @@ -54,6 +69,27 @@ in
withHardenedConfigs = true;
};
ghaf.givc.host.enable = true;
systemd.services.display-suspend = lib.mkIf manageDisplay {
enable = true;
description = "Display Suspend Service";
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.givc-cli}/bin/givc-cli ${cliArgs} suspend";
};
wantedBy = [ "sleep.target" ];
before = [ "sleep.target" ];
};

systemd.services.display-resume = lib.mkIf manageDisplay {
enable = true;
description = "Display Resume Service";
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.givc-cli}/bin/givc-cli ${cliArgs} wakeup";
};
wantedBy = [ "suspend.target" ];
after = [ "suspend.target" ];
};

# TODO: remove hardcoded paths
systemd.services."microvm@audio-vm".serviceConfig =
Expand Down

0 comments on commit b4b747b

Please sign in to comment.