{ pkgs, ... }: { imports = [ ./hardware-configuration.nix ]; services.displayManager = { defaultSession = "hyprland"; autoLogin = { enable = true; user = "phos"; }; }; 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; autoStart = true; openFirewall = true; capSysAdmin = true; settings = { sunshine_name = "phosphophyllite"; output_name = 1; capture = "wlr"; encoder = "software"; hevc_mode = 1; av1_mode = 1; packetsize = 1200; min_log_level = "debug"; origin_web_ui_allowed = "lan"; global_prep_cmd = ''[ {"do":"/run/wrappers/bin/sudo ${pkgs.systemd}/bin/systemctl stop sunshine-poweroff.timer","undo":"/run/wrappers/bin/sudo ${pkgs.systemd}/bin/systemctl start sunshine-poweroff.timer"}, {"do":"${pkgs.systemd}/bin/systemctl --user start sunshine-monitor-prep.service","undo":"${pkgs.systemd}/bin/systemctl --user start sunshine-monitor-restore.service"} ]''; }; }; systemd.user.services.sunshine.serviceConfig.ExecStartPre = "${pkgs.procps}/bin/pkill -x sunshine || true"; 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.user.services.sunshine-monitor-prep = { description = "Disable vertical monitor for Sunshine sessions"; serviceConfig = { Type = "oneshot"; ExecStart = "${pkgs.bash}/bin/bash -lc '/run/current-system/sw/bin/hyprctl keyword monitor HDMI-A-1,disable || true'"; }; }; systemd.user.services.sunshine-monitor-restore = { description = "Restore vertical monitor after Sunshine sessions"; serviceConfig = { Type = "oneshot"; ExecStart = "${pkgs.bash}/bin/bash -lc '/run/current-system/sw/bin/hyprctl keyword monitor HDMI-A-1,1920x1080@60,2560x0,1,transform,3 || true'"; }; }; systemd.user.services.autolock-after-login = { description = "Lock session shortly after autologin"; wantedBy = [ "graphical-session.target" ]; after = [ "graphical-session.target" ]; serviceConfig = { Type = "oneshot"; ExecStart = "${pkgs.bash}/bin/bash -lc 'sleep 20; command -v serpantinum >/dev/null && serpantinum lock || true'"; }; }; 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 <