1{
2 stdenv,
3 lib,
4 fetchFromGitLab,
5 fetchpatch,
6 autoreconfHook,
7 pkg-config,
8 python3,
9 addDriverRunpath,
10 libX11,
11 libXext,
12 xorgproto,
13}:
14
15stdenv.mkDerivation rec {
16 pname = "libglvnd";
17 version = "1.7.0";
18
19 src = fetchFromGitLab {
20 domain = "gitlab.freedesktop.org";
21 owner = "glvnd";
22 repo = "libglvnd";
23 rev = "v${version}";
24 sha256 = "sha256-2U9JtpGyP4lbxtVJeP5GUgh5XthloPvFIw28+nldYx8=";
25 };
26
27 patches = [
28 # Enable 64-bit file APIs on 32-bit systems:
29 # https://gitlab.freedesktop.org/glvnd/libglvnd/-/merge_requests/288
30 (fetchpatch {
31 name = "large-file.patch";
32 url = "https://gitlab.freedesktop.org/glvnd/libglvnd/-/commit/956d2d3f531841cabfeddd940be4c48b00c226b4.patch";
33 hash = "sha256-Y6YCzd/jZ1VZP9bFlHkHjzSwShXeA7iJWdyfxpgT2l0=";
34 })
35 ];
36
37 nativeBuildInputs = [
38 autoreconfHook
39 pkg-config
40 python3
41 addDriverRunpath
42 ];
43 buildInputs = [
44 libX11
45 libXext
46 xorgproto
47 ];
48
49 postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
50 substituteInPlace src/GLX/Makefile.am \
51 --replace "-Wl,-Bsymbolic " ""
52 substituteInPlace src/EGL/Makefile.am \
53 --replace "-Wl,-Bsymbolic " ""
54 substituteInPlace src/GLdispatch/Makefile.am \
55 --replace "-Xlinker --version-script=$(VERSION_SCRIPT)" "-Xlinker"
56 '';
57
58 env.NIX_CFLAGS_COMPILE = toString (
59 [
60 "-UDEFAULT_EGL_VENDOR_CONFIG_DIRS"
61 # FHS paths are added so that non-NixOS applications can find vendor files.
62 "-DDEFAULT_EGL_VENDOR_CONFIG_DIRS=\"${addDriverRunpath.driverLink}/share/glvnd/egl_vendor.d:/etc/glvnd/egl_vendor.d:/usr/share/glvnd/egl_vendor.d\""
63
64 "-Wno-error=array-bounds"
65 ]
66 ++ lib.optionals stdenv.cc.isClang [
67 "-Wno-error"
68 "-Wno-int-conversion"
69 ]
70 );
71
72 configureFlags =
73 [ ]
74 # Indirectly: https://bugs.freedesktop.org/show_bug.cgi?id=35268
75 ++ lib.optional stdenv.hostPlatform.isMusl "--disable-tls"
76 # Remove when aarch64-darwin asm support is upstream: https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/216
77 ++ lib.optional (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) "--disable-asm";
78
79 outputs = [
80 "out"
81 "dev"
82 ];
83
84 # Set RUNPATH so that libGLX can find driver libraries in /run/opengl-driver(-32)/lib.
85 # Note that libEGL does not need it because it uses driver config files which should
86 # contain absolute paths to libraries.
87 postFixup = ''
88 addDriverRunpath $out/lib/libGLX.so
89 '';
90
91 passthru = { inherit (addDriverRunpath) driverLink; };
92
93 meta = {
94 description = "GL Vendor-Neutral Dispatch library";
95 longDescription = ''
96 libglvnd is a vendor-neutral dispatch layer for arbitrating OpenGL API
97 calls between multiple vendors. It allows multiple drivers from different
98 vendors to coexist on the same filesystem, and determines which vendor to
99 dispatch each API call to at runtime.
100 Both GLX and EGL are supported, in any combination with OpenGL and OpenGL ES.
101 '';
102 inherit (src.meta) homepage;
103 # https://gitlab.freedesktop.org/glvnd/libglvnd#libglvnd:
104 changelog = "https://gitlab.freedesktop.org/glvnd/libglvnd/-/tags/v${version}";
105 license = with lib.licenses; [
106 mit
107 bsd1
108 bsd3
109 gpl3Only
110 asl20
111 ];
112 platforms = lib.platforms.unix;
113 # https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/212
114 badPlatforms = [ lib.systems.inspect.platformPatterns.isStatic ];
115 maintainers = with lib.maintainers; [ ];
116 };
117}