1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
{
lib,
stdenv,
config,
fetchFromGitHub,
nix-update-script,
pkg-config,
libGLSupported ? lib.elem stdenv.hostPlatform.system mesa.meta.platforms,
openglSupport ? libGLSupported,
libGL,
alsaSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
alsa-lib,
x11Support ? !stdenv.hostPlatform.isWindows && !stdenv.hostPlatform.isAndroid,
libX11,
xorgproto,
libICE,
libXi,
libXScrnSaver,
libXcursor,
libXinerama,
libXext,
libXxf86vm,
libXrandr,
waylandSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
wayland,
wayland-protocols,
wayland-scanner,
drmSupport ? false,
libdrm,
mesa,
libxkbcommon,
dbusSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
dbus,
udevSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
udev,
ibusSupport ? false,
ibus,
libdecorSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
libdecor,
pipewireSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
pipewire, # NOTE: must be built with SDL2 without pipewire support
pulseaudioSupport ? config.pulseaudio or stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
libpulseaudio,
AudioUnit,
Cocoa,
CoreAudio,
CoreServices,
ForceFeedback,
OpenGL,
audiofile,
libiconv,
withStatic ? stdenv.hostPlatform.isMinGW,
# passthru.tests
testers,
guile-sdl2,
jazz2,
SDL2_ttf,
SDL2_net,
SDL2_gfx,
SDL2_sound,
SDL2_mixer,
SDL2_image,
python3Packages,
}:
# NOTE: When editing this expression see if the same change applies to
# SDL expression too
stdenv.mkDerivation (finalAttrs: {
pname = "SDL2";
version = "2.30.6";
src = fetchFromGitHub {
owner = "libsdl-org";
repo = "SDL";
rev = "release-${finalAttrs.version}";
hash = "sha256-ij9/VhSacUaPbMGX1hx2nz0n8b1tDb1PnC7IO9TlNhE=";
};
dontDisableStatic = if withStatic then 1 else 0;
outputs = [
"out"
"dev"
];
outputBin = "dev"; # sdl-config
patches = [
# `sdl2-config --cflags` from Nixpkgs returns include path to just SDL2.
# On a normal distro this is enough for includes from all SDL2* packages to work,
# but on NixOS they're spread across different paths.
# This patch + the setup-hook will ensure that `sdl2-config --cflags` works correctly.
./find-headers.patch
];
postPatch = ''
# Fix running wayland-scanner for the build platform when cross-compiling.
# See comment here: https://github.com/libsdl-org/SDL/issues/4860#issuecomment-1119003545
substituteInPlace configure \
--replace '$(WAYLAND_SCANNER)' 'wayland-scanner'
'';
strictDeps = true;
depsBuildBuild = [ pkg-config ];
nativeBuildInputs =
[ pkg-config ]
++ lib.optionals waylandSupport [
wayland
wayland-scanner
];
dlopenPropagatedBuildInputs =
[ ]
# Propagated for #include <GLES/gl.h> in SDL_opengles.h.
++ lib.optional (openglSupport && !stdenv.isDarwin) libGL
# Propagated for #include <X11/Xlib.h> and <X11/Xatom.h> in SDL_syswm.h.
++ lib.optionals x11Support [ libX11 ];
propagatedBuildInputs =
lib.optionals x11Support [ xorgproto ] ++ finalAttrs.dlopenPropagatedBuildInputs;
dlopenBuildInputs =
lib.optionals alsaSupport [
alsa-lib
audiofile
]
++ lib.optional dbusSupport dbus
++ lib.optional libdecorSupport libdecor
++ lib.optional pipewireSupport pipewire
++ lib.optional pulseaudioSupport libpulseaudio
++ lib.optional udevSupport udev
++ lib.optionals waylandSupport [
wayland
libxkbcommon
]
++ lib.optionals x11Support [
libICE
libXi
libXScrnSaver
libXcursor
libXinerama
libXext
libXrandr
libXxf86vm
]
++ lib.optionals drmSupport [
libdrm
mesa
];
buildInputs =
[ libiconv ]
++ finalAttrs.dlopenBuildInputs
++ lib.optional ibusSupport ibus
++ lib.optionals waylandSupport [ wayland-protocols ]
++ lib.optionals stdenv.isDarwin [
AudioUnit
Cocoa
CoreAudio
CoreServices
ForceFeedback
OpenGL
];
enableParallelBuilding = true;
configureFlags =
[ "--disable-oss" ]
++ lib.optional (!x11Support) "--without-x"
++ lib.optional alsaSupport "--with-alsa-prefix=${alsa-lib.out}/lib"
++ lib.optional stdenv.hostPlatform.isWindows "--disable-video-opengles"
++ lib.optional stdenv.isDarwin "--disable-sdltest";
# We remove libtool .la files when static libs are requested,
# because they make the builds of downstream libs like `SDL_tff`
# fail with `cannot find -lXext, `-lXcursor` etc. linker errors
# because the `.la` files are not pruned if static libs exist
# (see https://github.com/NixOS/nixpkgs/commit/fd97db43bcb05e37f6bb77f363f1e1e239d9de53)
# and they also don't carry the necessary `-L` paths of their
# X11 dependencies.
# For static linking, it is better to rely on `pkg-config` `.pc`
# files.
postInstall = ''
if [ "$dontDisableStatic" -eq "1" ]; then
rm $out/lib/*.la
else
rm $out/lib/*.a
fi
moveToOutput bin/sdl2-config "$dev"
'';
# SDL is weird in that instead of just dynamically linking with
# libraries when you `--enable-*` (or when `configure` finds) them
# it `dlopen`s them at runtime. In principle, this means it can
# ignore any missing optional dependencies like alsa, pulseaudio,
# some x11 libs, wayland, etc if they are missing on the system
# and/or work with wide array of versions of said libraries. In
# nixpkgs, however, we don't need any of that. Moreover, since we
# don't have a global ld-cache we have to stuff all the propagated
# libraries into rpath by hand or else some applications that use
# SDL API that requires said libraries will fail to start.
#
# You can grep SDL sources with `grep -rE 'SDL_(NAME|.*_SYM)'` to
# list the symbols used in this way.
postFixup =
let
rpath = lib.makeLibraryPath (
finalAttrs.dlopenPropagatedBuildInputs ++ finalAttrs.dlopenBuildInputs
);
in
lib.optionalString (stdenv.hostPlatform.extensions.sharedLibrary == ".so") ''
for lib in $out/lib/*.so* ; do
if ! [[ -L "$lib" ]]; then
patchelf --set-rpath "$(patchelf --print-rpath $lib):${rpath}" "$lib"
fi
done
'';
setupHook = ./setup-hook.sh;
passthru = {
inherit openglSupport;
updateScript = nix-update-script {
extraArgs = [
"--version-regex"
"release-(.*)"
];
};
tests = {
pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; };
inherit
guile-sdl2
jazz2
SDL2_ttf
SDL2_net
SDL2_gfx
SDL2_sound
SDL2_mixer
SDL2_image
;
inherit (python3Packages) pygame pygame-ce pygame-sdl2;
};
};
meta = with lib; {
description = "Cross-platform multimedia library";
mainProgram = "sdl2-config";
homepage = "http://www.libsdl.org/";
changelog = "https://github.com/libsdl-org/SDL/releases/tag/release-${finalAttrs.version}";
license = licenses.zlib;
platforms = platforms.all;
maintainers = lib.teams.sdl.members;
pkgConfigModules = [ "sdl2" ];
};
})
|