83 lines
2.2 KiB
Nix
83 lines
2.2 KiB
Nix
{
|
|
lib,
|
|
stdenv,
|
|
fetchzip,
|
|
patchelf,
|
|
glibc,
|
|
}:
|
|
|
|
let
|
|
version = "1.14.39";
|
|
|
|
srcs = {
|
|
aarch64-darwin = {
|
|
url = "https://github.com/anomalyco/opencode/releases/download/v${version}/opencode-darwin-arm64.zip";
|
|
sha256 = "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5";
|
|
};
|
|
x86_64-darwin = {
|
|
url = "https://github.com/anomalyco/opencode/releases/download/v${version}/opencode-darwin-x64.zip";
|
|
sha256 = "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5";
|
|
};
|
|
x86_64-linux = {
|
|
url = "https://github.com/anomalyco/opencode/releases/download/v${version}/opencode-linux-x64.tar.gz";
|
|
sha256 = "1flvi0anw6irm83kh5kndqgs6nasbicharqc6pzxkxbsl37saarl";
|
|
};
|
|
aarch64-linux = {
|
|
url = "https://github.com/anomalyco/opencode/releases/download/v${version}/opencode-linux-arm64.tar.gz";
|
|
sha256 = "1samhrmpvq5ar1lf1k5f8851qkl8z4b8rmq7gwbnp42ysaqj5ac8";
|
|
};
|
|
};
|
|
|
|
src =
|
|
srcs.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
|
|
|
|
in
|
|
stdenv.mkDerivation {
|
|
pname = "opencode";
|
|
inherit version;
|
|
|
|
src = fetchzip {
|
|
inherit (src) url sha256;
|
|
};
|
|
|
|
# Bun standalone binaries have JS code appended after the ELF sections
|
|
# stripping/patching would remove or corrupt this appended data
|
|
dontStrip = true;
|
|
dontPatchELF = true;
|
|
|
|
nativeBuildInputs = lib.optionals stdenv.isLinux [ patchelf ];
|
|
|
|
installPhase = ''
|
|
runHook preInstall
|
|
|
|
install -Dm755 $src/opencode $out/bin/opencode
|
|
|
|
runHook postInstall
|
|
'';
|
|
|
|
# Manually patch the interpreter for bun standalone binaries on Linux
|
|
postFixup = lib.optionalString stdenv.isLinux ''
|
|
interpreter="${glibc}/lib/${
|
|
if stdenv.hostPlatform.system == "aarch64-linux" then
|
|
"ld-linux-aarch64.so.1"
|
|
else
|
|
"ld-linux-x86-64.so.2"
|
|
}"
|
|
patchelf --set-interpreter "$interpreter" $out/bin/opencode
|
|
'';
|
|
|
|
meta = with lib; {
|
|
description = "Terminal-based AI coding assistant";
|
|
homepage = "https://opencode.ai";
|
|
license = licenses.mit;
|
|
maintainers = [ ];
|
|
platforms = [
|
|
"aarch64-darwin"
|
|
"x86_64-darwin"
|
|
"x86_64-linux"
|
|
"aarch64-linux"
|
|
];
|
|
mainProgram = "opencode";
|
|
};
|
|
}
|