diff options
| author | Albert O'Shea <[email protected]> | 2025-11-18 17:46:49 +1100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-18 00:46:49 -0600 |
| commit | 5e13527416e183c7ea6d1baa3528b5c30108372e (patch) | |
| tree | 6d839be0118b84974eacc670a93823974787faba /nix/opencode.nix | |
| parent | aba94c658f5c0987443196a5e850fdf7293d5006 (diff) | |
| download | opencode-5e13527416e183c7ea6d1baa3528b5c30108372e.tar.gz opencode-5e13527416e183c7ea6d1baa3528b5c30108372e.zip | |
feat: nix support for the nix folks (#3924)
Co-authored-by: opencode <[email protected]>
Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Diffstat (limited to 'nix/opencode.nix')
| -rw-r--r-- | nix/opencode.nix | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/nix/opencode.nix b/nix/opencode.nix new file mode 100644 index 000000000..bec299760 --- /dev/null +++ b/nix/opencode.nix @@ -0,0 +1,108 @@ +{ lib, stdenv, stdenvNoCC, bun, fzf, ripgrep, makeBinaryWrapper }: +args: +let + scripts = args.scripts; + mkModules = + attrs: + args.mkNodeModules ( + attrs + // { + canonicalizeScript = scripts + "/canonicalize-node-modules.ts"; + normalizeBinsScript = scripts + "/normalize-bun-binaries.ts"; + } + ); +in +stdenvNoCC.mkDerivation (finalAttrs: { + pname = "opencode"; + version = args.version; + + src = args.src; + + node_modules = mkModules { + version = finalAttrs.version; + src = finalAttrs.src; + }; + + nativeBuildInputs = [ + bun + 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"; + + buildPhase = '' + runHook preBuild + + cp ${scripts + "/bun-build.ts"} bun-build.ts + + substituteInPlace bun-build.ts \ + --replace '@VERSION@' "${finalAttrs.version}" + + export BUN_COMPILE_TARGET=${args.target} + bun --bun bun-build.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 + exit 1 + fi + if [ ! -f opencode-worker.js ]; then + echo "ERROR: opencode worker bundle not found in $(pwd)" + ls -la + 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 + runHook postInstall + ''; + + postFixup = '' + wrapProgram "$out/bin/opencode" --prefix PATH : ${lib.makeBinPath [ fzf ripgrep ]} + ''; + + meta = { + description = "AI coding agent built for the terminal"; + longDescription = '' + OpenCode is a terminal-based agent that can build anything. + It combines a TypeScript/JavaScript core with a Go-based TUI + to provide an interactive AI coding experience. + ''; + homepage = "https://github.com/sst/opencode"; + license = lib.licenses.mit; + platforms = [ + "aarch64-linux" + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + mainProgram = "opencode"; + }; +}) |
