# This override makes OpenGL just automagically work with VirtualGL # # Add a setup hook to the mesa_noglu package that automatically adds # a libvglfaker.so dependency to executables that depend on libGL.so. { super, stdenv, buildEnv, substituteAll, bash , autoreconfHook, pkgconfig, python2 , xorg, llvmPackages, expat, mesa_glxgallium, mesa_noglu, libglvnd }: let autoVirtualGLHook = let # Ugliness required to break the loop created by the fact that # the libGL hook requires VirtualGL which requires libGL. # # This would be clean if super was closed on itself (nixpkgs #15280) libGL = super.libGL; libGLU = super.libGLU.override { inherit libGL; }; libGLU_combined = buildEnv { name = "libGLU-combined"; paths = [ libGL libGLU ]; extraOutputsToInstall = [ "dev" ]; }; virtualglLib = (super.virtualglLib.override { inherit libGLU_combined fltk; }).overrideAttrs (attrs: { postFixup = attrs.postFixup or "" + '' patchelf --set-rpath /usr/lib${stdenv.lib.optionalString stdenv.is64bit "64"}/nvidia:"$(patchelf --print-rpath $out/lib/libvglfaker.so)" $out/lib/libvglfaker.so ''; } ); fltk = super.fltk.override { inherit libGLU_combined freeglut; }; freeglut = super.freeglut.override { inherit libGL libGLU; }; in substituteAll { src = ./insert-virtualgl.sh; bash = "${bash}/bin/bash"; virtualglLib = "${virtualglLib}/lib/libvglfaker.so"; }; in { # Mesa build for glxgallium software rendering (works with all X11 forwarding) mesa_glxgallium = stdenv.mkDerivation rec { version = super.mesa_noglu.version; name = "mesa-glxgallium-${version}"; src = super.mesa_noglu.src; outputs = [ "out" "dev" ]; configureFlags = [ "--with-gallium-drivers=swrast" "--with-platforms=x11" # surfaceless would make sense, but egl requires dri "--disable-dri" "--enable-glx=gallium-xlib" # gallium-xlib requires no dri "--enable-gallium-osmesa" "--enable-llvm" "--disable-egl" # egl requries dri for some reason "--disable-gbm" # gbm requires dri for some reason "--enable-llvm-shared-libs" "--disable-opencl" ]; nativeBuildInputs = [ autoreconfHook pkgconfig python2 ]; propagatedBuildInputs = [ ]; buildInputs = [ llvmPackages.llvm xorg.xorgproto xorg.libX11 xorg.libXext xorg.libxcb expat ]; enableParallelBuilding = true; meta = with stdenv.lib; { description = "An open source implementation of OpenGL"; homepage = https://www.mesa3d.org/; license = licenses.mit; # X11 variant, in most files platforms = platforms.linux; }; }; # Duplicate mesa_noglu.stub with mesa_glxgallium stuffed in as the libGL source libGL = stdenv.mkDerivation { name = "libGL-${libglvnd.version}"; outputs = [ "out" "dev" ]; nativeBuildInputs = [ xorg.lndir ]; # Use stub libraries from mesa_glxgallium and libglvnd and headers from lib_noglu buildCommand = '' mkdir -p $out/lib lndir -silent ${mesa_glxgallium.out}/lib $out/lib lndir -silent ${libglvnd.out}/lib $out/lib mkdir -p $dev/{,lib/pkgconfig,nix-support} echo "$out" > $dev/nix-support/propagated-build-inputs echo ${autoVirtualGLHook} >> $dev/nix-support/propagated-build-inputs ln -s ${mesa_noglu.dev}/include $dev/include genPkgConfig() { local location="$1" local name="$2" local lib="$3" cat <$dev/lib/pkgconfig/$name.pc Name: $name Description: $lib library Version: ${mesa_noglu.version} Libs: -L$location/lib -l$lib Cflags: -I${mesa_noglu.dev}/include EOF } genPkgConfig ${mesa_glxgallium.out} gl GL genPkgConfig ${libglvnd.out} egl EGL genPkgConfig ${libglvnd.out} glesv1_cm GLESv1_CM genPkgConfig ${libglvnd.out} glesv2 GLESv2 ''; }; }