diff --git a/scripts/run-local.mjs b/scripts/run-local.mjs index acdf07f..4188d7d 100644 --- a/scripts/run-local.mjs +++ b/scripts/run-local.mjs @@ -14,8 +14,15 @@ import { fileURLToPath } from "node:url"; const ROOT = dirname(dirname(fileURLToPath(import.meta.url))); const DIST_DIR = join(ROOT, "dist"); -process.env.BLOB_DB_PATH ??= join(process.env.COMMONS_DATA_DIR ?? join(ROOT, ".data"), "blobs.sqlite3"); -process.env.EVENT_DB_PATH ??= join(process.env.COMMONS_DATA_DIR ?? join(ROOT, ".data"), "events.sqlite3"); +// ROOT (dist/, api/, this script itself) is the built package's own +// install path - under `nix run`, that's an immutable Nix store path, so +// it can NEVER be the data directory's default (mkdir there fails with +// ENOENT/EACCES, Nix store paths are read-only by design). The data dir +// must default to somewhere always writable regardless of how this +// script is invoked: the directory the user is actually running from. +const DATA_DIR = process.env.COMMONS_DATA_DIR ?? join(process.cwd(), ".data"); +process.env.BLOB_DB_PATH ??= join(DATA_DIR, "blobs.sqlite3"); +process.env.EVENT_DB_PATH ??= join(DATA_DIR, "events.sqlite3"); await import("node:fs/promises").then((fs) => fs.mkdir(dirname(process.env.BLOB_DB_PATH), { recursive: true }), );