Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
1265 lines (1181 loc) · 50.5 KB
/
Copy pathflake.nix
File metadata and controls
1265 lines (1181 loc) · 50.5 KB
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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
description = "Spool build environment";
nixConfig = {
extra-substituters = [ "https://spool.cachix.org" ];
extra-trusted-public-keys = [ "spool.cachix.org-1:yx+E3raAGXiyUNoMEscSu9c85b+WbgoV7swqyY8oL6s=" ];
};
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Nixpkgs 26.11 dropped x86_64-darwin, so Intel macOS builds track the
# 26.05 darwin branch, which is maintained to the end of 2026.
nixpkgs-x86-darwin.url = "github:NixOS/nixpkgs/nixpkgs-26.05-darwin";
libplacebo-src = {
url = "github:haasn/libplacebo/a7a18af88ff0a17c04840dcb3246047bb6b46df3?submodules=1";
flake = false;
};
qcoro-src = {
url = "github:danvratil/qcoro/d1b52b5db2ff9560185c39a4ed9f944dc610c235";
flake = false;
};
mpv-src = {
url = "git+file:./mpv";
flake = false;
};
};
outputs = { self, nixpkgs, nixpkgs-x86-darwin, libplacebo-src, qcoro-src, mpv-src, ... }:
let
systems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ];
androidToolchain =
builtins.fromJSON (builtins.readFile ./tools/manifests/qt-android-6.11.json);
androidSdkArgs = {
platformVersions = [ androidToolchain.android.compileSdk ];
buildToolsVersions = [ androidToolchain.android.buildTools ];
includeNDK = true;
ndkVersions = [ androidToolchain.android.ndkVersion ];
};
androidEnvironment = pkgs:
let
# The root nixpkgs input is nixos-unstable. Keep the emulator on
# that binary-packaged channel rather than following nixpkgs master.
composition = pkgs.androidenv.composeAndroidPackages androidSdkArgs;
emulator = pkgs.androidenv.emulateApp {
name = "spool-android-emulator";
platformVersion = "36";
abiVersion = "x86_64";
systemImageType = "google_apis";
configOptions = {
"hw.keyboard" = "yes";
"hw.ramSize" = "4096";
"vm.heapSize" = "512";
};
sdkExtraArgs = androidSdkArgs;
androidEmulatorFlags =
"-no-window -no-audio -no-boot-anim -no-snapshot -gpu swangle";
};
tvEmulator = pkgs.androidenv.emulateApp {
name = "spool-android-tv-emulator";
deviceName = "spool-android-tv";
# The pinned SDK metadata contains this actual Android TV image,
# including its x86_64 ABI; do not merely toggle the app's TV flag.
platformVersion = "36";
abiVersion = "x86_64";
systemImageType = "android-tv";
configOptions = {
"hw.keyboard" = "yes";
"hw.dPad" = "yes";
"hw.touchScreen" = "no";
"hw.lcd.width" = "1920";
"hw.lcd.height" = "1080";
"hw.lcd.density" = "320";
"hw.ramSize" = "3072";
"vm.heapSize" = "512";
};
sdkExtraArgs = androidSdkArgs;
androidEmulatorFlags =
"-no-window -no-audio -no-boot-anim -no-snapshot -gpu swangle -cores 2";
};
in {
sdk = composition.androidsdk;
inherit emulator tvEmulator;
};
# Only Intel macOS needs the older branch; every other system stays on
# the pin the rest of the project is built and tested against.
nixpkgsFor = system:
if system == "x86_64-darwin" then nixpkgs-x86-darwin else nixpkgs;
# tools/manifests/toolchain.json is the single place the Qt and FFmpeg
# versions are set. Everything below reads it rather than repeating a
# version of its own, so no channel can drift a platform off the pin.
toolchain = builtins.fromJSON (builtins.readFile ./tools/manifests/toolchain.json);
ffmpegPin = toolchain.ffmpeg;
# Our own FFmpeg, not the channel's: every system builds the same
# upstream release regardless of which nixpkgs it came in on.
spoolFfmpegFor = pkgs:
let pinned = base: (base.override {
inherit (ffmpegPin) version;
# The release tarball the webOS and Android cross builds fetch,
# rather than the channel's git checkout, so every platform is
# building the same bytes.
source = pkgs.fetchurl { inherit (ffmpegPin) url; hash = ffmpegPin.sri; };
}).overrideAttrs (old: {
# Keep the genuine HLS seek fixture/reference unchanged across
# CPU counts; the direct generator otherwise auto-slices video.
patches = (old.patches or []) ++ [
./tools/patches/ffmpeg-fate-hls-fixed-slice-count.patch
];
});
in
if pkgs ? ffmpeg_9-full
then pinned pkgs.ffmpeg_9-full
# The x86_64-darwin maintenance branch predates FFmpeg 9. Its generic
# derivation supports newer upstream versions; discard its two obsolete
# FFmpeg 8 configure switches when building the newer source.
else (pinned (pkgs.ffmpeg-full.override { withCelt = false; })).overrideAttrs (old: {
configureFlags = builtins.filter (flag:
!builtins.elem flag [ "--disable-libcelt" "--disable-libshaderc" ])
old.configureFlags;
});
libplaceboOverlay = final: prev: {
spoolLibplacebo = prev.libplacebo.overrideAttrs (_: {
version = "master-a7a18af";
src = libplacebo-src;
patches = [];
});
};
mesaTestOverlay = final: prev: {
# Keep Qt/Weston and normal desktop drivers unchanged. Only the
# explicitly selected isolated CPU test drivers use this WSI fix.
spoolTestMesa = prev.mesa.overrideAttrs (old: {
patches = (old.patches or []) ++ [
./tools/patches/mesa-wayland-fifo-presentation-clock.patch
];
});
};
ffmpegCapabilities =
builtins.fromJSON (builtins.readFile ./tools/manifests/ffmpeg-capabilities.json);
ffmpegConfigureFlags = platform:
let
enableEach = kind: values: map (value: "--enable-${kind}=${value}") values;
platformConfig = ffmpegCapabilities.platforms.${platform};
protocols = ffmpegCapabilities.protocols ++ platformConfig.protocols;
in
ffmpegCapabilities.requiredDisableFlags
++ ffmpegCapabilities.commonConfigureFlags
++ nixpkgs.lib.optional platformConfig.gpl "--enable-gpl"
++ platformConfig.configureFlags
++ map (library: "--enable-${library}") ffmpegCapabilities.libraries
++ enableEach "protocol" protocols
++ enableEach "demuxer" ffmpegCapabilities.demuxers
++ enableEach "parser" ffmpegCapabilities.parsers
++ enableEach "decoder" ffmpegCapabilities.decoders
++ enableEach "encoder" ffmpegCapabilities.encoders
++ enableEach "filter" ffmpegCapabilities.filters
++ enableEach "muxer" ffmpegCapabilities.muxers
++ enableEach "bsf" (ffmpegCapabilities.bitstreamFilters ++ (platformConfig.bitstreamFilters or []))
++ enableEach "hwaccel" platformConfig.hardwareAccelerators;
ffmpegSlimOverlay = final: prev:
let
platform = if final.stdenv.hostPlatform.isDarwin then "macos" else "linux";
structuralEnableFlags = [
"--enable-asm"
"--enable-fast-unaligned"
"--enable-hardcoded-tables"
"--enable-inline-asm"
"--enable-optimizations"
"--enable-pic"
"--enable-pthreads"
"--enable-rpath"
"--enable-runtime-cpudetect"
"--enable-safe-bitstream-reader"
"--enable-shared"
"--enable-stripping"
"--enable-swscale-alpha"
"--enable-x86asm"
];
keepInheritedFlag = flag:
!(nixpkgs.lib.hasPrefix "--enable-" flag)
|| builtins.elem flag structuralEnableFlags;
in {
spoolFfmpeg = ((spoolFfmpegFor prev).override
(nixpkgs.lib.genAttrs ffmpegCapabilities.disabledNixFeatures (_: false))).overrideAttrs (old: {
doCheck = false;
configureFlags =
builtins.filter keepInheritedFlag old.configureFlags
++ ffmpegConfigureFlags platform
# Darwin ld64 emits invalid chained fixups for this FFmpeg build.
++ nixpkgs.lib.optionals final.stdenv.hostPlatform.isDarwin [
"--extra-ldflags=-Wl,-no_fixup_chains"
];
postInstall = (old.postInstall or "") + ''
mkdir -p "$bin/bin" "$data/share/ffmpeg" "$doc/share/doc/ffmpeg" "$man/share/man"
'';
});
};
pinnedQtOverlay = final: prev:
let
srcs = builtins.mapAttrs (name: sha256: {
version = toolchain.qt.version;
src = final.fetchurl {
url = "${toolchain.qt.baseUrl}/${name}-everywhere-src-${toolchain.qt.version}.tar.xz";
inherit sha256;
};
}) toolchain.qt.sources;
in {
qt6 = (prev.qt6.overrideScope (_qtFinal: qtPrev: {
inherit srcs;
# qtbase takes its source directly; the other modules use qtModule.
qtbase = qtPrev.qtbase.override { inherit (srcs.qtbase) src version; };
qtModule = qtPrev.qtModule.override { inherit srcs; };
qtdeclarative = qtPrev.qtdeclarative.overrideAttrs (old: {
# The Intel maintenance channel backports this TableView fix.
# It is already in the pinned Qt release; applying it again fails.
patches = builtins.filter (patch:
!final.lib.hasSuffix "8a2c82be6ad90e3f2a0760d8bab1e3a8cdb2473a.diff" (toString patch))
(old.patches or []);
});
})) // {
override = prev.qt6.override;
};
};
tailoredQtOverlay = final: prev: {
spoolQt6 = (prev.qt6.overrideScope (qtFinal: qtPrev: {
qtbase = (qtPrev.qtbase.override {
systemdSupport = false;
withGtk3 = false;
}).overrideAttrs (old: {
patches = (old.patches or []) ++ final.lib.optional final.stdenv.hostPlatform.isDarwin
./tools/patches/qt-cocoa-pending-fullscreen-state.patch;
# Both desktop renderers share Qt's Vulkan device with libplacebo;
# macOS supplies the Vulkan implementation through MoltenVK.
propagatedBuildInputs = builtins.filter (input:
input != final.glib
&& input != final.icu
&& input != final.unixodbc
&& input != final.unixodbcDrivers.mariadb
&& input != final.unixodbcDrivers.psql
&& input != final.unixodbcDrivers.sqlite
&& (!final.stdenv.hostPlatform.isLinux || input != final.systemd))
old.propagatedBuildInputs;
buildInputs = builtins.filter (input:
input != final.libmysqlclient
&& input != final.libpq)
old.buildInputs;
cmakeFlags = old.cmakeFlags
++ final.lib.optional (!(builtins.elem "-DQT_FEATURE_vulkan=ON" old.cmakeFlags))
"-DQT_FEATURE_vulkan=ON"
++ [
"-DQT_FEATURE_glib=OFF"
"-DQT_FEATURE_icu=OFF"
"-DQT_FEATURE_sql_mysql=OFF"
"-DQT_FEATURE_sql_odbc=OFF"
"-DQT_FEATURE_sql_psql=OFF"
];
postFixup = builtins.replaceStrings [
''patchelf --add-rpath "${final.libmysqlclient}/lib/mariadb" $out/lib/qt-6/plugins/sqldrivers/libqsqlmysql.so''
] [ "" ] (old.postFixup or "");
});
qtdeclarative = qtPrev.qtdeclarative.overrideAttrs (old: {
# The channel explicitly names its untailored host qsb. Use this
# scope's tool so building QML does not build a second native Qt.
cmakeFlags = builtins.filter (flag:
!final.lib.hasPrefix "-DQt6ShaderToolsTools_DIR=" flag) old.cmakeFlags
++ [ "-DQt6ShaderToolsTools_DIR=${qtFinal.qtshadertools}/lib/cmake/Qt6ShaderToolsTools" ];
});
})) // {
# pythonPackages.qt6 expects this secondary package scope.
override = prev.qt6.override;
};
};
qcoroOverlay = final: prev: {
spoolQcoro = (prev.qt6Packages.qcoro.override {
qtbase = final.spoolQt6.qtbase;
qtwebsockets = final.spoolQt6.qtwebsockets;
wrapQtAppsHook = final.spoolQt6.wrapQtAppsHook;
}).overrideAttrs (old: {
version = "0.13.0";
src = qcoro-src;
meta = old.meta // {
platforms = old.meta.platforms ++ final.lib.platforms.darwin;
};
});
};
cacheDependencyOverlay = final: prev: {
# Keep cached releases on the same vulnerability-fixed FFmpeg major.
spoolFfmpeg = (spoolFfmpegFor prev).overrideAttrs (_: { doCheck = false; });
};
forAllSystems = f:
nixpkgs.lib.genAttrs systems (system:
f (import (nixpkgsFor system) {
inherit system;
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
overlays = [ pinnedQtOverlay libplaceboOverlay mesaTestOverlay ffmpegSlimOverlay tailoredQtOverlay qcoroOverlay ];
}));
# Native artifacts use a tailored Qt without ICU, foreign SQL drivers
# or GTK. Release jobs retain the full build closure in GitHub
# Actions; Cachix receives only the runtime and development outputs that
# keep `nix run` from compiling Qt.
cachePkgsFor = system:
import (nixpkgsFor system) {
inherit system;
config.allowUnfree = true;
overlays = [ pinnedQtOverlay libplaceboOverlay mesaTestOverlay tailoredQtOverlay qcoroOverlay cacheDependencyOverlay ];
};
# Shared build/media dependencies. Intentionally contains no qt6.* packages.
# The Qt source build must not see nixpkgs Qt through CMAKE_PREFIX_PATH.
basePackages = pkgs: with pkgs; [
autoconf
automake
bashInteractive
bison
cacert
ccache
cmake
curl
expat
spoolFfmpeg
file
findutils
flex
fontconfig
freetype
git
gnumake
imagemagick
jq
lcms2
libarchive
libass
libbluray
libffi
spoolLibplacebo
libtool
libuchardet
libxkbcommon
lua5_2
luajit
meson
mujs
ninja
nodejs_22
patchelf
pcre2
perl
pkg-config
python3
rubberband
rustup
unzip
# mpv's Vulkan feature needs the headers and a loader to link against.
# The driver is the user's, found through the loader at runtime.
vulkan-headers
vulkan-loader
which
zlib
zip
];
dwarfsTools = pkgs: pkgs.stdenvNoCC.mkDerivation {
pname = "dwarfs-tools";
version = "0.14.0";
src = pkgs.fetchurl {
url = "https://github.com/mhx/dwarfs/releases/download/v0.14.0/dwarfs-0.14.0-Linux-x86_64.tar.xz";
hash = "sha256-KyU67IIkNDenkT6Kh4lE2Wp6swijhh1ZzkGqoV4UCa0=";
};
dontBuild = true;
installPhase = ''
runHook preInstall
mkdir -p "$out"
cp -R bin share sbin "$out/"
runHook postInstall
'';
};
zstdSource = pkgs:
let
pin = (builtins.fromJSON (builtins.readFile ./tools/manifests/android-third-party.json)).sources.zstd;
archive = pkgs.fetchurl { inherit (pin) url sha256; };
in pkgs.runCommand "spool-zstd-${pin.version}-source" {} ''
mkdir -p "$out"
tar -xzf "${archive}" --strip-components=1 -C "$out"
'';
sourceLinuxPackages = pkgs: with pkgs; [
alsa-lib
appimage-run
(dwarfsTools pkgs)
expat
libICE
libdrm
libpulseaudio
libsecret
libGL
libSM
libva
libvdpau
libx11
libxext
libxpresent
libxrandr
libxscrnsaver
mesa
nv-codec-headers-11
pipewire
shaderc
squashfsTools
spirv-cross
wayland
# Executed during native client builds, not a target Wayland binary.
buildPackages.wayland-scanner
wayland-protocols
zimg
];
darwinPackages = pkgs: with pkgs; [
apple-sdk_15
create-dmg
libiconvReal
moltenvk
vulkan-headers
vulkan-loader
];
# Native release builds do not need the webOS Qt toolchain, JavaScript
# interpreter, Rust, AppImage emulation or debugger stack. libmpv still
# enables Lua scripting on Linux and macOS.
nativeBasePackages = pkgs: with pkgs; [
bashInteractive
binutils
cacert
ccache
cmake
curl
spoolFfmpeg
file
findutils
fontconfig
freetype
git
gnumake
imagemagick
jq
lcms2
libarchive
libass
libbluray
libffi
spoolLibplacebo
libuchardet
libxkbcommon
lua5_2
meson
ninja
patchelf
pcre2
perl
pkg-config
python3
# The slim playback closure deliberately has no ffmpeg CLI/encoders;
# app-journey creates its finite FFV1 fixture with the full pinned CLI.
(lib.getBin (spoolFfmpegFor pkgs))
tesseract
rubberband
unzip
which
zlib
zip
];
nativeLinuxPackages = pkgs:
(builtins.filter (package: package != pkgs.appimage-run)
(sourceLinuxPackages pkgs))
# zstd compresses the portable Linux tarball; see
# tools/package-linux-bundle.sh.
++ [
pkgs.elfutils pkgs.vulkan-loader pkgs.zstd
# Isolated test displays exercise the real Qt/libmpv GPU paths.
pkgs.weston pkgs.xorg-server pkgs.xdotool pkgs.dbus
];
qmlToolWrappers = pkgs: qt:
pkgs.runCommand "qt-qml-tool-wrappers" { nativeBuildInputs = [ pkgs.makeWrapper ]; } ''
mkdir -p "$out/bin"
qml_import_path="${qt.qtdeclarative}/lib/qt-6/qml"
makeWrapper ${qt.qtdeclarative}/bin/qmllint "$out/bin/qmllint" \
--prefix QML2_IMPORT_PATH : "$qml_import_path"
makeWrapper ${qt.qtdeclarative}/bin/qmlformat "$out/bin/qmlformat" \
--prefix QML2_IMPORT_PATH : "$qml_import_path"
makeWrapper ${qt.qtdeclarative}/libexec/qmlcachegen "$out/bin/qmlcachegen" \
--prefix QML2_IMPORT_PATH : "$qml_import_path"
'';
# Shell used by tools/webos-native/build-qt6-611.sh. No nixpkgs Qt here.
sourceBuildPackages = pkgs:
basePackages pkgs
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux (sourceLinuxPackages pkgs)
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin (darwinPackages pkgs);
# Shell used by local native Linux app builds / nix run. This may use
# nixpkgs Qt, but the Qt source-build script should not be run from it.
nativePackages = pkgs:
nativeBasePackages pkgs
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux (nativeLinuxPackages pkgs)
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin (darwinPackages pkgs)
++ (with pkgs; [
spoolQt6.qtbase
spoolQt6.qtdeclarative
spoolQt6.qtimageformats
spoolQt6.qtsvg
spoolQcoro
spoolQt6.qttools
spoolQt6.qtwebsockets
spoolQt6.qtshadertools
(qmlToolWrappers pkgs pkgs.spoolQt6)
])
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux (with pkgs; [
spoolQt6.qtwayland
]);
nativeQtPackages = pkgs:
(with pkgs; [
spoolQt6.qtbase
spoolQt6.qtdeclarative
spoolQt6.qtimageformats
spoolQt6.qtsvg
spoolQt6.qtshadertools
spoolQt6.qtwebsockets
])
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux (with pkgs; [
spoolQt6.qtwayland
]);
nativeRuntimePackages = pkgs:
nativeQtPackages pkgs
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux (nativeLinuxPackages pkgs);
gitHooksShellHook = ''
repo_root="$(git rev-parse --show-toplevel 2>/dev/null || true)"
if [ -n "$repo_root" ] && [ -x "$repo_root/tools/install-git-hooks.sh" ]; then
"$repo_root/tools/install-git-hooks.sh"
fi
unset repo_root
'';
commonShellHook = pkgs: gitHooksShellHook + ''
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
export CURL_CA_BUNDLE="$SSL_CERT_FILE"
export NIX_ENFORCE_PURITY=0
export SPOOL_ZSTD_SOURCE_DIR="${zstdSource pkgs}"
if [ -z "''${WEBOS_SDK_ROOT:-}" ]; then
repo_sdk="$PWD/build/webos-sdk/arm-webos-linux-gnueabi_sdk-buildroot"
workspace_sdk="$PWD/../build/webos-sdk/arm-webos-linux-gnueabi_sdk-buildroot"
if [ -x "$repo_sdk/bin/arm-webos-linux-gnueabi-gcc" ]; then
export WEBOS_SDK_ROOT="$repo_sdk"
elif [ -x "$workspace_sdk/bin/arm-webos-linux-gnueabi-gcc" ]; then
export WEBOS_SDK_ROOT="$workspace_sdk"
else
export WEBOS_SDK_ROOT="$repo_sdk"
fi
unset repo_sdk workspace_sdk
fi
${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
export WAYLAND_PROTOCOLS_DIR="${pkgs.wayland-protocols}/share/wayland-protocols"
''}
${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
export GNU_ICONV_DYLIB="${pkgs.libiconvReal}/lib/libiconv.2.dylib"
export SPOOL_MOLTENVK_ICD="${pkgs.moltenvk}/share/vulkan/icd.d/MoltenVK_icd.json"
export SPOOL_VULKAN_LOADER="${pkgs.vulkan-loader}/lib/libvulkan.1.dylib"
export QT_VULKAN_LIB="''${QT_VULKAN_LIB-$SPOOL_VULKAN_LOADER}"
if [ -z "''${VK_DRIVER_FILES+x}''${VK_ICD_FILENAMES+x}''${VK_ADD_DRIVER_FILES+x}" ]; then
export VK_DRIVER_FILES="$SPOOL_MOLTENVK_ICD"
fi
''}
'';
sourceShellHook = pkgs: commonShellHook pkgs + ''
# Keep the Qt source build hermetic with respect to Qt. mkShell's setup
# hooks may set broad CMake/QML paths; the build script strips these too,
# but clearing them here makes interactive diagnostics less confusing.
unset Qt6_DIR Qt6Core_DIR Qt6Gui_DIR Qt6Widgets_DIR Qt6Qml_DIR Qt6Quick_DIR
unset Qt6CoreTools_DIR Qt6GuiTools_DIR Qt6WidgetsTools_DIR Qt6QmlTools_DIR
unset Qt6ShaderTools_DIR Qt6WaylandClient_DIR Qt6WaylandScannerTools_DIR
unset QT_PLUGIN_PATH QML_IMPORT_PATH QML2_IMPORT_PATH QT_SELECT
export QT_BUILD_CLEAN_POISONED=1
'';
nativeShellHook = pkgs: commonShellHook pkgs + ''
# This shell intentionally includes Spool's tailored nixpkgs Qt
# (spoolQt6) for native Linux/macOS development. Do not use it for
# tools/webos-native/build-qt6-611.sh.
export SPOOL_QT_CMAKE_DIR="${pkgs.spoolQt6.qtbase}/lib/cmake/Qt6"
native_qt_cmake_path="${pkgs.spoolQt6.qtbase}:${pkgs.spoolQt6.qtdeclarative}:${pkgs.spoolQt6.qtsvg}:${pkgs.spoolQt6.qttools}:${pkgs.spoolQt6.qtwebsockets}:${pkgs.spoolQt6.qtshadertools}"
export CMAKE_PREFIX_PATH="$native_qt_cmake_path''${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}"
unset native_qt_cmake_path
export SPOOL_SHELL=1
# macdeployqt and linuxdeploy-plugin-qt both discover plugins under one
# Qt prefix, and every Qt module is a separate store path here. That
# leaves qtimageformats invisible to packaging, so the bundles shipped
# only qtbase's gif/ico/jpeg readers while ArtworkService asks Jellyfin
# for webp. tools/lib/qt-deploy.sh and tools/package-appimage.sh take
# qwebp from this prefix; both then assert it landed.
export SPOOL_QT_EXTRA_PLUGIN_DIRS="${pkgs.spoolQt6.qtimageformats}/lib/qt-6/plugins"
${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isLinux ''
# The test driver opts into these CPU drivers only inside its isolated
# compositor. Do not replace the developer's normal desktop drivers.
export SPOOL_TEST_DRI_DIR="${pkgs.spoolTestMesa}/lib/dri"
export SPOOL_TEST_VULKAN_ICD="$(echo ${pkgs.spoolTestMesa}/share/vulkan/icd.d/lvp_icd.*.json)"
export SPOOL_TEST_DRIVER_LIB_DIR="${pkgs.lib.makeLibraryPath [ pkgs.spoolTestMesa pkgs.libGL pkgs.vulkan-loader ]}"
export SPOOL_TEST_EGL_VENDOR="${pkgs.spoolTestMesa}/share/glvnd/egl_vendor.d/50_mesa.json"
''}
'';
cachedNativeQtPackage = pkgs:
let
packages = nativeQtPackages pkgs ++ [
pkgs.spoolQt6.qttools
pkgs.spoolQcoro
];
in
pkgs.symlinkJoin {
name = "spool-native-qt-${pkgs.spoolQt6.qtbase.version}";
paths = pkgs.lib.unique (packages ++ map pkgs.lib.getDev packages);
};
androidQtHostPackage = pkgs:
let
qt = pkgs.spoolQt6.overrideScope (_qtFinal: qtPrev: {
qtdeclarative = qtPrev.qtdeclarative.overrideAttrs (old: {
# The mobile phase targets share the real app's recursive
# scanner exclusions. Upstream -exclude alone skips only the
# named directory's direct files, not its vendored descendants.
patches = (old.patches or []) ++ [
./tools/webos-native/patches/qtdeclarative-6.11-qmlimportscanner-exclude-subtrees.patch
];
# Match the webOS host-tools profile: without an imported qsb,
# qtdeclarative skips Quick, Controls and styles, not QML tools.
cmakeFlags = builtins.filter (flag:
!pkgs.lib.hasPrefix "-DQt6ShaderToolsTools_DIR=" flag) old.cmakeFlags ++ [
"-DCMAKE_DISABLE_FIND_PACKAGE_Qt6ShaderToolsTools=TRUE"
"-DFEATURE_quick_vectorimage=OFF"
];
});
qttools = qtPrev.qttools.overrideAttrs (old: {
cmakeFlags = old.cmakeFlags ++ [
"-DFEATURE_linguist=ON"
"-DFEATURE_assistant=OFF"
"-DFEATURE_designer=OFF"
"-DFEATURE_distancefieldgenerator=OFF"
"-DFEATURE_pixeltool=OFF"
"-DFEATURE_qdoc=OFF"
"-DFEATURE_qtattributionsscanner=OFF"
"-DFEATURE_qtdiag=OFF"
"-DFEATURE_qtplugininfo=OFF"
];
});
});
# moc/rcc/androiddeployqt, QML generators, qsb and translation tools.
# QtGui remains a dependency of the shader and QML tools; native
# QCoro, WebSockets, image-format plugins and Wayland do not.
packages = with qt; [ qtbase qtdeclarative qtshadertools qttools ];
in pkgs.symlinkJoin {
name = "spool-android-qt-host-${toolchain.qt.version}";
paths = pkgs.lib.unique (packages ++ map pkgs.lib.getDev packages);
};
cachedNativePackage = pkgs:
pkgs.stdenv.mkDerivation {
pname = "spool";
version = pkgs.lib.removeSuffix "\n" (builtins.readFile ./VERSION);
src = builtins.path {
path = self;
name = "spool-source";
filter = path: _: baseNameOf path != "mpv";
};
nativeBuildInputs = nativePackages pkgs ++ [ pkgs.spoolQt6.wrapQtAppsHook ];
SPOOL_ZSTD_SOURCE_DIR = zstdSource pkgs;
dontWrapQtApps = pkgs.stdenv.hostPlatform.isDarwin;
dontConfigure = true;
dontInstall = true;
qtWrapperArgs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux [
"--prefix"
"PATH"
":"
(pkgs.lib.makeBinPath [ pkgs.libsecret ])
];
postUnpack = ''
rm -rf "$sourceRoot/mpv"
cp -R ${mpv-src} "$sourceRoot/mpv"
chmod -R u+w "$sourceRoot/mpv"
'';
buildPhase = ''
patchShebangs mpv/TOOLS
runHook preBuild
export HOME="$TMPDIR/home"
export XDG_CACHE_HOME="$TMPDIR/cache"
export SPOOL_SHELL=1
export SPOOL_QT_CMAKE_DIR="${pkgs.spoolQt6.qtbase}/lib/cmake/Qt6"
export CMAKE_PREFIX_PATH="${pkgs.spoolQt6.qtbase}:${pkgs.spoolQt6.qtdeclarative}:${pkgs.spoolQt6.qtsvg}:${pkgs.spoolQt6.qttools}:${pkgs.spoolQt6.qtwebsockets}:${pkgs.spoolQt6.qtshadertools}''${CMAKE_PREFIX_PATH:+:$CMAKE_PREFIX_PATH}"
mkdir -p "$HOME" "$XDG_CACHE_HOME"
${if pkgs.stdenv.hostPlatform.isDarwin then ''
export PATH="$PATH:/usr/bin:/bin"
BUILD_ROOT="$TMPDIR/spool-build" \
MPV_PREFIX="$out" \
APP_INSTALL="$out/Applications" \
DEPLOY_APP=0 \
SPOOL_MACOS_CREDENTIAL_SERVICE=com.sachk.spool \
bash tools/build-macos.sh
'' else ''
BUILD_ROOT="$TMPDIR/spool-build" \
APP_INSTALL="$out" \
bash tools/build-linux-release.sh
''}
runHook postBuild
'';
meta = {
description = "Spool";
license = pkgs.lib.licenses.gpl3Plus;
platforms = systems;
};
};
in
{
packages = forAllSystems (pkgs: let
cachedPkgs = cachePkgsFor pkgs.stdenv.hostPlatform.system;
in {
default = cachedNativePackage cachedPkgs;
native-cache = cachedNativePackage cachedPkgs;
native-qt-cache = cachedNativeQtPackage cachedPkgs;
} // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
android-emulator = (androidEnvironment pkgs).emulator;
android-tv-emulator = (androidEnvironment pkgs).tvEmulator;
});
devShells = forAllSystems (pkgs:
let
system = pkgs.stdenv.hostPlatform.system;
lintPkgs = import (nixpkgsFor system) {
inherit system;
overlays = [ pinnedQtOverlay ];
};
android = androidEnvironment pkgs;
androidQtHost = androidQtHostPackage pkgs;
in {
default = pkgs.mkShell {
packages = sourceBuildPackages pkgs;
shellHook = sourceShellHook pkgs;
};
lint = lintPkgs.mkShell {
packages = with lintPkgs; [
python3
qt6.qtdeclarative
(qmlToolWrappers lintPkgs lintPkgs.qt6)
];
shellHook = gitHooksShellHook;
};
qt-source = pkgs.mkShell {
packages = sourceBuildPackages pkgs;
shellHook = sourceShellHook pkgs;
};
native = pkgs.mkShell {
packages = nativePackages pkgs;
shellHook = nativeShellHook pkgs;
};
android = pkgs.mkShell {
packages = with pkgs; [
android.sdk
androidQtHost
autoconf
automake
bashInteractive
ccache
cmake
curl
git
imagemagick
jdk17_headless
jq
libtool
meson
nasm
ninja
perl
pkg-config
python3
yasm
] ++ lib.optionals stdenv.hostPlatform.isLinux [ util-linux ];
ANDROID_HOME = "${android.sdk}/libexec/android-sdk";
ANDROID_SDK_ROOT = "${android.sdk}/libexec/android-sdk";
ANDROID_NDK_ROOT = "${android.sdk}/libexec/android-sdk/ndk/${androidToolchain.android.ndkVersion}";
JAVA_HOME = pkgs.jdk17_headless.home;
SPOOL_ANDROID_QT_HOST = "${androidQtHost}";
shellHook = gitHooksShellHook;
};
} // pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
windows-proton = pkgs.mkShell {
packages = with pkgs; [
umu-launcher vulkan-tools python3 msitools gcab p7zip
curl git jq
podman util-linux
];
};
});
apps = forAllSystems (pkgs:
let
system = pkgs.stdenv.hostPlatform.system;
cachedPkgs = cachePkgsFor system;
cachedPackage = cachedNativePackage cachedPkgs;
android = androidEnvironment pkgs;
cachedQtPluginPath =
cachedPkgs.lib.makeSearchPath cachedPkgs.spoolQt6.qtbase.qtPluginPrefix
(nativeQtPackages cachedPkgs);
cachedQmlImportPath =
cachedPkgs.lib.makeSearchPath cachedPkgs.spoolQt6.qtbase.qtQmlPrefix
(nativeQtPackages cachedPkgs);
cachedRuntimeLibPath =
cachedPkgs.lib.makeLibraryPath (nativeRuntimePackages cachedPkgs);
cachedPackageDerivation =
builtins.unsafeDiscardStringContext cachedPackage.drvPath;
immutableRevision = self ? rev && !(self ? dirtyRev);
stagedSourceId = builtins.substring 0 12
(builtins.hashString "sha256" "${self}-${mpv-src}");
buildScript =
if pkgs.stdenv.hostPlatform.isDarwin
then "tools/build-macos.sh"
else "tools/build-linux-release.sh";
buildCommand =
if pkgs.stdenv.hostPlatform.isDarwin
then ''APP_INSTALL="$REPO_ROOT/build/macos/run-install" DEPLOY_APP=0 exec bash ${buildScript}''
else "exec bash ${buildScript}";
binaryPath =
if pkgs.stdenv.hostPlatform.isDarwin
then "build/macos/run-install/Spool.app/Contents/MacOS/Spool"
else "build/linux-release/install/bin/spool";
nativeBuildStamp =
if pkgs.stdenv.hostPlatform.isDarwin
then "build/macos/.spool-nix-source-id"
else "build/linux-release/.spool-nix-source-id";
mpvLibraryPath =
if pkgs.stdenv.hostPlatform.isDarwin
then "build/macos/mpv-prefix/lib"
else "build/linux-release/mpv-prefix/lib";
libraryPathVariable =
if pkgs.stdenv.hostPlatform.isDarwin
then "DYLD_LIBRARY_PATH"
else "LD_LIBRARY_PATH";
qtPluginPath =
pkgs.lib.makeSearchPath pkgs.spoolQt6.qtbase.qtPluginPrefix
(nativeQtPackages pkgs);
qmlImportPath =
pkgs.lib.makeSearchPath pkgs.spoolQt6.qtbase.qtQmlPrefix
(nativeQtPackages pkgs);
nativeRuntimeLibPath = pkgs.lib.makeLibraryPath (nativeRuntimePackages pkgs);
appBuildDir =
if pkgs.stdenv.hostPlatform.isDarwin
then "build/macos/app"
else "build/linux-release/app";
# One driver runs the complete traditional phase before real GUI e2e,
# retaining both failures rather than excluding GPU consumers on Linux.
testJobs =
if pkgs.stdenv.hostPlatform.isDarwin
then "$(sysctl -n hw.ncpu)"
else "$(nproc)";
nativeEnvironmentScrub = ''PATH=$(printf %s "$PATH" | tr ":" "\n" | grep -v webos-sdk | paste -sd:); export PATH; unset WEBOS_SDK_ROOT QT_PLUGIN_PATH QML2_IMPORT_PATH QML_IMPORT_PATH'';
testScript = pkgs.writeShellScript "spool-tests" ''
set -euo pipefail
${nativeEnvironmentScrub}
cd "$1"
shift
workers="${testJobs}"
if (( workers > 32 )); then workers=32; fi
exec python3 tools/run-tests.py --build-dir ${appBuildDir} --workers "$workers" "$@"
'';
# Development apps resolve the checkout, optionally build the
# selected native variant, then launch it inside the #native shell.
makeRunner = {
name,
launchPrefix ? "",
cmakeExtraArgs ? "",
buildRoot ? "",
buildBeforeRun ? false,
buildOnly ? false,
runTests ? false,
localProviders ? false,
controlCli ? false,
checkoutScript ? "",
}:
let
runnerBinaryPath =
if controlCli then "${buildRoot}/" + (if pkgs.stdenv.hostPlatform.isDarwin then "run-install" else "install") + "/bin/spoolet"
else
if buildRoot == "" then binaryPath
else if pkgs.stdenv.hostPlatform.isDarwin
then "${buildRoot}/run-install/Spool.app/Contents/MacOS/Spool"
else "${buildRoot}/install/bin/spool";
runnerMpvLibraryPath =
if buildRoot == "" then mpvLibraryPath
else "${buildRoot}/mpv-prefix/lib";
runnerBuildStamp =
if buildRoot != "" then "${buildRoot}/.spool-nix-source-id"
else if pkgs.stdenv.hostPlatform.isDarwin then "build/macos/.spool-nix-source-id"
else "build/linux-release/.spool-nix-source-id";
buildRootExport = pkgs.lib.optionalString (buildRoot != "")
''export BUILD_ROOT="$REPO_ROOT/${buildRoot}"; '';
runnerBuildCommand =
if pkgs.stdenv.hostPlatform.isDarwin && buildRoot != ""
then ''APP_INSTALL="$REPO_ROOT/${buildRoot}/run-install" DEPLOY_APP=0 exec bash ${buildScript}''
else buildCommand;
in pkgs.writeShellScriptBin name ''
export PATH="${pkgs.lib.makeBinPath ([ pkgs.nix pkgs.bashInteractive pkgs.coreutils pkgs.gnugrep pkgs.gnused ] ++ pkgs.lib.optional (localProviders || checkoutScript != "") pkgs.python3)}:$PATH"
set -euo pipefail
FLAKE_SOURCE="${self}"
MPV_SOURCE="${mpv-src}"
is_repo_root() {
[ -f "$1/CMakeLists.txt" ] && [ -f "$1/tools/build-macos.sh" ] && [ -f "$1/mpv/meson.build" ]
}
stage_flake_source() {
cache_base="''${XDG_CACHE_HOME:-$HOME/.cache}/spool/nix-run"
staged="$cache_base/${stagedSourceId}"
marker="$staged/.spool-staged-source"
if [ ! -f "$marker" ]; then
tmp="$cache_base/.${stagedSourceId}.$$"
rm -rf "$tmp"
mkdir -p "$cache_base"
cp -R "$FLAKE_SOURCE/." "$tmp"
chmod -R u+w "$tmp"
rm -rf "$tmp/mpv"
ln -s "$MPV_SOURCE" "$tmp/mpv"
printf '%s\n' "${stagedSourceId}" > "$tmp/.spool-staged-source"
rm -rf "$staged"
mv "$tmp" "$staged"
fi
printf '%s\n' "$staged"
}
if [ -n "''${SPOOL_REPO:-}" ]; then
REPO_ROOT="$SPOOL_REPO"
if ! is_repo_root "$REPO_ROOT"; then
echo "error: SPOOL_REPO does not point to a usable spool checkout: $REPO_ROOT" >&2
exit 1
fi
elif is_repo_root "$PWD"; then
REPO_ROOT="$PWD"
else
${pkgs.lib.optionalString (localProviders || checkoutScript != "") ''
echo "error: run this local-provider workflow from the checkout root or set SPOOL_REPO" >&2
exit 1
''}
REPO_ROOT="$(stage_flake_source)"
fi
cd "$REPO_ROOT"
export REPO_ROOT
${pkgs.lib.optionalString (checkoutScript != "") ''
exec bash "$REPO_ROOT/${checkoutScript}" "$@"
''}
${pkgs.lib.optionalString localProviders ''
if [ "''${1:-}" = "--dry-run" ]; then
exec bash "$REPO_ROOT/tools/build-local-providers.sh" "$@"
fi
''}
BIN="$REPO_ROOT/${runnerBinaryPath}"
BUILD_STAMP="$REPO_ROOT/${runnerBuildStamp}"