trilium/scripts/utils.mts
Elian Doran df1b87e3ac
Some checks failed
Checks / main (push) Has been cancelled
CodeQL Advanced / Analyze (${{ matrix.language }}) (none, actions) (push) Has been cancelled
CodeQL Advanced / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled
Dev / Test development (push) Has been cancelled
/ Check Docker build (Dockerfile) (push) Has been cancelled
/ Check Docker build (Dockerfile.alpine) (push) Has been cancelled
playwright / main (push) Has been cancelled
Dev / Build Docker image (push) Has been cancelled
Dev / Check Docker build (Dockerfile) (push) Has been cancelled
Dev / Check Docker build (Dockerfile.alpine) (push) Has been cancelled
/ Build Docker images (Dockerfile, ubuntu-24.04-arm, linux/arm/v7) (push) Has been cancelled
/ Build Docker images (Dockerfile, ubuntu-24.04-arm, linux/arm/v8) (push) Has been cancelled
/ Build Docker images (Dockerfile, ubuntu-24.04-arm, linux/arm64) (push) Has been cancelled
/ Build Docker images (Dockerfile.alpine, ubuntu-latest, linux/amd64) (push) Has been cancelled
/ Merge manifest lists (push) Has been cancelled
chore(dx/nix): fix flake partially
2025-09-04 12:12:23 +03:00

45 lines
1.4 KiB
TypeScript

import { execSync } from "child_process";
import { existsSync, readFileSync } from "fs";
import { platform } from "os";
export function isNixOS() {
if (platform() !== "linux") return false;
const osReleasePath = "/etc/os-release";
if (existsSync(osReleasePath)) {
const osReleaseFile = readFileSync(osReleasePath, "utf-8");
return osReleaseFile.includes("ID=nixos");
} else {
return !!process.env.NIX_STORE;
}
}
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 || "";
// npm usually adds something like ".../node_modules/.bin"
process.env.PATH = origPath
.split(":")
.filter(p => !p.includes("node_modules/.bin"))
.join(":");
}
export function getElectronPath() {
if (isNixOS()) {
resetPath();
try {
const path = execSync("which electron").toString("utf-8").trimEnd();
return path;
} catch (e) {
// Nothing to do, since we have a fallback below.
}
console.log("Using default since no Electron is available in path.");
return execSync("nix eval --raw nixpkgs#electron_37").toString("utf-8") + "/bin/electron";
} else {
return "electron";
}
}