-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
624 lines (527 loc) · 17.5 KB
/
flake.nix
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
{
description = "yaaaaaaaaaaaaaaaaaaaaa";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
libmpv-windows = {
url = "https://sourceforge.net/projects/mpv-player-windows/files/libmpv/mpv-dev-x86_64-20211128-git-f08db00.7z/download";
flake = false;
};
};
outputs = inputs:
inputs.flake-utils.lib.eachDefaultSystem (system: let
flakePackage = flake: package: flake.packages."${system}"."${package}";
flakeDefaultPackage = flake: flakePackage flake "default";
pkgs = import inputs.nixpkgs rec {
inherit system;
config = {
allowUnfree = true;
android_sdk.accept_license = true;
};
overlays = [
(final: prev: {
unstable = import inputs.nixpkgs-unstable {
inherit system config;
};
})
];
};
android-shell = pkgs.mkShell {
packages =
[
pkgs.jdk
(pkgs.gradle.override {
java = pkgs.jdk;
javaToolchains = [pkgs.jdk];
})
]
++ (with pkgs; [
android-studio
glibc
gradle
jdk
jetbrains.idea-community
unstable.jdt-language-server
rustup
]);
shellHook = ''
export ANDROID_NDK_TOOLCHAIN_DIR="$HOME/.android/Sdk/ndk"
export ANDROID_NDK_HOME="$HOME/.android/Sdk/ndk/27.0.12077973"
export BUILD_MODE="PROD"
export UI_BACKEND="NONE"
export SERVER_PORT=6176
'';
env = {
JAVA_HOME = "${pkgs.jdk.home}";
# - [Android Emulator not working](https://github.com/NixOS/nixpkgs/issues/267176#issuecomment-2074366571)
QT_QPA_PLATFORM = "xcb";
DEV_SHELL = "ANDROID";
};
};
qt-shell =
pkgs.mkShell.override {
inherit stdenv;
} {
nativeBuildInputs = (env-packages pkgs) ++ [fhs];
inputsFrom = [
covau
qweb
];
buildInputs = (with pkgs; [
unstable.qtcreator
# this is for the shellhook portion
unstable.qt6.wrapQtAppsHook
makeWrapper
bashInteractive
]) ++ [
qweb
];
# - [(Qt)Quick C++ Project Setup with Nix](https://galowicz.de/2023/01/16/cpp-qt-qml-nix-setup/)
# set the environment variables that Qt apps expect
shellHook = ''
# - [Qt WebEngine Debugging and Profiling | Qt WebEngine 6.7.2](https://doc.qt.io/qt-6/qtwebengine-debugging.html#qt-webengine-developer-tools)
export QTWEBENGINE_REMOTE_DEBUGGING=6178
export DEV_SHELL="QT"
export QT_QPA_PLATFORM="wayland"
bashdir=$(mktemp -d)
makeWrapper "$(type -p bash)" "$bashdir/bash" "''${qtWrapperArgs[@]}"
exec "$bashdir/bash"
'';
};
# - [Cross compilation — nix.dev documentation](https://nix.dev/tutorials/cross-compilation.html)
# - [Cross Compile Rust for Windows - Help - NixOS Discourse](https://discourse.nixos.org/t/cross-compile-rust-for-windows/9582/7)
# windows-pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux.pkgsCross.mingw32;
windows-pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux.pkgsCross.mingwW64;
# windows-pkgs = import inputs.nixpkgs {
# localSystem = "x86_64-linux";
# crossSystem.config = "x86_64-w64-mingw32";
# };
# windows-pkgs = import inputs.nixpkgs {
# localSystem = "x86_64-linux";
# crossSystem.config = "x86_64-w64-mingwW64";
# };
# - [fatal error: EventToken.h: No such file or directory](https://github.com/webview/webview/issues/1036)
# - [MinGW-w64 requirements](https://github.com/webview/webview?tab=readme-ov-file#mingw-w64-requirements)
# - [WinLibs - GCC+MinGW-w64 compiler for Windows](https://winlibs.com/#download-release)
winlibs = windows-pkgs.stdenv.mkDerivation {
name = "winlibs";
src = windows-pkgs.fetchzip {
url = "https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-18.1.8-12.0.0-ucrt-r1/winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-18.1.8-mingw-w64ucrt-12.0.0-r1.zip";
sha256 = "sha256-xBRZ8NJmWXpvraaTpXBkd2QbhF5hR/8g/UBPwCd12hc=";
};
phases = ["installPhase"];
installPhase = ''
mkdir $out
cp -r $src/* $out/.
'';
};
mcfgthread = windows-pkgs.stdenv.mkDerivation {
name = "mcfgthread";
src = windows-pkgs.fetchurl {
url = "https://mirror.msys2.org/mingw/mingw64/mingw-w64-x86_64-mcfgthread-1.8.3-1-any.pkg.tar.zst";
sha256 = "sha256-ogfmo9utCtE2WpWtmPDuf+M6WIvpp1Xvxn+aqRu+nbs=";
};
nativeBuildInputs = [
pkgs.zstd
];
phases = ["installPhase"];
installPhase = ''
mkdir $out
cp $src $out/src
cd $out
tar --zstd -xvf src
rm src
mv mingw64/* .
rmdir mingw64
'';
};
rust-bin = inputs.rust-overlay.lib.mkRustBin {} windows-pkgs.buildPackages;
windows-mpv = windows-pkgs.stdenv.mkDerivation {
name = "libmpv";
src = inputs.libmpv-windows;
phases = ["installPhase"];
installPhase = ''
mkdir -p $out/lib
cd $out
${pkgs.p7zip}/bin/7z x $src
# mv libmpv-2.dll ./lib/.
mv libmpv.dll.a ./lib/.
mv mpv-1.dll ./lib/.
'';
};
windows-shell = windows-pkgs.mkShell {
nativeBuildInputs = [
rust-bin.stable.latest.minimal
windows-pkgs.buildPackages.pkg-config
windows-pkgs.openssl
# winlibs
# mcfgthread
];
depsBuildBuild = [];
# OOF: kinda works :/
# first build with no pthreads
# then enable pthreads and build again :clown
buildInputs = [
# windows-pkgs.buildPackages.pkg-config
windows-pkgs.openssl
# windows-pkgs.windows.mingw_w64_pthreads
windows-pkgs.windows.pthreads
windows-mpv
# winlibs
# mcfgthread
];
env = {
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
DEV_SHELL = "WIN";
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${windows-pkgs.stdenv.cc.targetPrefix}cc";
};
};
meta = with pkgs.lib; {
homepage = manifest.repository;
# description = manifest.description;
license = licenses.mit;
# platforms = platforms.linux;
};
manifest = (pkgs.lib.importTOML ./app/Cargo.toml).package;
yarn-lock = pkgs.stdenv.mkDerivation {
name = "yarn.lock";
src = ./.;
buildPhase = ''
cd ui
bun i -y --frozen-lockfile --production --dry-run
'';
installPhase = ''
mkdir $out
mv ./yarn.lock $out/.
'';
nativeBuildInputs = with pkgs; [
unstable.bun
];
};
yarn-deps = pkgs.fetchYarnDeps {
yarnLock = yarn-lock + /yarn.lock;
hash = "sha256-c4ictJfi9S8TgXBkAZ9JkSHAquusGj2aqCVEwVO9Vt8=";
};
yarn-modules = pkgs.unstable.mkYarnModules {
pname = "yarn-modules";
version = "0.0";
yarnLock = yarn-lock + /yarn.lock;
# yarnLock = ./ui + /yarn.lock;
packageJSON = ./ui/package.json;
};
ui-dist = pkgs.stdenv.mkDerivation {
name = "ui-dist";
src = ./.;
buildPhase = ''
# export UI_BACKEND="ELECTRON"
# export UI_BACKEND="TAO-WRY"
export UI_BACKEND="QWEB"
# export UI_BACKEND="NONE"
export BUILD_MODE="PROD"
export SERVER_PORT=6173
export DEV_VITE_PORT=6175
cd ui
ln -s ${yarn-modules}/node_modules ./node_modules
bun run build
cd ..
'';
installPhase = ''
mkdir $out
mv ./ui/dist $out/.
'';
nativeBuildInputs = with pkgs; [
bun
];
};
covau = pkgs.unstable.rustPlatform.buildRustPackage rec {
pname = manifest.name;
version = manifest.version;
cargoLock = {
lockFile = ./Cargo.lock;
};
src = pkgs.lib.cleanSource ./.;
buildPhase = ''
# export UI_BACKEND="ELECTRON"
# export UI_BACKEND="TAO-WRY"
export UI_BACKEND="QWEB"
# export UI_BACKEND="NONE"
export BUILD_MODE="PROD"
export SERVER_PORT=6173
export DEV_VITE_PORT=6175
cd ui
ln -s ${yarn-modules}/node_modules ./node_modules
bun run build
cd ..
cargo build --release --locked --offline -Z unstable-options --out-dir ./.
'';
installPhase = ''
mkdir -p $out/bin
mv ./${pname} $out/bin/.
'';
buildInputs = (with pkgs; [
openssl
# zweb
webkitgtk
# wry
webkitgtk_4_1
libsoup
# gst_all_1.gstreamer
# gst_all_1.gst-plugins-base
# gst_all_1.gst-plugins-good
# gst_all_1.gst-plugins-bad
# gst_all_1.gst-plugins-ugly
# # Plugins to reuse ffmpeg to play almost every video format
# gst_all_1.gst-libav
# # Support the Video Audio (Hardware) Acceleration API
# gst_all_1.gst-vaapi
mpv
]) ++ [
qweb
];
nativeBuildInputs = with pkgs; [
bun
pkg-config
sqlite
];
inherit meta;
};
qweb = pkgs.clangStdenv.mkDerivation {
name = "covau-qweb";
src = ./qweb;
buildPhase = ''
cmake
make
'';
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/lib
mv ./qweb $out/bin/.
mv ./libqweb.so $out/lib/.
# mv ./libqweb.a $out/lib/.
'';
buildInputs = with pkgs; [
unstable.qt6.qtbase
unstable.qt6.full
unstable.qt6.qtwayland
# kdePackages.qtwebview
# kdePackages.qtwebengine
# kdePackages.qtdeclarative
# kdePackages.qtwayland
];
nativeBuildInputs = with pkgs; [
pkg-config
cmake
unstable.qt6.wrapQtAppsHook
];
};
fhs = pkgs.buildFHSEnv {
name = "fhs-shell";
targetPkgs = p: (env-packages p) ++ (custom-commands p);
runScript = "${pkgs.zsh}/bin/zsh";
profile = ''
export FHS=1
# source ./.venv/bin/activate
# source .env
'';
};
windows-commands = pkgs: [
(pkgs.writeShellScriptBin "build-zweb-windows" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/zweb
nix develop .#windows -c zig build -Dtarget=x86_64-windows
'')
(pkgs.writeShellScriptBin "build-covau-windows" ''
#!/usr/bin/env bash
export BUILD_MODE="PROD"
export UI_BACKEND="TAO-WRY"
export SERVER_PORT=6176
cd $PROJECT_ROOT/zweb
nix develop .#windows -c zig build -Dtarget=x86_64-windows --release=fast
cd $PROJECT_ROOT/wasm
wasm-pack build --release --target web
rm -r ../ui/src/wasm
mv ./pkg ../ui/src/wasm
cd $PROJECT_ROOT/ui
bun run build
cd $PROJECT_ROOT/app
nix develop .#windows -c cargo build --release --no-default-features --features tao-wry
'')
];
build-commands = pkgs: [
(pkgs.writeShellScriptBin "build-prod" ''
#!/usr/bin/env bash
export BUILD_MODE="PROD"
export UI_BACKEND="QWEB"
export SERVER_PORT=6176
# TODO: qweb is still needs to be in PATH :(
cd $PROJECT_ROOT/qweb
mkdir -p ./build
cd ./build
cmake -CMAKE_BUILD_TYPE=Release ..
make
cd $PROJECT_ROOT/wasm
wasm-pack build --release --target web
rm -r ../ui/src/wasm
mv ./pkg ../ui/src/wasm
cd $PROJECT_ROOT/ui
bun run build
cd $PROJECT_ROOT/app
cargo build --release
'')
];
dev-commands = pkgs: [
(pkgs.writeShellScriptBin "web-dev" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/ui
bun run dev
'')
(pkgs.writeShellScriptBin "wasm-dev" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT
build-wasm
inotifywait -q -m -e close_write --format %e -r ./covau/src -r ./wasm/src |
while read events; do
build-wasm
done
'')
(pkgs.writeShellScriptBin "run" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/app
cargo run -- $@
'')
(pkgs.writeShellScriptBin "android-dev" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/android
nix develop .#android -c android-studio .
'')
];
qweb-commands = pkgs: [
(pkgs.writeShellScriptBin "build-qweb" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/qweb
mkdir -p ./build
cd ./build
cmake $@ ..
make
'')
(pkgs.writeShellScriptBin "run-qweb" ''
#!/usr/bin/env bash
build-qweb -DCMAKE_BUILD_TYPE=Release
$PROJECT_ROOT/qweb/build/qweb $@
'')
(pkgs.writeShellScriptBin "run-covau-qweb" ''
#!/usr/bin/env bash
build-qweb -DCMAKE_BUILD_TYPE=Release
PATH=$PROJECT_ROOT/qweb/build:$PATH run qweb
'')
];
wasm-commands = pkgs: [
(pkgs.writeShellScriptBin "build-wasm" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/wasm
cargo build --target wasm32-unknown-unknown
rm -r ../ui/src/wasm
wasm-bindgen --web --out-dir ../ui/src/wasm ../target/wasm32-unknown-unknown/debug/covau_wasm.wasm
'')
(pkgs.writeShellScriptBin "build-wasm-pack" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/wasm
wasm-pack build --dev --target web
rm -r ../ui/src/wasm
mv ./pkg ../ui/src/wasm
'')
];
custom-commands = pkgs:
(windows-commands pkgs)
++ (dev-commands pkgs)
++ (qweb-commands pkgs)
++ (wasm-commands pkgs)
++ (build-commands pkgs)
++ [
(pkgs.writeShellScriptBin "build-zweb" ''
#!/usr/bin/env bash
cd $PROJECT_ROOT/zweb
zig build
'')
];
env-packages = pkgs:
(with pkgs;
[
unstable.rust-analyzer
unstable.rustfmt
unstable.clippy
# unstable.rustup
unstable.gdb
pkg-config
unstable.electron
# unstable.yarn
nodejs
nodePackages_latest.svelte-language-server
nodePackages_latest.typescript-language-server
tailwindcss-language-server
unstable.wasm-pack
unstable.lld
# unstable.cargo-binutils
# unstable.llvmPackages.bintools
# unstable.cargo-llvm-cov
# unstable.rustc.llvmPackages.llvm
# manually generate bindings
unstable.wasm-bindgen-cli
zig
zls
])
++ (custom-commands pkgs);
# stdenv = pkgs.clangStdenv;
stdenv = pkgs.gccStdenv;
in {
packages = {
qweb = qweb;
default = covau;
inherit covau;
};
devShells = {
windows = windows-shell;
android = android-shell;
qt = qt-shell;
default =
pkgs.mkShell.override {
inherit stdenv;
} {
nativeBuildInputs = (env-packages pkgs) ++ [fhs];
inputsFrom = [
covau
qweb
];
shellHook = ''
export PROJECT_ROOT="$(pwd)"
export RUST_BACKTRACE="1"
# $(pwd) always resolves to project root :)
export CLANGD_FLAGS="--compile-commands-dir=$(pwd)/plugin --query-driver=$(which $CXX)"
# export UI_BACKEND="ELECTRON"
# export UI_BACKEND="TAO-WRY"
# export UI_BACKEND="QWEB"
export UI_BACKEND="NONE"
export BUILD_MODE="DEV"
# export BUILD_MODE="PROD"
export SERVER_PORT=6173
export DEV_VITE_PORT=6175
export CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER="lld"
export PATH=$PROJECT_ROOT/qweb/build:$PATH
export QTWEBENGINE_REMOTE_DEBUGGING=6178
export QT_SCALE_FACTOR_ROUNDING_POLICY=RoundPreferFloor
export QT_WAYLAND_DISABLE_WINDOWDECORATION=0
# - [Workaround for blank window with WebKit/DMA-BUF/NVIDIA/X11 by SteffenL · Pull Request #1060 · webview/webview · GitHub](https://github.com/webview/webview/pull/1060)
# export WEBKIT_DISABLE_COMPOSITING_MODE=1
export WEBKIT_DISABLE_DMABUF_RENDERER=1
# makes the scale "normal"
export GDK_BACKEND=x11
'';
};
};
});
}