Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
samuela opened this issue Jan 20, 2024 · 8 comments
Open

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

samuela opened this issue Jan 20, 2024 · 8 comments

Comments

@samuela
Copy link
Contributor

samuela commented Jan 20, 2024

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
Copy link

jim3692 commented Jan 28, 2024

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

@samuela
Copy link
Contributor Author

samuela commented Jan 28, 2024

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
Copy link

jim3692 commented Jun 16, 2024

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
Copy link

jim3692 commented Jul 25, 2024

  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
Copy link

jim3692 commented Jul 25, 2024

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
Copy link

jim3692 commented Jul 25, 2024

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
Copy link

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
Copy link

jim3692 commented Nov 14, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@samuela @soupglasses @jim3692 and others