summaryrefslogtreecommitdiff
path: root/hosts
diff options
context:
space:
mode:
Diffstat (limited to 'hosts')
-rw-r--r--hosts/phosphophyllite/default.nix70
1 files changed, 69 insertions, 1 deletions
diff --git a/hosts/phosphophyllite/default.nix b/hosts/phosphophyllite/default.nix
index 104cbf1..95e6b9f 100644
--- a/hosts/phosphophyllite/default.nix
+++ b/hosts/phosphophyllite/default.nix
@@ -1,4 +1,4 @@
-{ ... }: {
+{ pkgs, ... }: {
imports = [
./hardware-configuration.nix
];
@@ -17,6 +17,74 @@
enable = true;
enable32Bit = true;
};
+
+ networking.interfaces.enp4s0.wakeOnLan.enable = true;
+
+ services.sunshine = {
+ enable = true;
+ openFirewall = true;
+ settings = {
+ sunshine_name = "phosphophyllite";
+ output_name = "DP-2";
+ capture = "wlr";
+ origin_web_ui_allowed = "lan";
+ global_prep_cmd = ''[{"do":"${pkgs.sudo}/bin/sudo ${pkgs.systemd}/bin/systemctl stop sunshine-poweroff.timer","undo":"${pkgs.sudo}/bin/sudo ${pkgs.systemd}/bin/systemctl start sunshine-poweroff.timer"}]'';
+ };
+ };
+
+ security.sudo.extraRules = [
+ {
+ users = [ "phos" ];
+ commands = [
+ {
+ command = "${pkgs.systemd}/bin/systemctl start sunshine-poweroff.timer";
+ options = [ "NOPASSWD" ];
+ }
+ {
+ command = "${pkgs.systemd}/bin/systemctl stop sunshine-poweroff.timer";
+ options = [ "NOPASSWD" ];
+ }
+ ];
+ }
+ ];
+
+ systemd.timers.sunshine-poweroff = {
+ description = "Shutdown desktop 15 minutes after Sunshine disconnect";
+ timerConfig = {
+ OnActiveSec = "15m";
+ AccuracySec = "30s";
+ Unit = "sunshine-poweroff.service";
+ };
+ };
+
+ systemd.services.sunshine-poweroff = {
+ description = "Power off if machine stays idle after Sunshine disconnect";
+ serviceConfig.Type = "oneshot";
+ script = ''
+ set -euo pipefail
+
+ sessions="$(${pkgs.systemd}/bin/loginctl list-sessions --no-legend || true)"
+ if [ -n "$sessions" ]; then
+ while read -r session _; do
+ [ -z "$session" ] && continue
+
+ seat="$(${pkgs.systemd}/bin/loginctl show-session "$session" -p Seat --value)"
+ [ -z "$seat" ] && continue
+
+ active="$(${pkgs.systemd}/bin/loginctl show-session "$session" -p Active --value)"
+ idle="$(${pkgs.systemd}/bin/loginctl show-session "$session" -p IdleHint --value)"
+
+ if [ "$active" = "yes" ] && [ "$idle" = "no" ]; then
+ exit 0
+ fi
+ done <<EOF
+$sessions
+EOF
+ fi
+
+ exec ${pkgs.systemd}/bin/systemctl poweroff
+ '';
+ };