Installing nixGL on aarch64

nixGL is a tool that’s useful for people who use Nix on distributions that aren’t NixOS. It lets you run graphical applications from nixpkgs with hardware acceleration; without it everything falls back to software rendering. Here’s how to install it on aarch64 (arm64).

nixGL provides the nixGLMesa and nixVulkanMesa packages. The second one is only useful if your system can handle vulkan. The recommended way to install these packages is with their channel, and that’s what I’m going to demonstrate. Adapt this to flakes as necessary.

First, add the channel:

nix-channel --add https://github.com/guibou/nixGL/archive/main.tar.gz nixgl && nix-channel --update

what not to do

If you just run nix-env -iA nixgl.nixGLMesa, you will get this error:

nix-env -iA nixgl.nixGLMesa
installing 'nixGLMesa'
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nixGLMesa'
         whose name attribute is located at /nix/store/aar6rj1zv6bkac1fis2kpg3ivl2jkw2r-nixpkgs-23.11/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:348:7

       … while evaluating attribute 'text' of derivation 'nixGLMesa'

         at /nix/store/aar6rj1zv6bkac1fis2kpg3ivl2jkw2r-nixpkgs-23.11/nixpkgs/pkgs/build-support/trivial-builders/default.nix:148:16:

          147|     runCommand name
          148|       { inherit text executable checkPhase allowSubstitutes preferLocalBuild;
             |                ^
          149|         passAsFile = [ "text" ];

       error: i686 Linux package set can only be used with the x86 family.

The important part:

error: i686 Linux package set can only be used with the x86 family.

This is because by default, nixGL pulls in some i686 libraries for multi-lib support, but it does this even if you are on arm. Fortunately this can be disabled with the enable32bits setting.

what to do

So, here’s what you should do instead:

nix-env -i -E '(_: with import <nixgl> { enable32bits = false; }; nixGLMesa)'

# if you want vulkan
nix-env -i -E '(_: with import <nixgl> { enable32bits = false; }; nixVulkanMesa)'

Now you can use the nixGLMesa and nixVulkanMesa commands to run programs. For example,

artemis@reform ~> nix-shell -p mesa-demos
[nix-shell:~]$ which glxinfo
/nix/store/pgkpc86qjnkncyq0h1bc7qdr7q2g0a2r-mesa-demos-9.0.0/bin/glxinfo

[nix-shell:~]$ nixGLMesa glxinfo | grep renderer
    GLX_MESA_copy_sub_buffer, GLX_MESA_query_renderer, GLX_MESA_swap_control, 
    GLX_MESA_query_renderer, GLX_MESA_swap_control, GLX_OML_swap_method, 
Extended renderer info (GLX_MESA_query_renderer):
OpenGL renderer string: Vivante GC7000 rev 6214

[nix-shell:~]$ 

There it is, Vivante GC7000! That means we are hardware accelerated :D

the more correct fix

It would probably be good to fix this upstream, so that it doesn’t pull on i686 libraries on other architectures. I don’t actually know how to do that though, else I’d try to write a fix myself, so I’m writing about how to make it work right now since that’s what I’ve got the energy for.