Skip to content

Build your personal knowledge base with Trilium Notes

fix(nix): not handling sqlite natives

Elian Doran94265f72b236
diff --git a/flake.nix b/flake.nix
index 4a539386c5..f8001a4489 100644
--- a/flake.nix
+++ b/flake.nix
@@ -225,11 +225,8 @@
desktop = makeApp {
app = "desktop";
- # pnpm throws an error at the end of `pnpm postinstall`, but it doesn't seem to matter:
- # ENOENT: no such file or directory, lstat
- # '/build/source/apps/desktop/node_modules/better-sqlite3/build/node_gyp_bins'
preBuildCommands = ''
- export npm_config_nodedir=${electron.headers}
+ export ELECTRON_NODEDIR=${electron.headers}
pnpm postinstall
'';
buildTask = "desktop:build";
@@ -286,7 +283,7 @@
edit-docs = makeApp {
app = "edit-docs";
preBuildCommands = ''
- export npm_config_nodedir=${electron.headers}
+ export ELECTRON_NODEDIR=${electron.headers}
pnpm postinstall
'';
buildTask = "edit-docs:build";
diff --git a/scripts/electron-rebuild.mts b/scripts/electron-rebuild.mts
index 9bea7ac8cd..059a6a4a85 100644
--- a/scripts/electron-rebuild.mts
+++ b/scripts/electron-rebuild.mts
@@ -52,6 +52,21 @@ async function rebuildNativeDependencies(projectRoot: string) {
console.log(`Rebuilding ${projectRoot} with ${electronVersion} for ${targetArch}...`);
const resolvedPath = resolve(projectRoot);
+
+ // Inside a Nix build, @electron/rebuild tries to download Electron headers
+ // from the internet which fails in the sandbox. Use node-gyp directly with
+ // the pre-fetched headers provided via ELECTRON_NODEDIR instead.
+ const nodedir = process.env.ELECTRON_NODEDIR;
+ if (process.env.NIX_BUILD_TOP && nodedir) {
+ const betterSqlite3 = join(resolvedPath, "node_modules/better-sqlite3");
+ console.log(`Nix build detected, running node-gyp directly for ${betterSqlite3}...`);
+ execSync(
+ `node-gyp rebuild --release --target=${electronVersion} --arch=${targetArch} --nodedir=${nodedir}`,
+ { cwd: betterSqlite3, stdio: "inherit" }
+ );
+ return;
+ }
+
await rebuild({
projectRootPath: resolvedPath,
buildPath: resolvedPath,