diff --git a/default/hypr/envs.lua b/default/hypr/envs.lua index 2921199e..11909844 100644 --- a/default/hypr/envs.lua +++ b/default/hypr/envs.lua @@ -35,6 +35,9 @@ end table.insert(kept, 1, bin_dir) hl.env("PATH", table.concat(kept, ":")) +-- Hardware-specific environment. +require("default.hypr.nvidia") + hl.config({ xwayland = { force_zero_scaling = true, diff --git a/default/hypr/helpers.lua b/default/hypr/helpers.lua index eb647a17..80aa5747 100644 --- a/default/hypr/helpers.lua +++ b/default/hypr/helpers.lua @@ -6,6 +6,21 @@ local function shell_quote(value) return "'" .. tostring(value):gsub("'", "'\\''") .. "'" end +o.shell_quote = shell_quote + +function o.shell_succeeds(command) + local ok, _, code = os.execute(command .. " >/dev/null 2>&1") + return ok == true or ok == 0 or code == 0 +end + +function o.cmd_present(command) + return o.shell_succeeds("command -v " .. shell_quote(command)) +end + +function o.cmd_missing(command) + return not o.cmd_present(command) +end + local function command_from(value, description) if type(value) ~= "table" then return value diff --git a/default/hypr/nvidia.lua b/default/hypr/nvidia.lua new file mode 100644 index 00000000..3f6c8daf --- /dev/null +++ b/default/hypr/nvidia.lua @@ -0,0 +1,15 @@ +local paths = require("default.hypr.paths") + +local nvidia_gsp = paths.omarchy_path .. "/bin/omarchy-hw-nvidia-gsp" +local nvidia_without_gsp = paths.omarchy_path .. "/bin/omarchy-hw-nvidia-without-gsp" + +if o.shell_succeeds("lspci | grep -qi nvidia") then + if o.shell_succeeds(o.shell_quote(nvidia_gsp)) then + hl.env("NVD_BACKEND", "direct") + hl.env("LIBVA_DRIVER_NAME", "nvidia") + hl.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia") + elseif o.shell_succeeds(o.shell_quote(nvidia_without_gsp)) then + hl.env("NVD_BACKEND", "egl") + hl.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia") + end +end diff --git a/install/config/hardware/nvidia-user.sh b/install/config/hardware/nvidia-user.sh deleted file mode 100644 index e604f1db..00000000 --- a/install/config/hardware/nvidia-user.sh +++ /dev/null @@ -1,21 +0,0 @@ -envs="$HOME/.config/hypr/envs.lua" -[[ -f $envs ]] || exit 0 - -if lspci | grep -qi 'nvidia'; then - if omarchy-hw-nvidia-gsp && ! grep -q 'NVIDIA (Turing+ with GSP firmware)' "$envs"; then - cat >>"$envs" <<'EOF' - --- NVIDIA (Turing+ with GSP firmware) -hl.env("NVD_BACKEND", "direct") -hl.env("LIBVA_DRIVER_NAME", "nvidia") -hl.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia") -EOF - elif omarchy-hw-nvidia-without-gsp && ! grep -q 'NVIDIA (Maxwell/Pascal/Volta without GSP firmware)' "$envs"; then - cat >>"$envs" <<'EOF' - --- NVIDIA (Maxwell/Pascal/Volta without GSP firmware) -hl.env("NVD_BACKEND", "egl") -hl.env("__GLX_VENDOR_LIBRARY_NAME", "nvidia") -EOF - fi -fi diff --git a/install/config/hardware/nvidia.sh b/install/config/hardware/nvidia.sh index b10985cf..e7370995 100644 --- a/install/config/hardware/nvidia.sh +++ b/install/config/hardware/nvidia.sh @@ -17,7 +17,7 @@ if lspci | grep -qi 'nvidia'; then omarchy-pkg-add "${PACKAGES[@]}" - # Per-user Hyprland NVIDIA env vars are handled by nvidia-user.sh. + # Per-session Hyprland NVIDIA env vars are handled by default/hypr/nvidia.lua. # Configure modprobe for early KMS mkdir -p /etc/modprobe.d diff --git a/install/config/user.sh b/install/config/user.sh index 4e5602ad..063080c8 100644 --- a/install/config/user.sh +++ b/install/config/user.sh @@ -7,4 +7,3 @@ run_logged $OMARCHY_INSTALL/config/hardware/bluetooth-user.sh run_logged $OMARCHY_INSTALL/config/hardware/asus/fix-audio-mixer.sh run_logged $OMARCHY_INSTALL/config/hardware/asus/fix-mic.sh run_logged $OMARCHY_INSTALL/config/hardware/framework/fix-f13-amd-audio-input.sh -run_logged $OMARCHY_INSTALL/config/hardware/nvidia-user.sh