How do you replace mesa without recompiling everything?

There’s currently a bug in Mesa 21.0 that I need to fix to get correct behaviour with OBS.

I currently trying to rebuild with this:

but I suspect it would be a lot easier to just repackage OBS to depend on my custom mesa, but OBS doesn’t depend on mesa at all, and I get errors passing mesa to it with override, and I’m getting a little confused if this is the correct behavior.

perhaps I can pass it to hardware.opengl extraPackages? I’m getting lost! thanks.

  nixpkgs.config.packageOverrides = pkgs: {
      mesa = (pkgs.mesa.overrideAttrs (oldAttrs: rec {
        patches = [( pkgs.fetchurl {
          url = "https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9995.diff";
          sha256 = "0m7lrqjf4d79sppx7800wkwpyk9axwrch0l5v6lpc5arald77lab";
        })] ++ oldAttrs.patches;
      })).override {
        ninja = pkgs.ninja.overrideAttrs (oldAttrs: rec {
          NIX_CFLAGS_COMPILE = pkgs.lib.optionals (pkgs.stdenv.hostPlatform.system == "i686-linux") [
            "-D_LARGEFILE_SOURCE"
            "-D_FILE_OFFSET_BITS=64"
          ];
        });
      };
  };

The OpenGL/Vulkan/OpenCL driver that is used is a global state in /run/opengl-driver. There is a hidden configuration option hardware.opengl.package that is set to pkgs.mesa.drivers. Rather than overriding Mesa system-wide (potentially causing a lot of rebuilds), you could set hardware.opengl.package to your override. Something like (minus syntax errors :wink: ):

hardware.opengl.package = (pkgs.mesa.overrideAttrs (oldAttrs: rec {
        patches = [( pkgs.fetchurl {
          url = "https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9995.diff";
          sha256 = "0m7lrqjf4d79sppx7800wkwpyk9axwrch0l5v6lpc5arald77lab";
        })] ++ oldAttrs.patches;
      })).override {
        ninja = pkgs.ninja.overrideAttrs (oldAttrs: rec {
          NIX_CFLAGS_COMPILE = pkgs.lib.optionals (pkgs.stdenv.hostPlatform.system == "i686-linux") [
            "-D_LARGEFILE_SOURCE"
            "-D_FILE_OFFSET_BITS=64"
          ];
        }).drivers;

There is also hardware.opengl.package32 in case you also want to override 32-bit drivers.

2 Likes

In this particular case completely unnecessary but for the record - there is this cheaty impure way of replacing derivation as well:
https://search.nixos.org/options?channel=20.09&show=system.replaceRuntimeDependencies&from=0&size=50&sort=relevance&query=system.replaceRuntimeDependencies

1 Like