Skip to content

Instantly share code, notes, and snippets.

@rvanlaar
Last active May 4, 2020 20:47
Show Gist options
  • Save rvanlaar/5ca5ed3cd4314c12e8518b5672ae3774 to your computer and use it in GitHub Desktop.
Save rvanlaar/5ca5ed3cd4314c12e8518b5672ae3774 to your computer and use it in GitHub Desktop.
Scripts to use the correct nixGL paths
function use_nvidia_drivers() {
export LD_LIBRARY_PATH=/nix/store/xl3cr8kwlpi0j7il0zx4cb6sw05wx40g-libglvnd-1.2.0/lib:/nix/store/lhfyarm78k3lswp6xcvp51s9x4j6baq0-nvidia-440.64/lib:/nix/store/k8x3i9r3lyx4sv0wls45akvkk23bflg7-nvidia-440.64-lib32/lib:/nix/store/aw33ya4m2qmfjhvrxlvlw9gl28ixviya-libglvnd-1.2.0/lib:${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
}
function use_intel_drivers() {
export LIBGL_DRIVERS_PATH=/nix/store/vjcmnq73yj45bksaivwkzpzdc1vzf6yd-mesa-20.0.2-drivers/lib/dri:/nix/store/bdyq8k5kyp2lgva9vr03f04b18ys1vbg-mesa-20.0.2-drivers/lib/dri
export LD_LIBRARY_PATH=/nix/store/vjcmnq73yj45bksaivwkzpzdc1vzf6yd-mesa-20.0.2-drivers/lib:/nix/store/bdyq8k5kyp2lgva9vr03f04b18ys1vbg-mesa-20.0.2-drivers/lib:$LD_LIBRARY_PATH
}
if [ -f "$HOME/bin/is_egpu_connected.sh" ]; then
. "$HOME/bin/is_egpu_connected.sh"
is_egpu_connected
if [ $? -eq 1 ]; then
use_nvidia_drivers
else
use_intel_drivers
fi
fi
#!/usr/bin/env bash
# inspired by https://github.com/hertg/egpu-switcher
# declare files
declare xdir=/etc/X11
declare xfile=$xdir/xorg.conf
declare xfile_egpu=$xdir/xorg.conf.egpu
function is_egpu_connected() {
# read pci id from xorg.conf.egpu
declare egpu_pci_id=$(cat $xfile_egpu | grep -Ei "BusID" | grep -oEi '[0-9]+\:[0-9]+\:[0-9]+')
# create an array by splitting the BUS-ID on ':'
declare busArray=(${egpu_pci_id//:/ })
declare bus1d=${busArray[0]}
declare bus2d=${busArray[1]}
declare bus3d=${busArray[2]}
# convert dec to hex
declare bus1h=$(printf "%02x" $bus1d)
declare bus2h=$(printf "%02x" $bus2d)
declare bus3h=$(printf "%01x" $bus3d)
if [ $(lspci | grep -iEc "$bus1h:$bus2h.$bus3h") -eq 1 ]; then
return 1 # connected
fi
return 0 # unconnected
}
hash -r
@rvanlaar
Copy link
Author

rvanlaar commented May 4, 2020

Take this script as an example of how to automatically set up the OpenGL libs for Nixpkgs.
My setup has an external nvidia which is setup by the egpu-switcher utility.

To configure for your system:

  • write a check to see if intel or nvidia drivers are required
  • check out the contents of your nixGL and nixGLintel scripts,
  • paste exports in the driver functions
  • Add the contents of .profile to the end of your ~/.profile file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment