Open samuela opened 10 months ago
You can alias nix-shell
to nixGL nixVulkanIntel nix-shell
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.
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.
- 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?
Great. I will check it. Is there any related documentation to that? I want to understand whether something like this is possible for Vulkan.
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.
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.
I started using home-manager. I don't plan to move to system-manager at the moment, so I did the following:
Created /etc/tmpfiles.d/99-nix-ogl.conf
with the following contents. Make sure to replace the {USERNAME}
.
L+ /run/opengl-driver-32 - - - - /nix/var/nix/profiles/per-user/{USERNAME}/profile/drivers/opengl-driver-32
L+ /run/opengl-driver - - - - /nix/var/nix/profiles/per-user/{USERNAME}/profile/drivers/opengl-driver
Added nixgl to the flake inputs and extraSpecialArgs:
{
inputs = {
# ...
nixgl = {
url = "github:nix-community/nixGL";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { home-manager, nixgl, ... }: {
homeConfigurations."{USERNAME}" = home-manager.lib.homeManagerConfiguration {
# ...
extraSpecialArgs = { inherit nixgl; };
};
};
}
Added the following configuration to home-manager:
home.packages = [
nixgl.packages.${pkgs.system}.nixGLIntel
nixgl.packages.${pkgs.system}.nixVulkanIntel
(
let
driversEnv = with pkgs; buildEnv {
name = "graphics-drivers";
paths = [ mesa.drivers rocmPackages.clr.icd ];
};
driversEnv32 = with pkgs; buildEnv {
name = "graphics-drivers-32bit";
paths = with pkgsi686Linux; [ mesa.drivers ];
};
in pkgs.runCommand "graphics-drivers" {} ''
mkdir -p $out/drivers ; cd $out/drivers
ln -s "${toString driversEnv32}" opengl-driver-32
ln -s "${toString driversEnv}" opengl-driver
''
)
]
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
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?