{ pkgs, ... }: { imports = [ ./hardware-configuration.nix ]; services.xserver.videoDrivers = [ "nvidia" ]; hardware.nvidia = { modesetting.enable = true; powerManagement.enable = false; powerManagement.finegrained = false; open = false; nvidiaSettings = true; }; hardware.graphics = { enable = true; enable32Bit = true; }; networking.interfaces.enp4s0.wakeOnLan.enable = true; services.sunshine = { enable = true; openFirewall = true; capSysAdmin = true; settings = { sunshine_name = "phosphophyllite"; output_name = "DP-2"; capture = "kms"; encoder = "software"; hevc_mode = 1; av1_mode = 1; packetsize = 1200; min_log_level = "debug"; 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 <