fix: set writable OD_DATA_DIR default for nix run (#1159)

Fixes #1157

When running via 'nix run github:nexu-io/open-design', the daemon
attempted to create runtime state under the Nix store package path:

  /nix/store/.../lib/open-design/.od/projects

The Nix store is read-only at runtime, causing startup to fail with
ENOENT when mkdir() tried to create the projects directory.

This commit updates the nix run wrapper to export OD_DATA_DIR with
a writable default ($HOME/.od) when the variable is unset. Users
can still override it by setting OD_DATA_DIR before running.

The Home Manager and NixOS modules already set OD_DATA_DIR, so they
are unaffected by this change.
This commit is contained in:
Nicholas-Xiong 2026-05-11 10:52:53 +08:00 committed by GitHub
parent d3b1804523
commit 2838a28585
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,9 +62,14 @@
# Wrap `od` with `--no-open` for `nix run`: the daemon package # Wrap `od` with `--no-open` for `nix run`: the daemon package
# builds the daemon workspace only, not `apps/web/out/`, so the # builds the daemon workspace only, not `apps/web/out/`, so the
# browser would otherwise auto-open onto an empty static dir. # browser would otherwise auto-open onto an empty static dir.
#
# Set OD_DATA_DIR to a writable location when unset. The Nix store
# is read-only at runtime, so the daemon cannot write to its default
# `<projectRoot>/.od` location under `nix run`.
apps.default = { apps.default = {
type = "app"; type = "app";
program = "${pkgs.writeShellScript "od-nix-run" '' program = "${pkgs.writeShellScript "od-nix-run" ''
export OD_DATA_DIR="''${OD_DATA_DIR:-$HOME/.od}"
exec ${daemon}/bin/od --no-open "$@" exec ${daemon}/bin/od --no-open "$@"
''}"; ''}";
meta.description = "Open Design local daemon (`od`)"; meta.description = "Open Design local daemon (`od`)";