nix-community / nixGL

A wrapper tool for nix OpenGL application [maintainer=@guibou]
712 stars 80 forks source link

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

Open samuela opened 10 months ago

samuela commented 10 months ago

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?

jim3692 commented 9 months ago

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

samuela commented 9 months ago

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.

jim3692 commented 5 months ago

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 commented 3 months ago
  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 commented 3 months ago

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 commented 3 months ago

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.

soupglasses commented 1 month ago

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.

jim3692 commented 5 days ago

I started using home-manager. I don't plan to move to system-manager at the moment, so I did the following:

Now, I can update the Mesa/ROCm drivers for Nix using home-manager, without requiring root privileges.

It's inspired by the way NixOS installs OpenGL/Vulkan/OpenCL drivers. For more info: 64-bit drivers 32-bit drivers tmpfiles