-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathflake.nix
More file actions
489 lines (423 loc) · 19 KB
/
Copy pathflake.nix
File metadata and controls
489 lines (423 loc) · 19 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
{
description = "Nix Development Flake for Quasar";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs_unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
};
outputs =
{
self,
nixpkgs,
nixpkgs_unstable,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
# https://nixos.wiki/wiki/Rust
# https://nixos.org/manual/nixpkgs/stable/#rust
# if we want a specific rust version:
# rust-overlay.url = "github:oxalica/rust-overlay";
pkgs = import nixpkgs { inherit system; };
pkgs_unstable = import nixpkgs_unstable { inherit system; };
python = pkgs.python311;
mkTycliBin =
commandName:
pkgs.writeShellScriptBin commandName ''
set -euo pipefail
repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
cli_bin="$repo_root/packages/tycli/bin/tycli.cjs"
if [ ! -f "$cli_bin" ]; then
echo "$commandName: missing built tycli bundle at $cli_bin" >&2
echo "$commandName: run yarn tycli:build first" >&2
exit 1
fi
exec node "$cli_bin" "$@"
'';
mkTycliDevBin =
commandName:
pkgs.writeShellScriptBin commandName ''
set -euo pipefail
repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
exec yarn --cwd "$repo_root" node --import "$repo_root/packages/tycli/src/register.ts" --experimental-strip-types "$repo_root/packages/tycli/src/cli.ts" "$@"
'';
tycliBin = mkTycliBin "tycli";
tycBin = mkTycliBin "tyc";
tycliDevBin = mkTycliDevBin "tycli-dev";
tycDevBin = mkTycliDevBin "tyc-dev";
prepareRustBin = pkgs.writeShellScriptBin "prepare_rust" ''
set -euo pipefail
repo_root="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
rumoca_root="$repo_root/packages/rumoca"
toolchain_file="$rumoca_root/rust-toolchain.toml"
lock_file="$rumoca_root/Cargo.lock"
expected_wasm_pack="0.13.1"
if [ ! -f "$toolchain_file" ]; then
echo "prepare_rust: missing $toolchain_file" >&2
exit 1
fi
if [ ! -f "$lock_file" ]; then
echo "prepare_rust: missing $lock_file" >&2
exit 1
fi
toolchain="$(sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' "$toolchain_file" | head -n 1)"
if [ -z "$toolchain" ]; then
echo "prepare_rust: could not read pinned Rumoca toolchain from $toolchain_file" >&2
exit 1
fi
expected_wasm_bindgen="$(
python - <<'PY'
import pathlib, tomllib
lock = tomllib.loads(pathlib.Path("packages/rumoca/Cargo.lock").read_text())
versions = sorted(
{
pkg["version"]
for pkg in lock.get("package", [])
if pkg.get("name") == "wasm-bindgen"
}
)
if not versions:
raise SystemExit("failed to discover wasm-bindgen version in packages/rumoca/Cargo.lock")
print(versions[-1])
PY
)"
echo "[prepare_rust] Installing general Rust toolchain..."
rustup toolchain install stable
echo "[prepare_rust] Installing Rumoca pinned toolchain: $toolchain"
rustup toolchain install "$toolchain"
rustup target add wasm32-unknown-unknown --toolchain "$toolchain"
rustup component add rust-src --toolchain "$toolchain"
echo "[prepare_rust] Installing wasm-bindgen-cli $expected_wasm_bindgen"
cargo install wasm-bindgen-cli --version "$expected_wasm_bindgen" --locked --force
echo "[prepare_rust] Installing wasm-pack $expected_wasm_pack"
cargo install wasm-pack --version "$expected_wasm_pack" --locked --force
echo "[prepare_rust] Done."
'';
# this is all tauri-related stuff
libraries = with pkgs; [
# tauri deps
at-spi2-atk
atkmm
cairo
gdk-pixbuf
glib
glib-networking
gobject-introspection
gobject-introspection.dev
gtk3
harfbuzz
librsvg
libsoup_3
pango
gh
webkitgtk_4_1
webkitgtk_4_1.dev
#webkitgtk
#gtk3
#cairo
#gdk-pixbuf
#glib
#dbus
#openssl_3
#librsvg
#libsoup
# this is needed for appimage by build_appimage.sh ...
#libgpg-error
#xorg.libX11
#xorg.libSM
#xorg.libICE
#xorg.libxcb
#fribidi
#fontconfig
#libthai
#harfbuzz
#freetype
#libglvnd
#mesa
#libdrm
cargo-tauri
rustup # needed for adding new targets e.g. wasm-bindgen!
# add rust toolchain
rustc
rustfmt # needed in order to compile rumoca
cargo
# for cypress e2e testing
glib
nss
nspr
at-spi2-atk
cups
dbus
libdrm
gtk2
gtk3
pango
cairo
alsa-lib
libX11
libXcomposite
libXdamage
libXext
libXfixes
libXrandr
libxcb
libxkbcommon
#xorg
mesa
libgbm # for libgbm
expat
];
packages = with pkgs; [
# rust
#rustfmt
#clippy
#rustc
#cargo
#cargo-deny
#cargo-edit
#cargo-watch
#llvmPackages.bintools
#rustup
#rust-analyzer
#rust-src
# for tauri
curl
wget
pkg-config
systemd.dev
systemd
# for running local llm models:
# not sure, why.. but this isn't working, currently.. so we are using docker
# local-ai
# node
# yarn
# we disable yarn-berry, because it is installed using corepack!
# yarn-berry
nodejs_22
# helpers
graphviz # we are using this with "madge" in order to display dependency graphs...
perf # needed for cargo flamegraph (perf-based sampling)
xorgserver # provides Xvfb / xvfb-run for headless tauri diagnostics on servers
# supabase
docker-compose
# colima # also doesn't work yet somehow...
# podman # doesn't work with supabase I think
pkgs_unstable.stripe-cli
pkgs_unstable.deno
python # this is needed for newer quasar versions apparently...
# not sure.. but if I use our git-filter repo form main nix store, it doesn't work.. maybe becuase of cinflicting python versions?
# git-filter-repo
kdiff3
# we use this to search for missing libraries with the same version as this
# project here.
# run:
# > nix-index
# > nix-locate libgbm.so.1
nix-index
tycliBin
tycBin
tycliDevBin
tycDevBin
prepareRustBin
];
in
{
devShells.default = pkgs.mkShell rec {
# pure = true; # ← turn on “pure” mode
name = "xyntopia_gui";
# TODO: what is this for? nativeBuildInputs = [ pkgs.bashInteractive ];
buildInputs = libraries ++ packages;
# the following comes from here: https://tauri.app/start/prerequisites/
# but by declaring LD_LIBRARY_PATH we might have done it correctly already ;)
# and thats why we're commenting it out...
#PKG_CONFIG_PATH = "${glib.dev}/lib/pkgconfig:${libsoup_3.dev}/lib/pkgconfig:${webkitgtk_4_1.dev}/lib/pkgconfig:${at-spi2-atk.dev}/lib/pkgconfig:${gtk3.dev}/lib/pkgconfig:${gdk-pixbuf.dev}/lib/pkgconfig:${cairo.dev}/lib/pkgconfig:${pango.dev}/lib/pkgconfig:${harfbuzz.dev}/lib/pkgconfig";
# propagatedBuildInputs = libraries; # your GTK/WebKit/etc libs
shellHook = ''
# python poetry related stuff
unset SOURCE_DATE_EPOCH
unset LD_PRELOAD
# Environment variables
# fixes libstdc++ issues, libz.so.1 issues
export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib/:${pkgs.lib.makeLibraryPath buildInputs}";
export NODE_OPTIONS="--max-old-space-size=8192"
echo "increasing node memory allocation to $NODE_OPTIONS"
if [ -f ./.env ]; then
set -a # automatically export all variables
source ./.env
set +a
fi
export PATH="$(pwd)/node_modules/.bin:$PATH:$HOME/.cargo/bin"
check_rumoca_rust_toolchain() {
local toolchain_file="$(pwd)/packages/rumoca/rust-toolchain.toml"
local toolchain=""
local cargo_bin=""
local loader=""
if ! command -v rustup >/dev/null 2>&1; then
return
fi
if [ ! -f "$toolchain_file" ]; then
return
fi
toolchain="$(sed -n 's/^[[:space:]]*channel[[:space:]]*=[[:space:]]*"\([^"]*\)".*/\1/p' "$toolchain_file" | head -n 1)"
if [ -z "$toolchain" ]; then
return
fi
cargo_bin="$(rustup which cargo --toolchain "$toolchain" 2>/dev/null || true)"
if [ -z "$cargo_bin" ]; then
echo "[devShell] Rumoca Rust toolchain '$toolchain' is not installed."
echo "[devShell] Your general Rust toolchain is usually installed with:"
echo "[devShell] rustup toolchain install stable"
echo "[devShell] Rumoca also needs its pinned toolchain from packages/rumoca/rust-toolchain.toml:"
echo "[devShell] rustup toolchain install $toolchain"
echo "[devShell] rustup target add wasm32-unknown-unknown --toolchain $toolchain"
echo "[devShell] rustup component add rust-src --toolchain $toolchain"
return
fi
if "$cargo_bin" --version >/dev/null 2>&1; then
return
fi
loader="$(${pkgs.binutils}/bin/readelf -l "$cargo_bin" 2>/dev/null | sed -n 's@.*Requesting program interpreter: \(.*\)]@\1@p' | head -n 1)"
echo "[devShell] Rumoca Rust toolchain '$toolchain' is installed but not executable."
if [ -n "$loader" ] && [ ! -e "$loader" ]; then
echo "[devShell] Missing ELF loader: $loader"
echo "[devShell] This often happens after a NixOS upgrade or GC when rustup binaries still point at an older glibc path."
fi
echo "[devShell] If your base Rust install is broken, first try:"
echo "[devShell] rustup toolchain install stable"
echo "[devShell] Rumoca itself still needs its pinned toolchain, so reinstall that too:"
echo "[devShell] rustup toolchain uninstall $toolchain"
echo "[devShell] rustup toolchain install $toolchain"
echo "[devShell] rustup target add wasm32-unknown-unknown --toolchain $toolchain"
echo "[devShell] rustup component add rust-src --toolchain $toolchain"
}
check_rumoca_wasm_tooling() {
local rumoca_root="$(pwd)/packages/rumoca"
local expected_wasm_bindgen=""
local expected_wasm_pack="0.13.1"
local wasm_bindgen_bin=""
local wasm_pack_bin=""
local wasm_bindgen_version=""
local wasm_pack_version=""
local loader=""
if [ ! -d "$rumoca_root" ]; then
return
fi
expected_wasm_bindgen="$(
python - <<'PY' 2>/dev/null
import pathlib, tomllib
lock = tomllib.loads(pathlib.Path("packages/rumoca/Cargo.lock").read_text())
versions = sorted(
{
pkg["version"]
for pkg in lock.get("package", [])
if pkg.get("name") == "wasm-bindgen"
}
)
if versions:
print(versions[-1])
PY
)"
wasm_bindgen_bin="$(command -v wasm-bindgen 2>/dev/null || true)"
if [ -z "$wasm_bindgen_bin" ]; then
echo "[devShell] wasm-bindgen-cli is missing."
if [ -n "$expected_wasm_bindgen" ]; then
echo "[devShell] Install it with:"
echo "[devShell] cargo install wasm-bindgen-cli --version $expected_wasm_bindgen --locked --force"
fi
else
wasm_bindgen_version="$(wasm-bindgen --version 2>/dev/null | sed -n 's/.* \([0-9][0-9A-Za-z._-]*\)$/\1/p' | head -n 1)"
if ! wasm-bindgen --version >/dev/null 2>&1; then
loader="$(${pkgs.binutils}/bin/readelf -l "$wasm_bindgen_bin" 2>/dev/null | sed -n 's@.*Requesting program interpreter: \(.*\)]@\1@p' | head -n 1)"
echo "[devShell] wasm-bindgen-cli exists but is not executable: $wasm_bindgen_bin"
if [ -n "$loader" ] && [ ! -e "$loader" ]; then
echo "[devShell] Missing ELF loader: $loader"
echo "[devShell] This often happens after a NixOS upgrade or GC."
fi
if [ -n "$expected_wasm_bindgen" ]; then
echo "[devShell] Reinstall it with:"
echo "[devShell] cargo install wasm-bindgen-cli --version $expected_wasm_bindgen --locked --force"
fi
elif [ -n "$expected_wasm_bindgen" ] && [ "$wasm_bindgen_version" != "$expected_wasm_bindgen" ]; then
echo "[devShell] wasm-bindgen-cli version mismatch: found $wasm_bindgen_version, expected $expected_wasm_bindgen."
echo "[devShell] Reinstall it with:"
echo "[devShell] cargo install wasm-bindgen-cli --version $expected_wasm_bindgen --locked --force"
fi
fi
wasm_pack_bin="$(command -v wasm-pack 2>/dev/null || true)"
if [ -z "$wasm_pack_bin" ]; then
echo "[devShell] wasm-pack is missing."
echo "[devShell] Install it with:"
echo "[devShell] cargo install wasm-pack --version $expected_wasm_pack --locked --force"
return
fi
wasm_pack_version="$(wasm-pack --version 2>/dev/null | sed -n 's/.* \([0-9][0-9A-Za-z._-]*\)$/\1/p' | head -n 1)"
if ! wasm-pack --version >/dev/null 2>&1; then
echo "[devShell] wasm-pack exists but is not executable: $wasm_pack_bin"
echo "[devShell] Reinstall it with:"
echo "[devShell] cargo install wasm-pack --version $expected_wasm_pack --locked --force"
return
fi
if [ "$wasm_pack_version" != "$expected_wasm_pack" ]; then
echo "[devShell] wasm-pack version mismatch: found $wasm_pack_version, expected $expected_wasm_pack."
echo "[devShell] Install the expected version with:"
echo "[devShell] cargo install wasm-pack --version $expected_wasm_pack --locked --force"
fi
}
check_rumoca_rust_toolchain
check_rumoca_wasm_tooling
export LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath libraries}:$LD_LIBRARY_PATH
export XDG_DATA_DIRS=${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS
# Ensure WebKitGTK/libsoup can load the TLS backend on NixOS.
export GIO_MODULE_DIR="${pkgs.glib-networking}/lib/gio/modules"
export GIO_EXTRA_MODULES="${pkgs.glib-networking}/lib/gio/modules''${GIO_EXTRA_MODULES:+:}$GIO_EXTRA_MODULES"
# Ensure certificate bundle is available for HTTPS validation.
export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
export NIX_SSL_CERT_FILE="$SSL_CERT_FILE"
# ── Corepack cache location ─────────────────────────────────────────────────────
# By default, Corepack stores downloaded package managers (e.g. Yarn CLI JS) in
# $COREPACK_HOME. If unset, it uses a global cache outside the repo (e.g. ~/.cache/node/corepack).
#
# In our old setup, we forced COREPACK_HOME into ./.corepack/home (inside the repo)
# so everything was self-contained. However:
# • Our repo’s package.json sets `"type": "module"`, so any JS under it is treated as ESM.
# • Yarn’s CLI bundle contains `require()` calls, which fail under ESM with:
# "Error: Dynamic require of 'util' is not supported"
# • This broke Yarn in some projects (notably when package.json was at repo root).
#
# Fix: move COREPACK_HOME to a location *outside* any `"type": "module"` package boundary
# (e.g. $HOME/.cache/corepack-home) so Node treats Yarn’s CLI as CommonJS.
# We still keep shims (yarn, pnpm, etc.) in ./.corepack/bin so they are project-local.
#
# Nix note: use ''${...} to pass Bash \$\{...} through without Nix interpolating it.
### ability to use modern yarn
# Put shims & downloaded package managers inside repo
# this helps with our new yarn version using corepack on nixos!
# ── Corepack shims (idempotent & self-healing) ────────────────────────────────
# Keep Corepack cache outside the repo (CJS-safe),
# but regenerate repo-local shims when Node/Corepack changes.
export COREPACK_HOME="''${XDG_CACHE_HOME:-$HOME/.cache}/corepack-home"
export PATH="$(pwd)/.corepack/bin:$PATH"
COREPACK_BIN="$(pwd)/.corepack/bin"
COREPACK_MARKER="$COREPACK_BIN/.node-version"
mkdir -p "$COREPACK_BIN"
NODE_VERSION="$(node -v 2>/dev/null || true)"
if [ ! -f "$COREPACK_MARKER" ] || ! grep -qx "$NODE_VERSION" "$COREPACK_MARKER"; then
echo "[devShell] Refreshing Corepack shims (node $NODE_VERSION)"
rm -f \
"$COREPACK_BIN/yarn" \
"$COREPACK_BIN/yarnpkg" \
"$COREPACK_BIN/pnpm" \
"$COREPACK_BIN/pnpx"
corepack enable --install-directory="$COREPACK_BIN"
echo "$NODE_VERSION" > "$COREPACK_MARKER"
fi
'';
# fixes xcb issues :
# QT_PLUGIN_PATH=${qt5.qtbase}/${qt5.qtbase.qtPluginPrefix}
# fixes libstdc++ issues and libgl.so issues
#LD_LIBRARY_PATH=${stdenv.cc.cc.lib}/lib/:/run/opengl-driver/lib/
};
}
);
}