mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
* nix: add official flake with home-manager and nixos modules
* Pin pnpm version
* Format README.md
* Populate PATH files to discover installed CLIs
* Revert "Populate PATH files to discover installed CLIs"
This reverts commit 18d88781a88b8781913cf5a8b680dfb38eabf7e4.
* Fix missing sqlite issue
* Fix system issue
* Reapply "Populate PATH files to discover installed CLIs"
This reverts commit d02ea994e6.
* Handle different ports for web frontend
* Provide documentation for getting pnpm hash
* Enable nix flake checks for code changes
* Set `OD_WEB_PORT` on daemon when declared
* fix: Fix environmentFile for macOS targets
* chore: Ignore nix and direnv related files
* fix: Read version directly from `package.json`
* feat: Make nix shell entry prettier
* chore: Update pnpm hashes
* chore: Bump `pnpm` hashes
* docs: Add blurb about dev shell in `README.md`
* Address review comments
* Add support for `OD_WEB_ORIGINS`
* Fix `isLocalSameOrigin`
* Update pnpm checksums
* docs: Update documentation on host origins
* Move allowedOrigins mapping out of the webFrontend.enable guard
* fix: Bump pnpm hashes
* Remove changes to `daemon` with `main` changes
`main` merged a feature that addressed our need for allowed origins.
Since this feature branch no longer needs it, remove any remaining
changes in `daemon` code so that this is a pure Nix change.
* Update documentation around `OD_DAEMON_URL`
* Rewrite option docs to match same-origin proxy contract
The port, webFrontend, and webFrontend.port option descriptions still
described OD_DAEMON_URL as the runtime contract for the SPA, but the
SPA issues relative /api/*, /artifacts/*, /frames/* requests and there
is no runtime daemon-URL injection. Rewrite the three blocks to
describe what the caddy / custom proxy must actually do.
* Document daemon-side requirements for custom-server proxy paths
The bring-your-own-server path in section (3) and the same-origin
contract in section (4) understated what the daemon needs: any proxy
whose origin differs from the daemon's bind (including loopback
split-port like 127.0.0.1:8080 while the daemon stays on :7457) is
403'd by the daemon's same-origin gate until told about that origin.
Add a callout under section (3)'s table, expand section (4) with a
decision table covering same-port, loopback split-port (OD_WEB_PORT or
webFrontend.allowedOrigins), and non-loopback (webFrontend.allowedOrigins)
cases, and rewrite the webFrontend.allowedOrigins option description to
enumerate the cases where it's required and surface OD_WEB_PORT as an
alternative for the loopback split-port case.
---------
Co-authored-by: lefarcen <935902669@qq.com>
179 lines
6.3 KiB
Nix
179 lines
6.3 KiB
Nix
{
|
|
lib,
|
|
stdenv,
|
|
dream2nix,
|
|
nixpkgs,
|
|
system,
|
|
nodejs,
|
|
pnpm_10,
|
|
fetchPnpmDeps,
|
|
pnpmConfigHook,
|
|
src,
|
|
makeWrapper,
|
|
python3,
|
|
gnumake,
|
|
pkg-config,
|
|
}:
|
|
# Builds the @open-design/daemon workspace package — produces $out/bin/od.
|
|
#
|
|
# Implementation note on dream2nix:
|
|
# The flake takes `dream2nix` as an input (per the project's Nix
|
|
# contract) but the build itself uses stdenv.mkDerivation. dream2nix's
|
|
# nodejs builders consume npm's package-lock.json — they have no
|
|
# first-class pnpm-lock.yaml + workspace builder yet. When upstream
|
|
# ships one, swap this file for a thin dream2nix module — the inputs
|
|
# are already wired.
|
|
#
|
|
# pnpm version note:
|
|
# `package.json` declares `engines.pnpm: ">=10.33.2 <11"` and pnpm
|
|
# enforces this on `pnpm install` (regardless of `engine-strict`).
|
|
# nixpkgs currently ships 10.33.0, which is rejected. The flake
|
|
# overrides `pkgs.pnpm_10` to fetch the 10.33.2 tarball from npm —
|
|
# see flake.nix for the override and how to bump the hash when
|
|
# `packageManager` advances.
|
|
#
|
|
# Workspace siblings the daemon depends on (contracts, sidecar-proto,
|
|
# sidecar, platform) are built in dependency order before the daemon
|
|
# itself; tsc emits each package's dist/, which is what the daemon
|
|
# resolves at runtime via pnpm's symlinked node_modules.
|
|
let
|
|
pname = "open-design-daemon";
|
|
version = (lib.importJSON ../package.json).version;
|
|
|
|
# Vendored pnpm store. The hash MUST be pinned on first build:
|
|
# `nix build .#daemon` will fail with the expected hash printed; copy
|
|
# that into `pnpmDepsHash` below. Bump it whenever pnpm-lock.yaml
|
|
# changes.
|
|
pnpmDepsHash = "sha256-KF3Mld72/iau+pJmA7HvnanRx8VLtDP0N624SKrtrrc=";
|
|
# pnpmDepsHash = lib.fakeHash;
|
|
in
|
|
stdenv.mkDerivation (finalAttrs: {
|
|
inherit pname version src;
|
|
|
|
nativeBuildInputs = [
|
|
nodejs
|
|
pnpm_10
|
|
pnpmConfigHook
|
|
makeWrapper
|
|
# Required to rebuild better-sqlite3's native binding from source.
|
|
# node-gyp drives this via Python; gnumake/pkg-config + the C++
|
|
# compiler from stdenv complete the toolchain.
|
|
python3
|
|
gnumake
|
|
pkg-config
|
|
];
|
|
|
|
pnpmDeps = fetchPnpmDeps {
|
|
inherit (finalAttrs) pname version src;
|
|
hash = pnpmDepsHash;
|
|
fetcherVersion = 3;
|
|
};
|
|
|
|
env.NODE_ENV = "production";
|
|
|
|
# pnpm_10.configHook runs in postConfigureHooks: it unpacks
|
|
# `pnpmDeps`, points pnpm at the unpacked store, and runs
|
|
# `pnpm install --offline --ignore-scripts --frozen-lockfile`.
|
|
# No custom configurePhase needed.
|
|
|
|
buildPhase = ''
|
|
runHook preBuild
|
|
|
|
# Build better-sqlite3's native binding from source.
|
|
#
|
|
# Why from source on Node 24:
|
|
# better-sqlite3 (even 12.9.0, latest as of 2026-05) only
|
|
# publishes prebuilds up to node-v131 (Node 22). No v137
|
|
# (Node 24) prebuild exists. `prebuild-install` would itself
|
|
# fail the GitHub fetch and fall through to a compile, so we
|
|
# skip the download attempt entirely and compile.
|
|
#
|
|
# Why not `pnpm rebuild`:
|
|
# In pnpm 10, `onlyBuiltDependencies` interacts with the
|
|
# "approve-builds" consent gate; `pnpm rebuild <pkg>` silently
|
|
# no-ops in some configurations. Invoke node-gyp directly to
|
|
# sidestep all of that.
|
|
#
|
|
# Env vars:
|
|
# * npm_config_nodedir → use the headers shipped with the
|
|
# nixpkgs nodejs we're already building against, so node-gyp
|
|
# doesn't try to fetch them from nodejs.org/dist (no network
|
|
# in the build sandbox).
|
|
# * npm_config_build_from_source → tell better-sqlite3's
|
|
# prebuild-install fallback chain to skip the CDN download
|
|
# and compile.
|
|
#
|
|
# node-gyp lookup:
|
|
# nixpkgs nodejs ships node-gyp bundled inside npm at
|
|
# ${nodejs}/lib/node_modules/npm/bin/node-gyp-bin. Putting
|
|
# that on PATH gives us a `node-gyp` shim without depending
|
|
# on pnpm-exec resolving from inside better-sqlite3's tree
|
|
# (better-sqlite3 doesn't list node-gyp as a direct dep).
|
|
export npm_config_nodedir=${nodejs}
|
|
export npm_config_build_from_source=true
|
|
export PATH="${nodejs}/lib/node_modules/npm/bin/node-gyp-bin:$PATH"
|
|
|
|
bsq_dir=$(find node_modules/.pnpm -mindepth 2 -maxdepth 4 \
|
|
-type d -path '*/better-sqlite3@*/node_modules/better-sqlite3' \
|
|
-print -quit)
|
|
if [ -z "$bsq_dir" ]; then
|
|
echo "ERROR: better-sqlite3 not found under node_modules/.pnpm — pnpm install may have failed" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Building better-sqlite3 from source at $bsq_dir"
|
|
( cd "$bsq_dir" && node-gyp rebuild --release --build-from-source )
|
|
|
|
# Fail fast if the .node file didn't land where bindings.js
|
|
# looks for it. Without this assertion, a silent skip produces
|
|
# a "valid" derivation that crashes at runtime with
|
|
# "Could not locate the bindings file".
|
|
if [ ! -f "$bsq_dir/build/Release/better_sqlite3.node" ]; then
|
|
echo "ERROR: better_sqlite3.node was not produced at $bsq_dir/build/Release/" >&2
|
|
find "$bsq_dir" -name '*.node' -print >&2 || true
|
|
exit 1
|
|
fi
|
|
|
|
for target in \
|
|
packages/contracts \
|
|
packages/sidecar-proto \
|
|
packages/sidecar \
|
|
packages/platform \
|
|
apps/daemon
|
|
do
|
|
pnpm -C "$target" run --if-present build
|
|
done
|
|
runHook postBuild
|
|
'';
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
mkdir -p $out/lib/open-design $out/bin
|
|
|
|
# Copy the whole workspace tree — pnpm's symlinks under node_modules
|
|
# resolve sibling packages by relative paths, so we cannot prune to
|
|
# just apps/daemon.
|
|
cp -r . $out/lib/open-design/
|
|
|
|
chmod +x $out/lib/open-design/apps/daemon/dist/cli.js
|
|
|
|
makeWrapper ${nodejs}/bin/node $out/bin/od \
|
|
--add-flags $out/lib/open-design/apps/daemon/dist/cli.js \
|
|
--set NODE_ENV production
|
|
runHook postInstall
|
|
'';
|
|
|
|
passthru = {
|
|
inherit nodejs;
|
|
pnpmDeps = finalAttrs.pnpmDeps;
|
|
};
|
|
|
|
meta = with lib; {
|
|
description = "Open Design daemon — local agent orchestrator + API (`od` CLI)";
|
|
homepage = "https://github.com/nexu-io/open-design";
|
|
license = licenses.asl20;
|
|
mainProgram = "od";
|
|
platforms = platforms.linux ++ platforms.darwin;
|
|
};
|
|
})
|