Something went wrong. Try again.
opencode v2 mirror
Something went wrong. Try again.
Nix
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118{ lib, stdenvNoCC, callPackage, bun, nodejs, sysctl, makeBinaryWrapper, models-dev, ripgrep, wayland, installShellFiles, versionCheckHook, writableTmpDirAsHomeHook, node_modules ? callPackage ./node-modules.nix { },}:stdenvNoCC.mkDerivation (finalAttrs: { pname = "opencode"; inherit (node_modules) version src; inherit node_modules;
nativeBuildInputs = [ bun nodejs # for patchShebangs node_modules installShellFiles makeBinaryWrapper models-dev writableTmpDirAsHomeHook ];
postPatch = '' # NOTE: Relax Bun version check to be a warning instead of an error substituteInPlace packages/script/src/index.ts \ --replace-fail 'throw new Error(`This script requires bun@''${expectedBunVersionRange}' \ 'console.warn(`Warning: This script requires bun@''${expectedBunVersionRange}' '';
configurePhase = '' runHook preConfigure
cp -R ${finalAttrs.node_modules}/. . patchShebangs node_modules patchShebangs packages/*/node_modules
runHook postConfigure '';
env.MODELS_DEV_API_JSON = "${models-dev}/dist/_api.json"; env.OPENCODE_DISABLE_MODELS_FETCH = true; env.OPENCODE_VERSION = finalAttrs.version; env.OPENCODE_CHANNEL = "prod"; env.NODE_OPTIONS = "--max-old-space-size=4096";
buildPhase = '' runHook preBuild
cd ./packages/cli bun --bun ./script/build.ts --single --skip-install
runHook postBuild '';
installPhase = '' runHook preInstall
install -Dm755 dist/cli-*/bin/opencode $out/bin/opencode
# OpenTUI dlopens Wayland for clipboard images. wrapProgram $out/bin/opencode \ --prefix PATH : ${ lib.makeBinPath ( [ ripgrep ] # bun runs sysctl to detect if running on rosetta2 ++ lib.optional stdenvNoCC.hostPlatform.isDarwin sysctl ) } ${lib.optionalString stdenvNoCC.hostPlatform.isLinux '' --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ wayland ]} ''}
ln -s opencode $out/bin/opencode2
runHook postInstall '';
postInstall = lib.optionalString (stdenvNoCC.buildPlatform.canExecute stdenvNoCC.hostPlatform) '' # trick yargs into also generating zsh completions installShellCompletion --cmd opencode \ --bash <($out/bin/opencode completion) \ --zsh <(SHELL=/bin/zsh $out/bin/opencode completion)
installShellCompletion --cmd opencode2 \ --bash <($out/bin/opencode2 completion) \ --zsh <(SHELL=/bin/zsh $out/bin/opencode2 completion) '';
nativeInstallCheckInputs = [ versionCheckHook writableTmpDirAsHomeHook ]; doInstallCheck = true; versionCheckKeepEnvironment = [ "HOME" "OPENCODE_DISABLE_MODELS_FETCH" ]; versionCheckProgramArg = "--version";
passthru = { env = finalAttrs.env; };
meta = { description = "The open source coding agent"; homepage = "https://opencode.ai"; license = lib.licenses.mit; mainProgram = "opencode"; inherit (node_modules.meta) platforms; };})