From f4f9852aa3de4f53a7406ce42db8cd8849c64fb4 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 25 Oct 2026 22:47:57 +0100 Subject: remote desktop setup --- hosts/phosphophyllite/default.nix | 70 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'hosts') 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 <