mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 07:08:55 +02:00
feat(dx/desktop): improve rebuilding experience on NixOS
This commit is contained in:
parent
d058dbe9af
commit
26c7f0b017
@ -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);
|
||||
|
@ -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: {
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user