Skip to content

Commit 6f27622

Browse files
committed
Step 6
.agents/codebase-insights.txt: appimage-scripts/build_appimage2.sh: appimage-scripts/build_with_nim2.sh: flake.lock: flake.nix: nix/packages/default.nix: Signed-off-by: Tzanko Matev <[email protected]>
1 parent 5178023 commit 6f27622

File tree

6 files changed

+226
-2
lines changed

6 files changed

+226
-2
lines changed

.agents/codebase-insights.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@
2424
- `ct record` verifies that `codetracer_python_recorder` is importable before launching the db backend and prints actionable guidance if the module is missing or broken.
2525
- Sudoku test-program datasets include intentionally invalid boards (e.g., examples #3 and #6) with duplicate digits inside a sub-grid; solvers should detect and report these gracefully.
2626
- `appimage-scripts/build_appimage.sh` assumes a devshell: it invokes `nix build`/`nix eval` directly and runs `npm install`/`npx yarn`, so it needs host network access and the git worktree metadata that a pure derivation build lacks.
27-
- `appimage-scripts/build_appimage2.sh` now consumes `packages.${system}.appimagePayload`, which layers the Rust binaries atop the dependency tree from `appimageDeps`; both derivations pre-run `patchelf`, so the script only patches the locally built Nim binaries and bundled Ruby while everything else already targets `/lib64/ld-linux…` (or `/lib/ld-linux-aarch64.so.1`) with `\$ORIGIN/../lib` rpaths.
27+
- `appimage-scripts/build_appimage2.sh` now consumes `packages.${system}.appimagePayload`, which layers the Rust binaries atop the dependency tree from `appimageDeps`; both derivations pre-run `patchelf`, so the script only patches the locally built Nim binaries and bundled Ruby while everything else already targets `/lib64/ld-linux…` (or `/lib/ld-linux-aarch64.so.1`) with `\$ORIGIN/../lib` rpaths. The Nim outputs are provided via dedicated derivations (`appimageCtUnwrapped`, `appimageDbBackendRecord`, etc.) so we can pinpoint issues per artifact.
28+
- `flake.nix` sets `self.submodules = true`, so `nix build` automatically materializes the git submodules under `libs/`, which is required for the Nim derivations to see their dependencies.

appimage-scripts/build_appimage2.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ bash "${ROOT_PATH}/appimage-scripts/setup_node_deps.sh"
7171
bash "${ROOT_PATH}/appimage-scripts/build_css.sh"
7272

7373
# Build/setup nim-based files
74-
bash "${ROOT_PATH}/appimage-scripts/build_with_nim.sh"
74+
bash "${ROOT_PATH}/appimage-scripts/build_with_nim2.sh"
7575

7676
cat <<'EOF' >"${APP_DIR}/bin/ct"
7777
#!/usr/bin/env bash
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
echo "==========="
6+
echo "codetracer build: nim impure steps"
7+
echo "(no remaining impure actions; artifacts provided via Nix derivations)"
8+
echo "==========="

flake.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
};
1010

1111
inputs = {
12+
self.submodules = true;
13+
1214
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
1315
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
1416

nix/packages/default.nix

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,189 @@
213213
done
214214
'';
215215

216+
nimBuildInputs = [
217+
pkgs.gcc
218+
pkgs.sqlite
219+
pkgs.pcre
220+
pkgs.libzip
221+
pkgs.openssl
222+
pkgs.libuv
223+
];
224+
225+
nimBuildSetup = ''
226+
export HOME=$TMPDIR/home
227+
mkdir -p "$HOME"
228+
mkdir -p nimcache
229+
'';
230+
231+
mkNimBinary =
232+
{
233+
name,
234+
outName,
235+
cmd,
236+
}:
237+
stdenv.mkDerivation {
238+
inherit src name;
239+
240+
nativeBuildInputs = [
241+
upstream-nim-codetracer
242+
];
243+
244+
buildInputs = nimBuildInputs;
245+
246+
buildPhase = ''
247+
${nimBuildSetup}
248+
${cmd}
249+
'';
250+
251+
installPhase = ''
252+
mkdir -p $out/bin
253+
install -m 0755 ${outName} $out/bin/${outName}
254+
'';
255+
};
256+
257+
mkNimJs =
258+
{
259+
name,
260+
outName,
261+
cmd,
262+
}:
263+
stdenv.mkDerivation {
264+
inherit src name;
265+
266+
nativeBuildInputs = [
267+
upstream-nim-codetracer
268+
];
269+
270+
buildInputs = nimBuildInputs;
271+
272+
buildPhase = ''
273+
${nimBuildSetup}
274+
${cmd}
275+
'';
276+
277+
installPhase = ''
278+
mkdir -p $out
279+
install -m 0644 ${outName} $out/${outName}
280+
'';
281+
};
282+
283+
appimageCtUnwrapped =
284+
mkNimBinary {
285+
name = "codetracer-appimage-ct-unwrapped";
286+
outName = "ct_unwrapped";
287+
cmd = ''
288+
${upstream-nim-codetracer.out}/bin/nim -d:release \
289+
--d:asyncBackend=asyncdispatch \
290+
--dynlibOverride:std -d:staticStd \
291+
--gc:refc --hints:on --warnings:off \
292+
--dynlibOverride:"sqlite3" \
293+
--dynlibOverride:"pcre" \
294+
--dynlibOverride:"libzip" \
295+
--dynlibOverride:"libcrypto" \
296+
--dynlibOverride:"libssl" \
297+
--passL:"-Wl,-Bstatic -lsqlite3 -Wl,-Bdynamic" \
298+
--passL:"${appimageDeps}/lib/libpcre.so.1" \
299+
--passL:"${appimageDeps}/lib/libzip.so.5" \
300+
--passL:"${appimageDeps}/lib/libcrypto.so" \
301+
--passL:"${appimageDeps}/lib/libcrypto.so.3" \
302+
--passL:"${appimageDeps}/lib/libssl.so" \
303+
--boundChecks:on \
304+
-d:useOpenssl3 \
305+
-d:ssl \
306+
-d:chronicles_sinks=json -d:chronicles_line_numbers=true \
307+
-d:chronicles_timestamps=UnixTime \
308+
-d:ctTest -d:testing --hint"[XDeclaredButNotUsed]":off \
309+
-d:builtWithNix \
310+
-d:ctEntrypoint \
311+
-d:linksPathConst=.. \
312+
-d:libcPath=libc \
313+
-d:pathToNodeModules=../node_modules \
314+
--nimcache:nimcache \
315+
--out:ct_unwrapped c ./src/ct/codetracer.nim
316+
'';
317+
};
318+
319+
appimageDbBackendRecord =
320+
mkNimBinary {
321+
name = "codetracer-appimage-db-backend-record";
322+
outName = "db-backend-record";
323+
cmd = ''
324+
${upstream-nim-codetracer.out}/bin/nim \
325+
-d:release -d:asyncBackend=asyncdispatch \
326+
--gc:refc --hints:off --warnings:off \
327+
--debugInfo --lineDir:on \
328+
--boundChecks:on --stacktrace:on --linetrace:on \
329+
-d:chronicles_sinks=json -d:chronicles_line_numbers=true \
330+
-d:chronicles_timestamps=UnixTime \
331+
-d:ssl \
332+
-d:ctTest -d:testing --hint"[XDeclaredButNotUsed]":off \
333+
-d:linksPathConst=.. \
334+
-d:libcPath=libc \
335+
-d:builtWithNix \
336+
-d:ctEntrypoint \
337+
--dynlibOverride:"libsqlite3" \
338+
--dynlibOverride:"sqlite3" \
339+
--dynlibOverride:"pcre" \
340+
--dynlibOverride:"libzip" \
341+
--passL:"-Wl,-Bstatic -lsqlite3 -Wl,-Bdynamic" \
342+
--passL:"${appimageDeps}/lib/libpcre.so.1" \
343+
--passL:"${appimageDeps}/lib/libzip.so.5" \
344+
--nimcache:nimcache \
345+
--out:db-backend-record c ./src/ct/db_backend_record.nim
346+
'';
347+
};
348+
349+
appimageIndexJs =
350+
mkNimJs {
351+
name = "codetracer-appimage-index-js";
352+
outName = "index.js";
353+
cmd = ''
354+
${upstream-nim-codetracer.out}/bin/nim \
355+
--hints:on --warnings:off --sourcemap:on \
356+
-d:ctIndex -d:chronicles_sinks=json \
357+
-d:nodejs --out:index.js js src/frontend/index.nim
358+
'';
359+
};
360+
361+
appimageServerIndexJs =
362+
mkNimJs {
363+
name = "codetracer-appimage-server-index-js";
364+
outName = "server_index.js";
365+
cmd = ''
366+
${upstream-nim-codetracer.out}/bin/nim \
367+
--hints:on --warnings:off --sourcemap:on \
368+
-d:ctIndex -d:server -d:chronicles_sinks=json \
369+
-d:nodejs --out:server_index.js js src/frontend/index.nim
370+
'';
371+
};
372+
373+
appimageUiJs =
374+
mkNimJs {
375+
name = "codetracer-appimage-ui-js";
376+
outName = "ui.js";
377+
cmd = ''
378+
${upstream-nim-codetracer.out}/bin/nim \
379+
--hints:off --warnings:off \
380+
-d:chronicles_enabled=off \
381+
-d:ctRenderer \
382+
--out:ui.js js src/frontend/ui_js.nim
383+
'';
384+
};
385+
386+
appimageSubwindowJs =
387+
mkNimJs {
388+
name = "codetracer-appimage-subwindow-js";
389+
outName = "subwindow.js";
390+
cmd = ''
391+
${upstream-nim-codetracer.out}/bin/nim \
392+
--hints:off --warnings:off \
393+
-d:chronicles_enabled=off \
394+
-d:ctRenderer \
395+
--out:subwindow.js js src/frontend/subwindow.nim
396+
'';
397+
};
398+
216399
appimagePayload = pkgs.runCommand "codetracer-appimage-payload" {
217400
nativeBuildInputs = [
218401
pkgs.bashInteractive
@@ -227,6 +410,7 @@
227410
cp -R ${appimageDeps}/. "$out/"
228411
chmod -R u+w "$out"
229412
mkdir -p "$out/bin"
413+
mkdir -p "$out/src"
230414
231415
INTERPRETER_PATH="${
232416
if pkgs.stdenv.hostPlatform.system == "aarch64-linux"
@@ -253,6 +437,23 @@
253437
254438
install_bin ${db-backend}/bin/db-backend db-backend
255439
install_bin ${backend-manager}/bin/backend-manager backend-manager
440+
install_bin ${appimageCtUnwrapped}/bin/ct_unwrapped ct_unwrapped
441+
install_bin ${appimageDbBackendRecord}/bin/db-backend-record db-backend-record
442+
443+
cp -L ${appimageIndexJs}/index.js "$out/index.js"
444+
cp -L ${appimageIndexJs}/index.js "$out/src/index.js"
445+
446+
cp -L ${appimageServerIndexJs}/server_index.js "$out/server_index.js"
447+
cp -L ${appimageServerIndexJs}/server_index.js "$out/src/server_index.js"
448+
449+
cp -L ${appimageUiJs}/ui.js "$out/ui.js"
450+
cp -L ${appimageUiJs}/ui.js "$out/src/ui.js"
451+
452+
cp -L ${appimageSubwindowJs}/subwindow.js "$out/subwindow.js"
453+
cp -L ${appimageSubwindowJs}/subwindow.js "$out/src/subwindow.js"
454+
455+
patch_binary "$out/bin/ct_unwrapped" || true
456+
patch_binary "$out/bin/db-backend-record" || true
256457
'';
257458

258459
indexJavascript = stdenv.mkDerivation {

0 commit comments

Comments
 (0)