Skip to content

Commit

Permalink
Replace unused powercontrol package with GIVC wrapper script
Browse files Browse the repository at this point in the history
Signed-off-by: Kajus Naujokaitis <[email protected]>
  • Loading branch information
kajusnau authored and brianmcgillion committed Nov 28, 2024
1 parent 01bb7e3 commit 2aea100
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 78 deletions.
67 changes: 67 additions & 0 deletions packages/ghaf-powercontrol/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# SPDX-License-Identifier: Apache-2.0
{
writeShellApplication,
lib,
ghafConfig,
systemd,
wlopm,
givc-cli,
...
}:
let
inherit (builtins) replaceStrings;
inherit (lib) optionalString;
cliArgs = replaceStrings [ "\n" ] [ " " ] ''
--name ${ghafConfig.givc.adminConfig.name}
--addr ${ghafConfig.givc.adminConfig.addr}
--port ${ghafConfig.givc.adminConfig.port}
${optionalString ghafConfig.givc.enableTls "--cacert /run/givc/ca-cert.pem"}
${optionalString ghafConfig.givc.enableTls "--cert /run/givc/gui-vm-cert.pem"}
${optionalString ghafConfig.givc.enableTls "--key /run/givc/gui-vm-key.pem"}
${optionalString (!ghafConfig.givc.enableTls) "--notls"}
'';
useGivc = ghafConfig.givc.enable;
# Handle Wayland display power state
waylandDisplayCmd = command: ''
WAYLAND_DISPLAY=/run/user/${builtins.toString ghafConfig.users.accounts.uid}/wayland-0 \
wlopm --${command} '*'
'';
in
writeShellApplication {
name = "ghaf-powercontrol";
runtimeInputs = [
systemd
wlopm
] ++ (lib.optional useGivc givc-cli);
text = ''
case "$1" in
reboot|poweroff)
${if useGivc then "givc-cli ${cliArgs}" else "systemctl"} "$1"
;;
suspend)
# Lock sessions
loginctl lock-session
# Switch off display before suspension
${waylandDisplayCmd "off"}
# Send suspend command to host, ensure screen is on in case of failure
${if useGivc then "givc-cli ${cliArgs}" else "systemctl"} suspend \
|| ${waylandDisplayCmd "on"}
# Switch on display on wakeup
${waylandDisplayCmd "on"}
;;
*)
echo "Unknown option. Supported: reboot, poweroff, suspend."
exit 1
;;
esac
'';

meta = {
description = "Wrapper script to control Ghaf power states using systemctl or GIVC.";
platforms = lib.platforms.linux;
};
}
78 changes: 0 additions & 78 deletions packages/powercontrol/default.nix

This file was deleted.

0 comments on commit 2aea100

Please sign in to comment.