From bd349f5abc69ec1b53b82aac14b7534c76e089f9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 2 Sep 2025 12:18:22 +0300 Subject: [PATCH] feat(dx/desktop): support raw NixOS via LD_LIBRARY_PATH injection --- apps/desktop/scripts/rebuild.mts | 11 +++++++++++ apps/desktop/scripts/start.mts | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/desktop/scripts/rebuild.mts b/apps/desktop/scripts/rebuild.mts index a37c72075..f367c3cde 100644 --- a/apps/desktop/scripts/rebuild.mts +++ b/apps/desktop/scripts/rebuild.mts @@ -32,6 +32,17 @@ function rebuildNativeDependencies() { buildPath: desktopProjectRoot, electronVersion }); + + if (isNixOS()) { + console.log("Patching ELF..."); + + + + return execSync(`nix-shell -p auto-patchelf gcc.cc.lib --run "auto-patchelf --paths node_modules/better-sqlite3/build/Release/better_sqlite3.node --libs ${libStdPath}"`, { + cwd: desktopProjectRoot, + stdio: "inherit" + }); + } } function determineElectronVersion() { diff --git a/apps/desktop/scripts/start.mts b/apps/desktop/scripts/start.mts index df956fc48..17245205c 100644 --- a/apps/desktop/scripts/start.mts +++ b/apps/desktop/scripts/start.mts @@ -4,11 +4,15 @@ import { join } from "path"; const projectRoot = join(import.meta.dirname, ".."); +let LD_LIBRARY_PATH = undefined; +let electronPath = "electron"; if (isNixOS()) { resetPath(); + LD_LIBRARY_PATH = execSync("nix eval --raw nixpkgs#gcc.cc.lib").toString("utf-8") + "/lib"; + electronPath = execSync("nix eval --raw nixpkgs#electron_37").toString("utf-8") + "/bin/electron"; } -execSync("electron ./src/main.ts", { +execSync(`${electronPath} ./src/main.ts`, { stdio: "inherit", cwd: projectRoot, env: { @@ -18,6 +22,7 @@ execSync("electron ./src/main.ts", { TRILIUM_ENV: "dev", TRILIUM_DATA_DIR: "data", TRILIUM_RESOURCE_DIR: "../server/src", - BETTERSQLITE3_NATIVE_PATH: join(projectRoot, "node_modules/better-sqlite3/build/Release/better_sqlite3.node") + BETTERSQLITE3_NATIVE_PATH: join(projectRoot, "node_modules/better-sqlite3/build/Release/better_sqlite3.node"), + LD_LIBRARY_PATH } });