summaryrefslogtreecommitdiffhomepage
path: root/nix/scripts
diff options
context:
space:
mode:
authorCaleb Norton <[email protected]>2026-01-18 11:14:13 -0600
committerGitHub <[email protected]>2026-01-18 11:14:13 -0600
commitdac099a4892689d11abedb0fcc1098b50e0958c8 (patch)
treeb47a7a4bae294e0d4222fac21605a380d54b3341 /nix/scripts
parent5009f10406c15c4b69c04fa626756ee7bf81b300 (diff)
downloadopencode-dac099a4892689d11abedb0fcc1098b50e0958c8.tar.gz
opencode-dac099a4892689d11abedb0fcc1098b50e0958c8.zip
feat(nix): overhaul nix flake and packages (#9032)
Diffstat (limited to 'nix/scripts')
-rw-r--r--nix/scripts/bun-build.ts120
-rw-r--r--nix/scripts/patch-wasm.ts43
2 files changed, 0 insertions, 163 deletions
diff --git a/nix/scripts/bun-build.ts b/nix/scripts/bun-build.ts
deleted file mode 100644
index e607676cb..000000000
--- a/nix/scripts/bun-build.ts
+++ /dev/null
@@ -1,120 +0,0 @@
-import solidPlugin from "./packages/opencode/node_modules/@opentui/solid/scripts/solid-plugin"
-import path from "path"
-import fs from "fs"
-
-const version = "@VERSION@"
-const pkg = path.join(process.cwd(), "packages/opencode")
-const parser = fs.realpathSync(path.join(pkg, "./node_modules/@opentui/core/parser.worker.js"))
-const worker = "./src/cli/cmd/tui/worker.ts"
-const target = process.env["BUN_COMPILE_TARGET"]
-
-if (!target) {
- throw new Error("BUN_COMPILE_TARGET not set")
-}
-
-process.chdir(pkg)
-
-const manifestName = "opencode-assets.manifest"
-const manifestPath = path.join(pkg, manifestName)
-
-const readTrackedAssets = () => {
- if (!fs.existsSync(manifestPath)) return []
- return fs
- .readFileSync(manifestPath, "utf8")
- .split("\n")
- .map((line) => line.trim())
- .filter((line) => line.length > 0)
-}
-
-const removeTrackedAssets = () => {
- for (const file of readTrackedAssets()) {
- const filePath = path.join(pkg, file)
- if (fs.existsSync(filePath)) {
- fs.rmSync(filePath, { force: true })
- }
- }
-}
-
-const assets = new Set<string>()
-
-const addAsset = async (p: string) => {
- const file = path.basename(p)
- const dest = path.join(pkg, file)
- await Bun.write(dest, Bun.file(p))
- assets.add(file)
-}
-
-removeTrackedAssets()
-
-const result = await Bun.build({
- conditions: ["browser"],
- tsconfig: "./tsconfig.json",
- plugins: [solidPlugin],
- sourcemap: "external",
- entrypoints: ["./src/index.ts", parser, worker],
- define: {
- OPENCODE_VERSION: `'@VERSION@'`,
- OTUI_TREE_SITTER_WORKER_PATH: "/$bunfs/root/" + path.relative(pkg, parser).replace(/\\/g, "/"),
- OPENCODE_CHANNEL: "'latest'",
- },
- compile: {
- target,
- outfile: "opencode",
- autoloadBunfig: false,
- autoloadDotenv: false,
- //@ts-ignore (bun types aren't up to date)
- autoloadTsconfig: true,
- autoloadPackageJson: true,
- execArgv: ["--user-agent=opencode/" + version, "--use-system-ca", "--"],
- windows: {},
- },
-})
-
-if (!result.success) {
- console.error("Build failed!")
- for (const log of result.logs) {
- console.error(log)
- }
- throw new Error("Compilation failed")
-}
-
-const assetOutputs = result.outputs?.filter((x) => x.kind === "asset") ?? []
-for (const x of assetOutputs) {
- await addAsset(x.path)
-}
-
-const bundle = await Bun.build({
- entrypoints: [worker],
- tsconfig: "./tsconfig.json",
- plugins: [solidPlugin],
- target: "bun",
- outdir: "./.opencode-worker",
- sourcemap: "none",
-})
-
-if (!bundle.success) {
- console.error("Worker build failed!")
- for (const log of bundle.logs) {
- console.error(log)
- }
- throw new Error("Worker compilation failed")
-}
-
-const workerAssets = bundle.outputs?.filter((x) => x.kind === "asset") ?? []
-for (const x of workerAssets) {
- await addAsset(x.path)
-}
-
-const output = bundle.outputs.find((x) => x.kind === "entry-point")
-if (!output) {
- throw new Error("Worker build produced no entry-point output")
-}
-
-const dest = path.join(pkg, "opencode-worker.js")
-await Bun.write(dest, Bun.file(output.path))
-fs.rmSync(path.dirname(output.path), { recursive: true, force: true })
-
-const list = Array.from(assets)
-await Bun.write(manifestPath, list.length > 0 ? list.join("\n") + "\n" : "")
-
-console.log("Build successful!")
diff --git a/nix/scripts/patch-wasm.ts b/nix/scripts/patch-wasm.ts
deleted file mode 100644
index 88a06c2bd..000000000
--- a/nix/scripts/patch-wasm.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/usr/bin/env bun
-
-import fs from "fs"
-import path from "path"
-
-/**
- * Rewrite tree-sitter wasm references inside a JS file to absolute paths.
- * argv: [node, script, file, mainWasm, ...wasmPaths]
- */
-const [, , file, mainWasm, ...wasmPaths] = process.argv
-
-if (!file || !mainWasm) {
- console.error("usage: patch-wasm <file> <mainWasm> [wasmPaths...]")
- process.exit(1)
-}
-
-const content = fs.readFileSync(file, "utf8")
-const byName = new Map<string, string>()
-
-for (const wasm of wasmPaths) {
- const name = path.basename(wasm)
- byName.set(name, wasm)
-}
-
-let next = content
-
-for (const [name, wasmPath] of byName) {
- next = next.replaceAll(name, wasmPath)
-}
-
-next = next.replaceAll("tree-sitter.wasm", mainWasm).replaceAll("web-tree-sitter/tree-sitter.wasm", mainWasm)
-
-// Collapse any relative prefixes before absolute store paths (e.g., "../../../..//nix/store/...")
-const nixStorePrefix = process.env.NIX_STORE || "/nix/store"
-next = next.replace(/(\.\/)+/g, "./")
-next = next.replace(
- new RegExp(`(\\.\\.\\/)+\\/{1,2}(${nixStorePrefix.replace(/^\//, "").replace(/\//g, "\\/")}[^"']+)`, "g"),
- "/$2",
-)
-next = next.replace(new RegExp(`(["'])\\/{2,}(\\/${nixStorePrefix.replace(/\//g, "\\/")}[^"']+)(["'])`, "g"), "$1$2$3")
-next = next.replace(new RegExp(`(["'])\\/\\/(${nixStorePrefix.replace(/\//g, "\\/")}[^"']+)(["'])`, "g"), "$1$2$3")
-
-if (next !== content) fs.writeFileSync(file, next)