Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@

perSystem = {pkgs, ...}: let
opencodePackage = pkgs.callPackage ./packages/opencode/package.nix {};
opencodeV2Package = pkgs.callPackage ./packages/opencode-v2/package.nix {};
in {
packages = {
default = opencodePackage;
opencode = opencodePackage;
opencode-v2 = opencodeV2Package;
};

apps = {
Expand All @@ -44,6 +46,11 @@
program = "${opencodePackage}/bin/opencode";
meta.description = "Run packaged opencode";
};
opencode-v2 = {
type = "app";
program = "${opencodeV2Package}/bin/opencode";
meta.description = "Run packaged opencode v2";
};
update = {
type = "app";
program = toString (pkgs.writeShellScript "opencode-flake-update" ''
Expand Down Expand Up @@ -92,6 +99,10 @@
imports = [self.homeManagerModules.default];
programs.opencode.package = self.packages.${pkgs.stdenv.hostPlatform.system}.opencode;
};
withPackageV2 = {pkgs, ...}: {
imports = [self.homeManagerModules.default];
programs.opencode.package = self.packages.${pkgs.stdenv.hostPlatform.system}.opencode-v2;
};
};

overlays.default = _final: prev: {
Expand Down
59 changes: 59 additions & 0 deletions packages/opencode-v2/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# OpenCode v2 terminal client (official Linux x64 npm release).
#
# Upstream ships a self-contained Bun-compiled binary, so this is a
# binary-fetch derivation: autoPatchelf only. The Bun payload must survive
# ELF fixup intact, hence dontStrip/dontPatchELF. V1 is built from source
# (packages/opencode); v2 has no equivalent source build here yet.
{
lib,
stdenvNoCC,
stdenv,
fetchurl,
autoPatchelfHook,
openssl,
versionCheckHook,
writableTmpDirAsHomeHook,
}: let
version = "2.0.21";
in
stdenvNoCC.mkDerivation {
pname = "opencode-v2";
inherit version;

src = fetchurl {
url = "https://registry.npmjs.org/@opencode/cli-linux-x64/-/cli-linux-x64-${version}.tgz";
hash = "sha512-intPGPRrEoZk+5Qq2dzYcq3Wv07vWvQrv56WieurupI9jGJSEAfT4a9Pi6YMW4tEW6SapAds/95K0egVS2YwiA==";
};

nativeBuildInputs = [autoPatchelfHook];
buildInputs = [stdenv.cc.cc.lib openssl];

dontConfigure = true;
dontBuild = true;
dontStrip = true;
dontPatchELF = true;

installPhase = ''
runHook preInstall
install -Dm755 bin/opencode $out/bin/opencode
runHook postInstall
'';

nativeInstallCheckInputs = [
versionCheckHook
# v2 writes logs under $HOME/.local/share; give installCheck a writable HOME.
writableTmpDirAsHomeHook
];
doInstallCheck = true;
versionCheckProgramArg = "--version";
versionCheckKeepEnvironment = ["HOME"];

meta = {
description = "AI coding agent built for the terminal (OpenCode v2)";
homepage = "https://opencode.ai";
license = lib.licenses.mit;
sourceProvenance = with lib.sourceTypes; [binaryNativeCode];
platforms = ["x86_64-linux"];
mainProgram = "opencode";
};
}
Loading