|
|
@@ -1,4 +1,4 @@
|
|
|
-{ lib, stdenv, stdenvNoCC, bun, fzf, ripgrep, makeBinaryWrapper }:
|
|
|
+{ lib, stdenvNoCC, bun, fzf, ripgrep, makeBinaryWrapper }:
|
|
|
args:
|
|
|
let
|
|
|
scripts = args.scripts;
|
|
|
@@ -28,64 +28,89 @@ stdenvNoCC.mkDerivation (finalAttrs: {
|
|
|
makeBinaryWrapper
|
|
|
];
|
|
|
|
|
|
- configurePhase = ''
|
|
|
- runHook preConfigure
|
|
|
- cp -R ${finalAttrs.node_modules}/. .
|
|
|
- runHook postConfigure
|
|
|
- '';
|
|
|
-
|
|
|
env.MODELS_DEV_API_JSON = args.modelsDev;
|
|
|
env.OPENCODE_VERSION = args.version;
|
|
|
env.OPENCODE_CHANNEL = "stable";
|
|
|
+ dontConfigure = true;
|
|
|
|
|
|
buildPhase = ''
|
|
|
runHook preBuild
|
|
|
|
|
|
- cp ${scripts + "/bun-build.ts"} bun-build.ts
|
|
|
+ cp -r ${finalAttrs.node_modules}/node_modules .
|
|
|
+ cp -r ${finalAttrs.node_modules}/packages .
|
|
|
|
|
|
- substituteInPlace bun-build.ts \
|
|
|
- --replace '@VERSION@' "${finalAttrs.version}"
|
|
|
+ (
|
|
|
+ cd packages/opencode
|
|
|
|
|
|
- export BUN_COMPILE_TARGET=${args.target}
|
|
|
- bun --bun bun-build.ts
|
|
|
+ chmod -R u+w ./node_modules
|
|
|
+ mkdir -p ./node_modules/@opencode-ai
|
|
|
+ rm -f ./node_modules/@opencode-ai/{script,sdk,plugin}
|
|
|
+ ln -s $(pwd)/../../packages/script ./node_modules/@opencode-ai/script
|
|
|
+ ln -s $(pwd)/../../packages/sdk/js ./node_modules/@opencode-ai/sdk
|
|
|
+ ln -s $(pwd)/../../packages/plugin ./node_modules/@opencode-ai/plugin
|
|
|
+
|
|
|
+ cp ${./bundle.ts} ./bundle.ts
|
|
|
+ chmod +x ./bundle.ts
|
|
|
+ bun run ./bundle.ts
|
|
|
+ )
|
|
|
|
|
|
runHook postBuild
|
|
|
'';
|
|
|
|
|
|
- dontStrip = true;
|
|
|
-
|
|
|
installPhase = ''
|
|
|
runHook preInstall
|
|
|
|
|
|
cd packages/opencode
|
|
|
- if [ ! -f opencode ]; then
|
|
|
- echo "ERROR: opencode binary not found in $(pwd)"
|
|
|
- ls -la
|
|
|
+ if [ ! -d dist ]; then
|
|
|
+ echo "ERROR: dist directory missing after bundle step"
|
|
|
exit 1
|
|
|
fi
|
|
|
- if [ ! -f opencode-worker.js ]; then
|
|
|
- echo "ERROR: opencode worker bundle not found in $(pwd)"
|
|
|
- ls -la
|
|
|
+
|
|
|
+ mkdir -p $out/lib/opencode
|
|
|
+ cp -r dist $out/lib/opencode/
|
|
|
+ chmod -R u+w $out/lib/opencode/dist
|
|
|
+
|
|
|
+ # Select bundled worker assets deterministically (sorted find output)
|
|
|
+ worker_file=$(find "$out/lib/opencode/dist" -type f \( -path '*/tui/worker.*' -o -name 'worker.*' \) | sort | head -n1)
|
|
|
+ parser_worker_file=$(find "$out/lib/opencode/dist" -type f -name 'parser.worker.*' | sort | head -n1)
|
|
|
+ if [ -z "$worker_file" ]; then
|
|
|
+ echo "ERROR: bundled worker not found"
|
|
|
exit 1
|
|
|
fi
|
|
|
|
|
|
- install -Dm755 opencode $out/bin/opencode
|
|
|
- install -Dm644 opencode-worker.js $out/bin/opencode-worker.js
|
|
|
- if [ -f opencode-assets.manifest ]; then
|
|
|
- while IFS= read -r asset; do
|
|
|
- [ -z "$asset" ] && continue
|
|
|
- if [ ! -f "$asset" ]; then
|
|
|
- echo "ERROR: referenced asset \"$asset\" missing"
|
|
|
- exit 1
|
|
|
- fi
|
|
|
- install -Dm644 "$asset" "$out/bin/$(basename "$asset")"
|
|
|
- done < opencode-assets.manifest
|
|
|
- fi
|
|
|
+ main_wasm=$(printf '%s\n' "$out"/lib/opencode/dist/tree-sitter-*.wasm | sort | head -n1)
|
|
|
+ wasm_list=$(find "$out/lib/opencode/dist" -maxdepth 1 -name 'tree-sitter-*.wasm' -print)
|
|
|
+ for patch_file in "$worker_file" "$parser_worker_file"; do
|
|
|
+ [ -z "$patch_file" ] && continue
|
|
|
+ [ ! -f "$patch_file" ] && continue
|
|
|
+ if [ -n "$wasm_list" ] && grep -q 'tree-sitter' "$patch_file"; then
|
|
|
+ # Rewrite wasm references to absolute store paths to avoid runtime resolve failures.
|
|
|
+ bun --bun ${scripts + "/patch-wasm.ts"} "$patch_file" "$main_wasm" $wasm_list
|
|
|
+ fi
|
|
|
+ done
|
|
|
+
|
|
|
+ mkdir -p $out/lib/opencode/node_modules
|
|
|
+ cp -r ../../node_modules/.bun $out/lib/opencode/node_modules/
|
|
|
+ mkdir -p $out/lib/opencode/node_modules/@opentui
|
|
|
+
|
|
|
+ mkdir -p $out/bin
|
|
|
+ makeWrapper ${bun}/bin/bun $out/bin/opencode \
|
|
|
+ --add-flags "run" \
|
|
|
+ --add-flags "$out/lib/opencode/dist/src/index.js" \
|
|
|
+ --prefix PATH : ${lib.makeBinPath [ fzf ripgrep ]} \
|
|
|
+ --argv0 opencode
|
|
|
+
|
|
|
runHook postInstall
|
|
|
'';
|
|
|
|
|
|
- postFixup = ''
|
|
|
- wrapProgram "$out/bin/opencode" --prefix PATH : ${lib.makeBinPath [ fzf ripgrep ]}
|
|
|
+ postInstall = ''
|
|
|
+ for pkg in $out/lib/opencode/node_modules/.bun/@opentui+core-* $out/lib/opencode/node_modules/.bun/@opentui+solid-* $out/lib/opencode/node_modules/.bun/@opentui+core@* $out/lib/opencode/node_modules/.bun/@opentui+solid@*; do
|
|
|
+ if [ -d "$pkg" ]; then
|
|
|
+ pkgName=$(basename "$pkg" | sed 's/@opentui+\([^@]*\)@.*/\1/')
|
|
|
+ ln -sf ../.bun/$(basename "$pkg")/node_modules/@opentui/$pkgName \
|
|
|
+ $out/lib/opencode/node_modules/@opentui/$pkgName
|
|
|
+ fi
|
|
|
+ done
|
|
|
'';
|
|
|
|
|
|
meta = {
|