summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Picciano <me@mediocregopher.com>2024-01-06 14:39:30 +0100
committerBrian Picciano <me@mediocregopher.com>2024-01-06 15:23:15 +0100
commit570561ac7339c6c27c12422be69005a429109258 (patch)
tree567a5ec05ee7892041646eb0aaa4a75a4f9b4d01
parent11bd1d5d87a8419ed5018f387f02dc5de8cd59a8 (diff)
Fix alacritty for ubuntu
-rw-r--r--alacritty/default.nix36
1 files changed, 32 insertions, 4 deletions
diff --git a/alacritty/default.nix b/alacritty/default.nix
index 0a84229..b24d696 100644
--- a/alacritty/default.nix
+++ b/alacritty/default.nix
@@ -19,6 +19,8 @@
alacrittyUnwrap = pkgs.writeShellScript "alacritty-unwrap" ''
unset LD_LIBRARY_PATH
+ unset LIBGL_DRIVERS_PATH
+ unset LIBVA_DRIVERS_PATH
unset __EGL_VENDOR_LIBRARY_DIRS
exec "$@"
'';
@@ -49,10 +51,36 @@
'';
alacritty = pkgs.writeShellScriptBin "alacritty" ''
- # TODO this might break things, especially if the machine is not using
- # nvidia, but more investigation is needed. But it at least lets us get rid
- # of nixGL.
- export LD_LIBRARY_PATH=/usr/lib
+ set -e -x
+
+ host_ld_lib_path="$(
+ ldconfig -v 2>/dev/null \
+ | grep -v ^$'\t' \
+ | tr -s ':\n' ':' \
+ | head -c-1 \
+ )"
+
+ bin_ld_lib_path="$(
+ objdump -x ${pkgs.alacritty}/bin/alacritty \
+ | grep "RUNPATH" \
+ | awk '{print $2}' \
+ )"
+
+ host_dri_path="$(
+ echo "$host_ld_lib_path" \
+ | tr -s ':' '\n' \
+ | while read d; do if [ -d "$d/dri" ]; then echo "$d"/dri; fi; done \
+ | tr '\n' ':' \
+ | head -c-1
+ )"
+
+ # overwrite LD_LIBRARY_PATH such that the binary's ld search path is still
+ # searched first, but afterwards the host's ld search path is looked
+ # through. Similarly, the dri paths are set to be the hosts. This allows us
+ # to use the host's graphics drivers for alacritty.
+ export LD_LIBRARY_PATH="$bin_ld_lib_path":"$host_ld_lib_path"
+ export LIBGL_DRIVERS_PATH="$host_dri_path"
+ export LIBVA_DRIVERS_PATH="$host_dri_path"
export __EGL_VENDOR_LIBRARY_DIRS=/usr/share/glvnd/egl_vendor.d
exec ${pkgs.alacritty}/bin/alacritty \