nixGL icon indicating copy to clipboard operation
nixGL copied to clipboard

[feature request] `source $(nixGL shell)` support

Open samuela opened this issue 1 year ago • 8 comments

It would be super handy to be able to "install" nixGL into a shell session such that I don't have to worry about wrapping each command in nixGL foo ....

Would maintainers be supportive of including such a feature?

samuela avatar Jan 20 '24 23:01 samuela

You can alias nix-shell to nixGL nixVulkanIntel nix-shell

jim3692 avatar Jan 28 '24 18:01 jim3692

That's certainly an option, but what I'm ideally looking for is a solution to "install" nixGL in the currently running shell instead of spawning a new one.

samuela avatar Jan 28 '24 18:01 samuela

That's certainly an option, but what I'm ideally looking for is a solution to "install" nixGL in the currently running shell instead of spawning a new one.

Lately Arch updated its gcc version and now that alias fails with these errors:

nix-shell: /nix/store/bn7pnigb0f8874m6riiw6dngsmdyic1g-gcc-13.3.0-lib/lib/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by /usr/lib/libnixexpr.so)
nix-shell: /nix/store/bn7pnigb0f8874m6riiw6dngsmdyic1g-gcc-13.3.0-lib/lib/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by /usr/lib/libnixmain.so)
nix-shell: /nix/store/bn7pnigb0f8874m6riiw6dngsmdyic1g-gcc-13.3.0-lib/lib/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by /usr/lib/libnixstore.so)
nix-shell: /nix/store/bn7pnigb0f8874m6riiw6dngsmdyic1g-gcc-13.3.0-lib/lib/libstdc++.so.6: version `CXXABI_1.3.15' not found (required by /usr/lib/libnixutil.so)

So, I came up with a more "install" solution:

if [[ ! "$IN_NIX_SHELL" = "" ]] && [[ "$IN_NIXGL" = "" ]]; then
  export IN_NIXGL=1
  source <(
    diff <(env) <(nixGL nixVulkanIntel env) \
      | grep '>' | sed 's/^>/export/g'
  )
fi

It extracts the environment variables that nixGL and nixVulkanIntel set, and adds them to the current shell.

jim3692 avatar Jun 16 '24 14:06 jim3692

Was looking at the solutions posted before and after, and in cross-repositories, but decided to make it the "NixOS" way, so that I won't boil my mind

Since I'm running an immutable setup, I wanted to keep the "packaging" unhingeness for personal reasons

The thing: https://github.com/immutarch/postcopy_beta/blob/main/usr/bin/ima-nix-mesa-binder

What this does?

  1. Runs nixGL env, checks for LIBGL_LIBRARY_PATH entries, where usually both 64-bit and 32-but MESA outputs are located
  2. Determines which arch are they, and appropiately symlinks each store to /run/opengl-driver(-32)

Cons:

  1. You might have to manually re-add symlinks after each mesa + nixgl update

Other than that, it works very much fine with everything graphically-required installed

IMG_20240725_022529_491 IMG_20240725_022534_403 IMG_20240725_022610_475

theVakhovskeIsTaken avatar Jul 24 '24 23:07 theVakhovskeIsTaken

  1. Determines which arch are they, and appropiately symlinks each store to /run/opengl-driver(-32)

I can't understand how the games manage to find the OpenGL drivers in that path. Are you exporting the /run/opengl-driver path?

jim3692 avatar Jul 25 '24 08:07 jim3692

Are you exporting the /run/opengl-driver path?

No, I am not. The base library preload directory is defined by package on it's own, so this entire thing is almost 1:1 with NixOS in terms of how drivers get loaded

theVakhovskeIsTaken avatar Jul 25 '24 09:07 theVakhovskeIsTaken

Great. I will check it. Is there any related documentation to that? I want to understand whether something like this is possible for Vulkan.

jim3692 avatar Jul 25 '24 10:07 jim3692

Great. I will check it. Is there any related documentation to that? I want to understand whether something like this is possible for Vulkan.

No reason to, these directories already include Vulkan drivers and their ICD loaders

theVakhovskeIsTaken avatar Jul 25 '24 10:07 theVakhovskeIsTaken

Sorry. My fault. I expected Vulkan to require a different method, as it's exposed with nixVulkanIntel, and not nixGL. Your script seems to work fine on Arch.

jim3692 avatar Jul 25 '24 10:07 jim3692

#!/bin/bash

mkdir -p /etc/tmpfiles.d
get_dri_info(){
    MESA_DRIVERS_PATH=$(nixGL env | grep LIBGL_DRIVERS_PATH | cut -d '=' -f 2 | sed 's/\/lib\/dri//g' | sed 's/:/ /g')
    for driver in ${MESA_DRIVERS_PATH}
    do
        DRIVER_FILE=$(file ${driver}/lib/libEGL_mesa.so.0.0.0 | cut -d ' ' -f 3)
        if [[ "${DRIVER_FILE}" == "64-bit" ]]; then
            DRIVER_64BIT=${driver}
        else
            DRIVER_32BIT=${driver}
        fi
    done
    echo "64-bit driver path: ${DRIVER_64BIT} | This will be symlinked to /run/opengl-driver"
    echo "L+ /run/opengl-driver - - - - ${DRIVER_64BIT}" > /etc/tmpfiles.d/99-nix-ogl-64b.conf
    echo "32-bit driver path: ${DRIVER_32BIT} | This will be symlinked to /run/opengl-driver-32"
    echo "L+ /run/opengl-driver-32 - - - - ${DRIVER_32BIT}" > /etc/tmpfiles.d/99-nix-ogl-32b.conf
    systemd-tmpfiles --create
}

if [[ "$(which nixGL)" ]]; then
    get_dri_info
else
    echo "nixGL is not installed on this system, please install nixGL"
fi

I've updated my scripts for my distro, so that's why i'm sending an universally working one here

theVakhovskeIsTaken avatar Jul 25 '24 16:07 theVakhovskeIsTaken

There's now also https://github.com/soupglasses/nix-system-graphics which is an alternative approach to do this with, which utilizes the /run/opengl-driver approach instead of environment variable magic as nixGL does.

soupglasses avatar Sep 26 '24 15:09 soupglasses