1 { stdenv, lib, fetchFromGitHub, cmake, pkg-config
2 , libGL, libXrandr, libXinerama, libXcursor, libX11, libXi, libXext
3 , darwin, fixDarwinDylibNames
5 , wayland-scanner, wayland-protocols, libxkbcommon, libdecor
6 , withMinecraftPatch ? false
12 pname = "glfw${lib.optionalString withMinecraftPatch "-minecraft"}";
15 src = fetchFromGitHub {
19 hash = "sha256-FcnQPDeNHgov1Z07gjFze0VMz2diOrpbKZCsI96ngz0=";
22 # Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583)
25 ] ++ lib.optionals withMinecraftPatch [
26 ./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch
29 propagatedBuildInputs = lib.optionals (!stdenv.hostPlatform.isWindows) [ libGL ];
31 nativeBuildInputs = [ cmake pkg-config ]
32 ++ lib.optionals stdenv.hostPlatform.isDarwin [ fixDarwinDylibNames ]
33 ++ lib.optionals stdenv.hostPlatform.isLinux [ wayland-scanner ];
36 lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ Carbon Cocoa Kernel ])
37 ++ lib.optionals stdenv.hostPlatform.isLinux [
50 "-DBUILD_SHARED_LIBS=ON"
51 ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) [
52 "-DCMAKE_C_FLAGS=-D_GLFW_GLX_LIBRARY='\"${lib.getLib libGL}/lib/libGL.so.1\"'"
53 "-DCMAKE_C_FLAGS=-D_GLFW_EGL_LIBRARY='\"${lib.getLib libGL}/lib/libEGL.so.1\"'"
56 postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
57 substituteInPlace src/wl_init.c \
58 --replace-fail "libxkbcommon.so.0" "${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0" \
59 --replace-fail "libdecor-0.so.0" "${lib.getLib libdecor}/lib/libdecor-0.so.0" \
60 --replace-fail "libwayland-client.so.0" "${lib.getLib wayland}/lib/libwayland-client.so.0" \
61 --replace-fail "libwayland-cursor.so.0" "${lib.getLib wayland}/lib/libwayland-cursor.so.0" \
62 --replace-fail "libwayland-egl.so.1" "${lib.getLib wayland}/lib/libwayland-egl.so.1"
65 # glfw may dlopen libwayland-client.so:
66 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
67 patchelf ''${!outputLib}/lib/libglfw.so --add-rpath ${lib.getLib wayland}/lib
71 description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time";
72 homepage = "https://www.glfw.org/";
73 license = licenses.zlib;
74 maintainers = with maintainers; [ marcweber Scrumplex twey ];
75 platforms = platforms.unix ++ platforms.windows;