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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
|
{
stdenv,
lib,
fetchFromGitHub,
fetchpatch,
fetchzip,
autoconf,
automake,
libtool,
makeWrapper,
pkg-config,
cmake,
yasm,
python3Packages,
libxcrypt,
libgcrypt,
libgpg-error,
libunistring,
boost,
avahi,
lame,
gettext,
pcre-cpp,
yajl,
fribidi,
which,
openssl,
gperf,
tinyxml,
tinyxml-2,
taglib,
libssh,
jre_headless,
gtest,
ncurses,
spdlog,
libxml2,
alsa-lib,
libGLU,
libGL,
ffmpeg,
fontconfig,
freetype,
ftgl,
libjpeg,
libpng,
libtiff,
libmpeg2,
libsamplerate,
libmad,
libogg,
libvorbis,
flac,
libxslt,
lzo,
libcdio,
libmodplug,
libass,
libbluray,
libudfread,
sqlite,
libmysqlclient,
nasm,
gnutls,
libva,
libdrm,
curl,
bzip2,
zip,
unzip,
mesa-demos,
libcec,
libcec_platform,
dcadec,
libuuid,
libcrossguid,
libmicrohttpd,
bluez,
doxygen,
giflib,
glib,
harfbuzz,
lcms2,
libidn2,
libpthread-stubs,
libtasn1,
libplist,
p11-kit,
zlib,
flatbuffers,
fstrcmp,
rapidjson,
lirc,
mesa-gl-headers,
x11Support ? true,
libx11,
xorgproto,
libxt,
libxmu,
libxext,
libxinerama,
libxrandr,
libxtst,
libxfixes,
xdpyinfo,
libxdmcp,
dbusSupport ? true,
dbus,
nfsSupport ? true,
libnfs,
pulseSupport ? true,
libpulseaudio,
pipewireSupport ? true,
pipewire,
rtmpSupport ? true,
rtmpdump,
sambaSupport ? true,
samba,
udevSupport ? true,
udev,
opticalSupport ? true,
usbSupport ? false,
libusb-compat-0_1,
vdpauSupport ? true,
libvdpau,
waylandSupport ? false,
wayland,
wayland-protocols,
waylandpp ? null,
libxkbcommon,
gbmSupport ? false,
libgbm,
libinput,
libdisplay-info,
buildPackages,
}:
assert usbSupport -> !udevSupport; # libusb-compat-0_1 won't be used if udev is available
assert gbmSupport || waylandSupport || x11Support;
let
# see https://github.com/xbmc/xbmc/blob/${kodiVersion}-${rel}/tools/depends/target/ to get suggested versions for all dependencies
# We can build these externally but FindLibDvd.cmake forces us to build it
# them, so we currently just use them for the src.
libdvdcss = fetchFromGitHub {
owner = "xbmc";
repo = "libdvdcss";
rev = "1.4.3-Next-Nexus-Alpha2-2";
sha256 = "sha256-CJMGH50mNAkovccNcol5ArF3zUnZKfbVB9EXyQgu5k4=";
};
libdvdnav = fetchFromGitHub {
owner = "xbmc";
repo = "libdvdnav";
rev = "6.1.1-Next-Nexus-Alpha2-2";
sha256 = "sha256-m8SCjOokVbwJ7eVfYKHap1pQjVbI+BXaoxhGZQIg0+k=";
};
libdvdread = fetchFromGitHub {
owner = "xbmc";
repo = "libdvdread";
rev = "6.1.3-Next-Nexus-Alpha2-2";
sha256 = "sha256-AphBQhXud+a6wm52zjzC5biz53NnqWdgpL2QDt2ZuXc=";
};
groovy = fetchzip {
url = "mirror://apache/groovy/4.0.16/distribution/apache-groovy-binary-4.0.16.zip";
sha256 = "sha256-OfZBiMVrhw6VqHRHCSC7ZV3FiZ26n4+F8hsskk+L6yU=";
};
apache_commons_lang = fetchzip {
url = "mirror://apache/commons/lang/binaries/commons-lang3-3.14.0-bin.zip";
sha512 = "sha512-eKF1IQ6PDtifb4pMHWQ2SYHIh0HbMi3qpc92lfbOo3uSsFJVR3n7JD0AdzrG17tLJQA4z5PGDhwyYw0rLeLsXw==";
};
apache_commons_text = fetchzip {
url = "mirror://apache/commons/text/binaries/commons-text-1.11.0-bin.zip";
sha512 = "sha512-P2IvnrHSYRF70LllTMI8aev43h2oe8lq6rrMYw450PEhEa7OuuCjh1Krnc/A4OqENUcidVAAX5dK1RAsZHh8Dg==";
};
kodi_platforms =
lib.optional gbmSupport "gbm"
++ lib.optional waylandSupport "wayland"
++ lib.optional x11Support "x11";
in
stdenv.mkDerivation (
finalAttrs:
let
texturePacker = buildPackages.callPackage (
{
cmake,
giflib,
libjpeg,
libpng,
lzo,
stdenv,
zlib,
pkg-config,
}:
stdenv.mkDerivation {
pname = finalAttrs.pname + "-build-tool-texture-packer";
inherit (finalAttrs) version src;
sourceRoot = "${finalAttrs.src.name}/tools/depends/native/TexturePacker/src";
nativeBuildInputs = [
pkg-config
cmake
];
buildInputs = [
giflib
libjpeg
libpng
lzo
zlib
];
env.NIX_CFLAGS_COMPILE = lib.optionalString (!stdenv.hostPlatform.isWindows) "-DTARGET_POSIX";
preConfigure = ''
cmakeFlagsArray+=(-DKODI_SOURCE_DIR=$src -DCMAKE_MODULE_PATH=$src/cmake/modules)
'';
meta.mainProgram = "TexturePacker";
}
) { };
jsonSchemaBuilder = buildPackages.callPackage (
{ stdenv, cmake }:
stdenv.mkDerivation {
pname = finalAttrs.pname + "-build-tool-json-schema-builder";
inherit (finalAttrs) version src;
sourceRoot = "${finalAttrs.src.name}/tools/depends/native/JsonSchemaBuilder/src";
nativeBuildInputs = [ cmake ];
meta.mainProgram = "JsonSchemaBuilder";
}
) { };
in
{
pname = "kodi";
version = "21.3";
kodiReleaseName = "Omega";
src = fetchFromGitHub {
owner = "xbmc";
repo = "xbmc";
rev = "${finalAttrs.version}-${finalAttrs.kodiReleaseName}";
hash = "sha256-36wBAqGEDCRZ4t1ygTg03Pyk7Gg9quUTUGD3SBp6nCk=";
};
patches = [
# TexturePacker has some conditionals on GIFLIB 5, which break with
# GIFLIB 6. This has been extended to support all versions >= 5 upstream,
# but has not yet made it into a release.
# https://github.com/xbmc/xbmc/pull/28016
(fetchpatch {
name = "texturepacker-giflib-6.patch";
url = "https://github.com/xbmc/xbmc/commit/29492cbd20d4c90a9c00a30ab525d4d0e81a968b.patch";
hash = "sha256-WNaODPCtRfn30jVU5HbBnAO2Vl/MQp2CYmKOTTyDGZI=";
})
];
# make derivations declared in the let binding available here, so
# they can be overridden
inherit
libdvdcss
libdvdnav
libdvdread
groovy
apache_commons_lang
apache_commons_text
;
buildInputs = [
gnutls
libidn2
libtasn1
nasm
p11-kit
libxml2
python3Packages.python
boost
libmicrohttpd
gettext
pcre-cpp
yajl
fribidi
libva
libdrm
openssl
gperf
tinyxml
tinyxml-2
taglib
libssh
ncurses
spdlog
alsa-lib
libGL
libGLU
fontconfig
freetype
ftgl
libjpeg
libpng
libtiff
libmpeg2
libsamplerate
libmad
libogg
libvorbis
flac
libxslt
lzo
libcdio
libmodplug
libass
libbluray
libudfread
sqlite
libmysqlclient
avahi
lame
curl
bzip2
zip
unzip
mesa-demos
libcec
libcec_platform
dcadec
libuuid
libxcrypt
libgcrypt
libgpg-error
libunistring
libcrossguid
libplist
bluez
glib
harfbuzz
lcms2
libpthread-stubs
ffmpeg
flatbuffers
fstrcmp
rapidjson
lirc
mesa-gl-headers
# Deps needed by TexturePacker, which is built and installed in normal
# kodi build, however the one used during the build is not this one
# in order to support cross-compilation.
giflib
zlib
]
++ lib.optionals x11Support [
libx11
xorgproto
libxt
libxmu
libxext.dev
libxdmcp
libxinerama
libxrandr.dev
libxtst
libxfixes
]
++ lib.optional dbusSupport dbus
++ lib.optional nfsSupport libnfs
++ lib.optional pulseSupport libpulseaudio
++ lib.optional pipewireSupport pipewire
++ lib.optional rtmpSupport rtmpdump
++ lib.optional sambaSupport samba
++ lib.optional udevSupport udev
++ lib.optional usbSupport libusb-compat-0_1
++ lib.optional vdpauSupport libvdpau
++ lib.optionals waylandSupport [
wayland
waylandpp.dev
wayland-protocols
# Not sure why ".dev" is needed here, but CMake doesn't find libxkbcommon otherwise
libxkbcommon.dev
]
++ lib.optionals gbmSupport [
libxkbcommon.dev
libgbm
libinput.dev
libdisplay-info
];
nativeBuildInputs = [
cmake
doxygen
makeWrapper
which
pkg-config
autoconf
automake
libtool # still needed for some components. Check if that is the case with 19.0
jre_headless
yasm
gettext
python3Packages.python
flatbuffers
]
++ lib.optionals waylandSupport [
wayland-protocols
waylandpp.bin
];
nativeCheckInputs = [
gtest
];
depsBuildBuild = [
buildPackages.stdenv.cc
];
cmakeFlags = [
"-DAPP_RENDER_SYSTEM=${if gbmSupport then "gles" else "gl"}"
"-Dlibdvdcss_URL=${finalAttrs.libdvdcss}"
"-Dlibdvdnav_URL=${finalAttrs.libdvdnav}"
"-Dlibdvdread_URL=${finalAttrs.libdvdread}"
"-Dgroovy_SOURCE_DIR=${finalAttrs.groovy}"
"-Dapache-commons-lang_SOURCE_DIR=${finalAttrs.apache_commons_lang}"
"-Dapache-commons-text_SOURCE_DIR=${finalAttrs.apache_commons_text}"
# Upstream derives this from the git HEADs hash and date.
# LibreElec (minimal distro for kodi) uses the equivalent to this.
"-DGIT_VERSION=${finalAttrs.version}-${finalAttrs.kodiReleaseName}"
"-DENABLE_EVENTCLIENTS=ON"
"-DENABLE_INTERNAL_CROSSGUID=OFF"
"-DENABLE_INTERNAL_RapidJSON=OFF"
"-DENABLE_OPTICAL=${if opticalSupport then "ON" else "OFF"}"
"-DENABLE_VDPAU=${if vdpauSupport then "ON" else "OFF"}"
"-DLIRC_DEVICE=/run/lirc/lircd"
"-DSWIG_EXECUTABLE=${buildPackages.swig}/bin/swig"
"-DFLATBUFFERS_FLATC_EXECUTABLE=${buildPackages.flatbuffers}/bin/flatc"
"-DPYTHON_EXECUTABLE=${buildPackages.python3Packages.python}/bin/python"
"-DPYTHON_LIB_PATH=${python3Packages.python.sitePackages}"
"-DWITH_JSONSCHEMABUILDER=${lib.getExe jsonSchemaBuilder}"
# When wrapped KODI_HOME will likely contain symlinks to static assets
# that Kodi's built in webserver will cautiously refuse to serve up
# (because their realpaths are outside of KODI_HOME and the other
# whitelisted directories). This adds the entire nix store to the Kodi
# webserver whitelist to avoid this problem.
"-DKODI_WEBSERVER_EXTRA_WHITELIST=${builtins.storeDir}"
]
++ lib.optionals waylandSupport [
"-DWAYLANDPP_SCANNER=${buildPackages.waylandpp}/bin/wayland-scanner++"
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"-DWITH_TEXTUREPACKER=${lib.getExe texturePacker}"
];
doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
checkPhase = ''
runHook preCheck
make -j $NIX_BUILD_CORES kodi-test
./kodi-test --gtest_filter=-${
lib.concatStringsSep ":" [
"TestCPUInfo.GetCPUFrequency"
"TestNetwork.PingHost"
"TestSystemInfo.GetOsName"
"TestSystemInfo.GetOsPrettyNameWithVersion"
]
}
runHook postCheck
'';
preConfigure = ''
cmakeFlagsArray+=("-DCORE_PLATFORM_NAME=${lib.concatStringsSep " " kodi_platforms}")
'';
postInstall = ''
# TODO: figure out which binaries should be wrapped this way and which shouldn't
for p in $(ls --ignore=kodi-send $out/bin/) ; do
wrapProgram $out/bin/$p \
--prefix PATH ":" "${
lib.makeBinPath (
[
python3Packages.python
mesa-demos
]
++ lib.optional x11Support xdpyinfo
++ lib.optional sambaSupport samba
)
}" \
--prefix LD_LIBRARY_PATH ":" "${
lib.makeLibraryPath (
[
curl
libmad
libcec
libcec_platform
libass
]
++ lib.optional vdpauSupport libvdpau
++ lib.optional nfsSupport libnfs
++ lib.optional rtmpSupport rtmpdump
)
}"
done
wrapProgram $out/bin/kodi-send \
--prefix PYTHONPATH : $out/${python3Packages.python.sitePackages}
substituteInPlace $out/share/xsessions/kodi.desktop \
--replace kodi-standalone $out/bin/kodi-standalone
'';
doInstallCheck = true;
installCheckPhase = "$out/bin/kodi --version";
passthru = {
pythonPackages = python3Packages;
ffmpeg = ffmpeg;
kodi = finalAttrs.finalPackage;
};
meta = {
description = "Media center";
homepage = "https://kodi.tv/";
license = lib.licenses.gpl2Plus;
platforms = lib.platforms.linux;
teams = [ lib.teams.kodi ];
mainProgram = "kodi";
};
}
)
|