From c95a59028ad98817e634a31c444bed735b7314d4 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Sat, 28 Dec 2024 12:21:49 +0000 Subject: [PATCH] fix(sunshine.nix): improve error messages and add checks --- hosts/architect/sunshine.nix | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hosts/architect/sunshine.nix b/hosts/architect/sunshine.nix index ba77396..47aa869 100644 --- a/hosts/architect/sunshine.nix +++ b/hosts/architect/sunshine.nix @@ -6,7 +6,7 @@ let name = "sunshine-resolution-script"; text = '' #!${pkgs.bash}/bin/bash - + width=''${1:-1280} height=''${2:-720} refresh_rate=''${3:-120} @@ -16,16 +16,21 @@ let xrandr_mode_str=''${modeline//Modeline \"*\" /} mode_alias="''${width}x''${height}" - echo "xrandr setting new mode ''${mode_alias} ''${xrandr_mode_str}" - ${pkgs.xorg.xrandr}/bin/xrandr --rmmode ''${mode_alias} || echo error - ${pkgs.xorg.xrandr}/bin/xrandr --newmode ''${mode_alias} ''${xrandr_mode_str} || echo error - ${pkgs.xorg.xrandr}/bin/xrandr --addmode DP-0 ''${mode_alias} || echo error + echo "xrandr setting new mode ''${mode_alias} ''${xrandr_mode_str}" + + # Check if mode exists before trying to remove it + if ${pkgs.xorg.xrandr}/bin/xrandr --listmodes | grep -q "^''${mode_alias}"; then + ${pkgs.xorg.xrandr}/bin/xrandr --rmmode ''${mode_alias} || echo "Failed to remove existing mode" + fi + + ${pkgs.xorg.xrandr}/bin/xrandr --newmode ''${mode_alias} ''${xrandr_mode_str} || echo "Failed to create new mode" + ${pkgs.xorg.xrandr}/bin/xrandr --addmode DP-0 ''${mode_alias} || echo "Failed to add mode to output" # Apply new xrandr mode - ${pkgs.xorg.xrandr}/bin/xrandr --output DP-0 --primary --mode ''${mode_alias} --pos 0x0 --rotate normal || echo error + ${pkgs.xorg.xrandr}/bin/xrandr --output DP-0 --primary --mode ''${mode_alias} --pos 0x0 --rotate normal || echo "Failed to apply mode" - ${config.boot.kernelPackages.nvidia_x11.settings}/bin/nvidia-settings -a 'SyncToVBlank=0' || echo error - ${config.boot.kernelPackages.nvidia_x11.bin}/bin/nvidia-smi --persistence-mode=ENABLED || echo error + ${config.boot.kernelPackages.nvidia_x11.settings}/bin/nvidia-settings -a 'SyncToVBlank=0' || echo "Failed to disable VSync" + ${config.boot.kernelPackages.nvidia_x11.bin}/bin/nvidia-smi --persistence-mode=ENABLED || echo "Failed to enable persistence mode" ''; executable = true; destination = "/bin/resolution.sh";