1 { stdenv, lib, fetchFromGitHub, cmake
2 , libGL, libXrandr, libXinerama, libXcursor, libX11, libXi, libXext
3 , Carbon, Cocoa, Kernel, OpenGL, fixDarwinDylibNames
4 , waylandSupport ? false, extra-cmake-modules, wayland
5 , wayland-protocols, libxkbcommon
8 stdenv.mkDerivation rec {
12 src = fetchFromGitHub {
16 sha256 = "sha256-4+H0IXjAwbL5mAWfsIVhW0BSJhcWjkQx4j2TrzZ3aIo=";
19 # Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583)
20 patches = lib.optional (!waylandSupport) ./x11.patch;
22 propagatedBuildInputs = [ (if stdenv.isDarwin then OpenGL else libGL) ];
24 nativeBuildInputs = [ cmake ]
25 ++ lib.optional stdenv.isDarwin fixDarwinDylibNames
26 ++ lib.optional waylandSupport extra-cmake-modules;
30 then [ wayland wayland-protocols libxkbcommon ]
31 else [ libX11 libXrandr libXinerama libXcursor libXi libXext ]
32 ++ lib.optionals stdenv.isDarwin [ Carbon Cocoa Kernel ];
35 "-DBUILD_SHARED_LIBS=ON"
36 ] ++ lib.optionals (!stdenv.isDarwin) [
37 "-DCMAKE_C_FLAGS=-D_GLFW_GLX_LIBRARY='\"${lib.getLib libGL}/lib/libGL.so.1\"'"
38 ] ++ lib.optionals waylandSupport [
39 "-DGLFW_USE_WAYLAND=ON"
40 "-DCMAKE_C_FLAGS=-D_GLFW_EGL_LIBRARY='\"${lib.getLib libGL}/lib/libEGL.so.1\"'"
43 postPatch = lib.optionalString waylandSupport ''
44 substituteInPlace src/wl_init.c \
45 --replace "libxkbcommon.so.0" "${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0"
49 description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time";
50 homepage = "https://www.glfw.org/";
51 license = licenses.zlib;
52 maintainers = with maintainers; [ marcweber twey ];
53 platforms = platforms.unix;