Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(dx/desktop): improve rebuilding experience on NixOS
Elian Doran26c7f0b0170e
diff --git a/apps/desktop/scripts/rebuild.mts b/apps/desktop/scripts/rebuild.mtsindex 25b341adab..635d4690f5 100644--- a/apps/desktop/scripts/rebuild.mts+++ b/apps/desktop/scripts/rebuild.mts@@ -1,8 +1,8 @@import { join } from "path";-import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "fs";+import { cpSync, existsSync, mkdirSync, rmSync } from "fs";import { execSync } from "child_process";import { rebuild } from "@electron/rebuild"-import { isNixOS, resetPath } from "../../../scripts/utils.mjs";+import { getElectronPath, isNixOS } from "../../../scripts/utils.mjs";import packageJson from "../package.json" with { type: "json" };const desktopProjectRoot = join(import.meta.dirname, "..");@@ -33,24 +33,14 @@ 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() {if (isNixOS()) {console.log("Detected NixOS, reading Electron version from PATH");- resetPath();try {- return execSync("electron --version", { }).toString("utf-8");+ return execSync(`${getElectronPath()} --version`, { }).toString("utf-8");} catch (e) {console.error("Got error while trying to read the Electron version from shell. Make sure that an Electron version is in the PATH (e.g. `nix-shell -p electron`)");process.exit(1);diff --git a/apps/desktop/scripts/start.mts b/apps/desktop/scripts/start.mtsindex a2151ba2dd..e283a70236 100644--- a/apps/desktop/scripts/start.mts+++ b/apps/desktop/scripts/start.mts@@ -1,18 +1,11 @@-import { execSync, spawnSync } from "child_process";-import { isNixOS, resetPath } from "../../../scripts/utils.mjs";+import { execSync } from "child_process";+import { getElectronPath, isNixOS } from "../../../scripts/utils.mjs";import { join } from "path";const projectRoot = join(import.meta.dirname, "..");+const LD_LIBRARY_PATH = isNixOS() && execSync("nix eval --raw nixpkgs#gcc.cc.lib").toString("utf-8") + "/lib";-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(`${electronPath} ./src/main.ts`, {+execSync(`${getElectronPath()} ./src/main.ts`, {stdio: "inherit",cwd: projectRoot,env: {diff --git a/scripts/utils.mts b/scripts/utils.mtsindex d8cefe4c51..ea63f3760c 100644--- a/scripts/utils.mts+++ b/scripts/utils.mts@@ -1,3 +1,4 @@+import { execSync } from "child_process";import { readFileSync } from "fs";import { platform } from "os";@@ -7,7 +8,7 @@ export function isNixOS() {return osReleaseFile.includes("ID=nixos");}-export function resetPath() {+function resetPath() {// On Unix-like systems, PATH is usually inherited from login shell// but npm prepends node_modules/.bin. Let's remove it:const origPath = process.env.PATH || "";@@ -18,3 +19,12 @@ export function resetPath() {.filter(p => !p.includes("node_modules/.bin")).join(":");}++export function getElectronPath() {+ if (isNixOS()) {+ resetPath();+ return execSync("nix eval --raw nixpkgs#electron_37").toString("utf-8") + "/bin/electron";+ } else {+ return "electron";+ }+}\ No newline at end of file