105 lines
3.4 KiB
Nix
105 lines
3.4 KiB
Nix
# This override makes OpenGL just automagically work with VirtualGL
|
|
#
|
|
# Add a setup hook to the mesa package that automatically adds a
|
|
# libvglfaker.so dependency to executables that depend on libGL.so.
|
|
|
|
{ prev, stdenv, buildEnv, substituteAll, bash
|
|
, autoreconfHook, pkg-config, python2
|
|
, xorg, llvmPackages, expat, mesa_glxgallium, mesa, 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 prev was closed on itself (nixpkgs #15280)
|
|
|
|
libGL = prev.libGL;
|
|
libGLU = prev.libGLU.override { inherit libGL; };
|
|
libGLU_combined = buildEnv {
|
|
name = "libGLU-combined";
|
|
paths = [ libGL libGLU ];
|
|
extraOutputsToInstall = [ "dev" ];
|
|
};
|
|
|
|
virtualglLib = (prev.virtualglLib.override { inherit libGL libGLU 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 = prev.fltk.override { inherit libGL libGLU freeglut; };
|
|
freeglut = prev.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 = mesa.overrideAttrs (attrs: {
|
|
mesonFlags = attrs.mesonFlags ++ [
|
|
"-Ddisk-cache-key=${placeholder "out"}"
|
|
"-Dglx=gallium-xlib"
|
|
"-Ddri-drivers="
|
|
"-Dgallium-drivers=swrast"
|
|
"-Dglvnd=false"
|
|
"-Dgallium-nine=false"
|
|
];
|
|
|
|
preInstall = ''
|
|
mkdir -p $out/share
|
|
'' + attrs.preInstall or "";
|
|
|
|
postInstall = ''
|
|
# move drivers (just vulkan in our case and doesn't avoid LLVM)
|
|
mkdir -p $drivers/lib
|
|
mv -t $drivers/lib $out/lib/libvulkan_*
|
|
|
|
# move libOSMesa to $osmesa, as it's relatively big
|
|
mkdir -p $osmesa/lib
|
|
mv -t $osmesa/lib/ $out/lib/libOSMesa*
|
|
|
|
# Update search path used by Vulkan (it's pointing to $out but
|
|
# drivers are in $drivers)
|
|
for js in $drivers/share/vulkan/icd.d/*.json; do
|
|
substituteInPlace "$js" --replace "$out" "$drivers"
|
|
done
|
|
'';
|
|
postFixup = "";
|
|
} );
|
|
|
|
# Duplicate mesa/stubs.nix with mesa_glxgallium stuffed in as the libGL source
|
|
|
|
libGL = stdenv.mkDerivation {
|
|
inherit (libglvnd) version;
|
|
pname = "libGL";
|
|
outputs = [ "out" "dev" ];
|
|
|
|
nativeBuildInputs = [ xorg.lndir ];
|
|
|
|
# Use stub libraries from mesa_glxgallium and libglvnd
|
|
buildCommand = ''
|
|
mkdir -p $out/lib
|
|
lndir -silent ${mesa_glxgallium.out}/lib $out/lib
|
|
lndir -silent ${libglvnd.out}/lib $out/lib
|
|
|
|
mkdir -p $dev/include
|
|
lndir -silent ${mesa_glxgallium.dev}/include $dev/include
|
|
lndir -silent ${libglvnd.dev}/include $dev/include
|
|
|
|
mkdir -p $dev/nix-support
|
|
echo "${autoVirtualGLHook} ${mesa_glxgallium.dev} ${libglvnd.dev} $out" \
|
|
> $dev/nix-support/propagated-build-inputs
|
|
|
|
mkdir -p $dev/lib/pkgconfig
|
|
ln -st $dev/lib/pkgconfig ${mesa_glxgallium.dev}/lib/pkgconfig/{gl,GL,glesv1_cm,GLESv1_CM,glesv2,GLESv2}.pc
|
|
ln -st $dev/lib/pkgconfig ${libglvnd.dev}/lib/pkgconfig/{egl,EGL}.pc
|
|
'';
|
|
};
|
|
}
|