1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 replaceVars, 7 fontconfig, 8 python, 9 10 # build-system 11 cython, 12 setuptools, 13 14 # nativeBuildInputs 15 SDL2, 16 pkg-config, 17 18 # buildInputs 19 freetype, 20 libjpeg, 21 libpng, 22 libX11, 23 portmidi, 24 SDL2_image, 25 SDL2_mixer, 26 SDL2_ttf, 27}: 28 29buildPythonPackage rec { 30 pname = "pygame"; 31 version = "2.6.1"; 32 pyproject = true; 33 34 src = fetchFromGitHub { 35 owner = "pygame"; 36 repo = "pygame"; 37 tag = version; 38 # Unicode file names lead to different checksums on HFS+ vs. other 39 # filesystems because of unicode normalisation. The documentation 40 # has such files and will be removed. 41 hash = "sha256-paSDF0oPogq0g0HSDRagGu0OfsqIku6q4GGAMveGntk="; 42 postFetch = "rm -rf $out/docs/reST"; 43 }; 44 45 patches = [ 46 # Patch pygame's dependency resolution to let it find build inputs 47 (replaceVars ./fix-dependency-finding.patch { 48 buildinputs_include = builtins.toJSON ( 49 builtins.concatMap (dep: [ 50 "${lib.getDev dep}/" 51 "${lib.getDev dep}/include" 52 "${lib.getDev dep}/include/SDL2" 53 ]) buildInputs 54 ); 55 buildinputs_lib = builtins.toJSON ( 56 builtins.concatMap (dep: [ 57 "${lib.getLib dep}/" 58 "${lib.getLib dep}/lib" 59 ]) buildInputs 60 ); 61 }) 62 63 # mixer queue test returns busy queue when it shouldn't 64 ./skip-mixer-test.patch 65 # https://github.com/libsdl-org/sdl2-compat/issues/476 66 ./skip-rle-tests.patch 67 # https://github.com/libsdl-org/sdl2-compat/issues/489 68 ./adapt-to-sdl3-format-message.patch 69 70 # https://github.com/pygame/pygame/pull/4497 71 ./0001-Use-SDL_HasSurfaceRLE-when-available.patch 72 ./0002-Don-t-assume-that-touch-devices-support-get_num_fing.patch 73 ]; 74 75 postPatch = '' 76 substituteInPlace src_py/sysfont.py \ 77 --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \ 78 --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list 79 ''; 80 81 build-system = [ 82 cython 83 setuptools 84 ]; 85 86 nativeBuildInputs = [ 87 SDL2 88 pkg-config 89 ]; 90 91 buildInputs = [ 92 freetype 93 libjpeg 94 libpng 95 libX11 96 portmidi 97 SDL2 98 (SDL2_image.override { enableSTB = false; }) 99 SDL2_mixer 100 SDL2_ttf 101 ]; 102 103 preConfigure = '' 104 ${python.pythonOnBuildForHost.interpreter} buildconfig/config.py 105 ''; 106 107 env = lib.optionalAttrs stdenv.cc.isClang { 108 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types"; 109 }; 110 111 checkPhase = '' 112 runHook preCheck 113 114 # No audio or video device in test environment 115 export SDL_VIDEODRIVER=dummy 116 export SDL_AUDIODRIVER=disk 117 # traceback for segfaults 118 export PYTHONFAULTHANDLER=1 119 120 ${python.interpreter} -m pygame.tests -v \ 121 --exclude opengl,timing \ 122 --time_out 300 123 124 runHook postCheck 125 ''; 126 pythonImportsCheck = [ "pygame" ]; 127 128 meta = { 129 description = "Python library for games"; 130 homepage = "https://www.pygame.org/"; 131 changelog = "https://github.com/pygame/pygame/releases/tag/${src.tag}"; 132 license = lib.licenses.lgpl21Plus; 133 maintainers = with lib.maintainers; [ emilytrau ]; 134 platforms = lib.platforms.unix; 135 }; 136}