Upgrading or Downgrading Mesa Drivers

I’m using a laptop with a Intel HD520 GPU on NixOS 20.09, which comes with Mesa 20.x. I’d like to see if switching to Mesa 19.x or 21.x fixes problems with the Jogl libraries that break Processing. I tried switching versions using the information in the OpenGL wiki article. None of this seemes to work:

Mesa 19.x

Changing only hardware.opengl.package to Mesa 19 as of nixpkgs 5272327 (which is what the tag 20.03 points to) or 1db42b7f (which is the latest update for Mesa 19.x) made me be able to rebuild nixos, but I got the following error when running glxinfo, along with graphical glitches in Gnome:

$ nix run nixpkgs#glxinfo
name of display: :0
MESA-LOADER: failed to open swrast (search paths /run/opengl-driver/lib/dri)
libGL error: failed to load driver: swrast
X Error of failed request:  GLXBadContext
  Major opcode of failed request:  148 (GLX)
  Minor opcode of failed request:  6 (X_GLXIsDirect)
  Serial number of failed request:  46
  Current serial number in output stream:  45

Configuring only

  system.replaceRuntimeDependencies = [
    ({ original = pkgs.mesa; replacement = nixos-old-stable.mesa; })
    ({ original = pkgs.mesa.drivers; replacement = nixos-old-stable.mesa.drivers; })
  ];

results in the following error:

$ sudo nixos-rebuild boot
building Nix...
building the system configuration...
error: assertion '((stringLength  (drvName  (toString  oldDependency))) == (stringLength  (drvName  (toString  newDependency))))' failed

       at /nix/store/ybz2s0fyk31lc92k28ajm567mq8g9vds-nixos-20.09.4209.05f3800b80f/nixos/pkgs/build-support/replace-dependency.nix:82:4:

           81|   drvHash = discard (toString drv);
           82| in assert (stringLength (drvName (toString oldDependency)) == stringLength (drvName (toString newDependency)));
             |    ^
           83| rewriteMemo.${drvHash} or (warn "replace-dependency.nix: Derivation ${drvHash} does not depend on ${discard (toString oldDependency)}" drv)
(use '--show-trace' to show detailed location information)

When not touching any of the attrs described in the wiki, but instead trying to use an overlay like so

  nixpkgs.overlays = [  (self: super: { mesa = nixos-unstable.mesa; }) ];

I spend quite some time rebuilding packages, only to see it fail in the end with the following output:

[...]
checking for inline... inline
checking for windres... no
checking for x86_64-pc-linux-gnu-windres... no
/build/cogl-1.22.6/cogl-pango/cogl-pango.h:246: syntax error, unexpected identifier in 'COGL_DEPRECATED_IN_1_16_FOR (cogl_pango_show_layout)' at 'COGL_DEPRECATED_IN_1_16_FOR'
/build/cogl-1.22.6/cogl-pango/cogl-pango.h:269: syntax error, unexpected identifier in 'COGL_DEPRECATED_IN_1_16_FOR (cogl_pango_show_layout)' at 'COGL_DEPRECATED_IN_1_16_FOR'
/build/cogl-1.22.6/cogl-pango/cogl-pango.h:289: syntax error, unexpected identifier in 'COGL_DEPRECATED_IN_1_16_FOR (cogl_pango_show_layout_line)' at 'COGL_DEPRECATED_IN_1_16_FOR'
checking for pid_t... yes
checking for ssize_t... yes
checking for uid_t in sys/types.h... yes
  CCLD     gem_set_tiling_vs_blt
checking for off64_t... no
checking for struct stat64... no
checking for ... no
checking malloc.h usability... yes
checking malloc.h presence... yes
checking for malloc.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking search.h usability... yes
checking search.h presence... yes
Command '['/build/cogl-1.22.6/cogl-pango/tmp-introspect8gsooo2x/CoglPango-1.0', '--introspect-dump=/build/cogl-1.22.6/cogl-pango/tmp-introspect8gsooo2x/functions.txt,/build/cogl-1.22.6/cogl-pango/tmp-introspect8gsooo2x/dump.xml']' died with <Signals.SIGSEGV: 11>.
checking for search.h... yes
make[2]: *** [/nix/store/1bvcx1pyvii0p7ajvr08k784fxg41xmi-gobject-introspection-1.64.1-dev/share/gobject-introspection-1.0/Makefile.introspection:156: CoglPango-1.0.gir] Error 1
make[2]: Leaving directory '/build/cogl-1.22.6/cogl-pango'
make[1]: *** [Makefile:598: all-recursive] Error 1
make[1]: Leaving directory '/build/cogl-1.22.6'
make: *** [Makefile:525: all] Error 2
error: builder for '/nix/store/mf42qb78rf09w5iyp79f6mvrz4421nyg-cogl-1.22.6.drv' failed with exit code 2
error: 1 dependencies of derivation '/nix/store/0dvqbapi2v2vb1qd1cdcfvncc17pjqha-clutter-1.26.4.drv' failed to build
error: 1 dependencies of derivation '/nix/store/nsj94rvjc85ai6py5bkggkdanwf057sb-clutter-gst-3.0.27.drv' failed to build
building '/nix/store/gnf9jc5x6lnyl0p8h6mlzxjvmppn153y-gst-plugins-ugly-1.16.3.drv'...
error: 1 dependencies of derivation '/nix/store/4xqpbcplr0hvjkq38qahmqsqbm2jz6p0-cheese-3.34.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/36cs9pdwfjcy8397bh2bd89fp1qx2vdr-clutter-gtk-1.8.4.drv' failed to build
error: 1 dependencies of derivation '/nix/store/267w9zb2rzqjhvvyd5pcy9d6wn3hlf85-gnome-control-center-3.36.4.drv' failed to build
error: 1 dependencies of derivation '/nix/store/086b7s39m9fvmd5l71xxy0m3r2rcfn7k-sushi-3.34.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/z28ab38p3i9ia14zli95vkqbyi1q3vlk-totem-3.34.1.drv' failed to build
error: 1 dependencies of derivation '/nix/store/cksfiwq7w7n4mcxcd756vs44wr1r41nj-cheese-3.34.0_fish-completions.drv' failed to build
error: 1 dependencies of derivation '/nix/store/y1g65g04gnbid2yd0qnrx3qa9c4mnl2a-dbus-1.drv' failed to build
error (ignored): error: cannot unlink '/tmp/nix-build-graphviz-2.42.2.drv-0/source': Directory not empty
error: 1 dependencies of derivation '/nix/store/5abnsr83kjyvk8p0hnxbrifch8nwfxh5-gnome-contacts-3.36.2.drv' failed to build
error: 1 dependencies of derivation '/nix/store/31mhvdkpz127r59kargd1ksb9iai81pg-libchamplain-0.12.20.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vjz2jrm2p0hy0jb4z7iinl9z5qkwx7fm-man-paths.drv' failed to build
error: 1 dependencies of derivation '/nix/store/mdm0p965d99p7q1hsvndlybaazvr9l7g-system-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/6ybqc5fnx3fp0i979aig3qrdi3qg6hbg-nixos-system-basil-hallward-20.09.4209.05f3800b80f.drv' failed to build

Mesa 21.x

When changing hardware.opengl.package to Mesa 21.x on nixos-unstable, I am greeted by a gray message telling me that my system encountered an error instead of showing the login prompt and that I should contact the administrator.

Trying to configure system.replaceRuntimeDependencies results in the same error as a above, and trying to rebuild the system with a mesa overlay results in the same build error as above where the build of cogl-pango is aborted eventually.

Is the information in the wiki outdated? I at first read it so that using different Mesa drivers would be a matter of changing one single line attr (hardware.opengl.package), what am I misunderstanding? Am I accidentally skipping some steps? Thanks for any help!

No, I’ve added that part just a few days ago.

Ideally it would be the easy but unfortunately there are a lot of asterisks due to impurities.

Mesa 19.x: hardware.opengl.package should theoretically still be sufficient but there’s likely a Glibc update between the two Nixpkgs revisions (which breaks things).
Mesa 21.x: hardware.opengl.package unfortunately doesn’t work anymore so system.replaceRuntimeDependencies is required.

Your best option is likely to use a local Git repo/worktree, base that on the same Nixpkgs revision that your system is based on and then checkout only pkgs/development/libraries/mesa/ from the desired Nixpkgs revision (that way the glibc versions, etc. match).

And the error you’re seeing when using system.replaceRuntimeDependencies occurs when the lengths of the two Nix store paths for original and replacement differ (can be fixed by modifying version (or name) so that they have the same length.

Thanks! That was very insightful. I could indeed downgrade to Mesa 19.3.3 by cloning nixpkgs and checking out only development/libraries/mesa, like you suggested. It also fixed the problem with Jogl / Processing.

One remaining question: If you’re talking about “nix store path”, are you talking about the string length of the absolute path of a derivation in /nix/store? I.e. /nix/store/sp1xljjzaivi7fr8lbb027v8fmf8xmbk-mesa-21.0.1 vs /nix/store/0imwdz7ppj123vzjvmc2akq3zckfn6z0-mesa-20.1.10-dev?

Yes (to be precise the selected output paths of the two derivations - derivations itself are just files, e.g. /nix/store/5ckbc24n83xms7lp6vafpdgdyixg9lnl-mesa-21.0.1.drv).