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_classic,
16 pkg-config,
17
18 # buildInputs
19 freetype,
20 libjpeg,
21 libpng,
22 libX11,
23 portmidi,
24 SDL2_classic_image,
25 SDL2_classic_mixer,
26 SDL2_classic_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 ];
66
67 postPatch = ''
68 substituteInPlace src_py/sysfont.py \
69 --replace-fail 'path="fc-list"' 'path="${fontconfig}/bin/fc-list"' \
70 --replace-fail /usr/X11/bin/fc-list ${fontconfig}/bin/fc-list
71 '';
72
73 build-system = [
74 cython
75 setuptools
76 ];
77
78 nativeBuildInputs = [
79 SDL2_classic
80 pkg-config
81 ];
82
83 buildInputs = [
84 freetype
85 libjpeg
86 libpng
87 libX11
88 portmidi
89 SDL2_classic
90 (SDL2_classic_image.override { enableSTB = false; })
91 SDL2_classic_mixer
92 SDL2_classic_ttf
93 ];
94
95 preConfigure = ''
96 ${python.pythonOnBuildForHost.interpreter} buildconfig/config.py
97 '';
98
99 env = lib.optionalAttrs stdenv.cc.isClang {
100 NIX_CFLAGS_COMPILE = "-Wno-error=incompatible-function-pointer-types";
101 };
102
103 checkPhase = ''
104 runHook preCheck
105
106 # No audio or video device in test environment
107 export SDL_VIDEODRIVER=dummy
108 export SDL_AUDIODRIVER=disk
109 # traceback for segfaults
110 export PYTHONFAULTHANDLER=1
111
112 ${python.interpreter} -m pygame.tests -v \
113 --exclude opengl,timing \
114 --time_out 300
115
116 runHook postCheck
117 '';
118 pythonImportsCheck = [ "pygame" ];
119
120 meta = {
121 description = "Python library for games";
122 homepage = "https://www.pygame.org/";
123 changelog = "https://github.com/pygame/pygame/releases/tag/${src.tag}";
124 license = lib.licenses.lgpl21Plus;
125 maintainers = with lib.maintainers; [ emilytrau ];
126 platforms = lib.platforms.unix;
127 };
128}