fix(run-local): default data dir to cwd, not the read-only nix store

'nix run' failed with ENOENT trying to mkdir inside the built package's
own Nix store path (.../the-commons-hollow-0.0.0/.data) - Nix store
paths are immutable by design, mkdir there can never succeed regardless
of permissions. The data directory must default to somewhere the
invoking user actually controls: process.cwd(), not the script's own
install location. Verified end to end through the real flake: 'nix
build' + 'nix run' from a separate writable directory now creates
.data there and serves real HTTP 200.
This commit is contained in:
OmO Orchestrator committed 2026-11-20 23:28:39 -05:00
1 parent 2751b3e701
commit 033db1bfd1
1 file changed
+9 -2
+9 -2
View File
@@ -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 }),
);