From 033db1bfd16108d60762bc1d5d58b62ba56dc453 Mon Sep 17 00:00:00 2001 From: OmO Orchestrator Date: Fri, 20 Nov 2026 23:28:39 -0500 Subject: [PATCH] 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. --- scripts/run-local.mjs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 }), );