-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpackage.nix
More file actions
73 lines (60 loc) · 2.01 KB
/
Copy pathpackage.nix
File metadata and controls
73 lines (60 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{ lib
, stdenv
, fetchurl
, patchelf
, glibc
}:
let
# Platform and architecture detection for npm package names
arch =
if stdenv.hostPlatform.isAarch64 then "arm64"
else if stdenv.hostPlatform.isx86_64 then "x64"
else throw "Unsupported architecture for opencode";
platform =
if stdenv.hostPlatform.isLinux then "linux"
else if stdenv.hostPlatform.isDarwin then "darwin"
else throw "Unsupported OS for opencode";
# Latest version
version = "1.3.13";
# SHA256 hashes for npm packages (nix base32 format)
hashes = {
x86_64-linux = "1b358lwgsjpc8j2qdvs9iv7fvkf9k51rdwqy0vh5xnlylrl0h4yp";
aarch64-linux = "1y9i1by85ydcqrfwnl8caiajgdgipwhp1lnvsq48mg1bs8kfcxy9";
x86_64-darwin = "1l0sbk26ld0cdahk6bdz2wj82r75h7awpy1xqjn6b2gzl064ppfd";
aarch64-darwin = "1yzfz79p4r1q1xrn2qk1xjkil0k70vr11fj7ihmrc71qbdlab3sj";
};
# Fetch the platform-specific npm package
src = fetchurl {
url = "https://registry.npmjs.org/opencode-${platform}-${arch}/-/opencode-${platform}-${arch}-${version}.tgz";
sha256 = hashes.${stdenv.hostPlatform.system};
};
in
stdenv.mkDerivation {
pname = "opencode";
inherit version;
inherit src;
# Do NOT use autoPatchelfHook - it corrupts the Bun-based binary
nativeBuildInputs = [ patchelf ];
# npm tarballs have a 'package' directory
sourceRoot = "package";
# Disable all default fixup phases that might corrupt the binary
dontStrip = true;
dontPatchELF = true;
dontPatchShebangs = true;
installPhase = ''
runHook preInstall
# Install binary
install -Dm755 bin/opencode $out/bin/opencode
# Only patch the interpreter, nothing else
patchelf --set-interpreter ${glibc}/lib/ld-linux-x86-64.so.2 $out/bin/opencode
runHook postInstall
'';
meta = with lib; {
description = "AI coding agent built for the terminal (latest version from npm)";
homepage = "https://opencode.ai";
license = licenses.mit;
platforms = platforms.linux ++ platforms.darwin;
maintainers = [ ];
mainProgram = "opencode";
};
}