Repository navigation
Expand file tree
/
Copy pathpackage.nix
More file actions
105 lines (94 loc) · 2.96 KB
/
Copy pathpackage.nix
File metadata and controls
105 lines (94 loc) · 2.96 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
lib,
mkUpdater,
stdenv,
makeWrapper,
formatelf,
ripgrep,
wayland,
libxcb,
platformSource,
versionCheckHook,
versionCheckHomeHook,
flake,
}:
let
# OpenCode 2 ships as platform-specific Bun executables on npm
# (@opencode/cli-<platform>).
source = platformSource {
hashesFile = ./hashes.json;
platforms = {
x86_64-linux = "linux-x64";
aarch64-linux = "linux-arm64";
aarch64-darwin = "darwin-arm64";
};
urlTemplate = "https://registry.npmjs.org/@opencode/cli-{platform}/-/cli-{platform}-{version}.tgz";
};
in
stdenv.mkDerivation {
pname = "opencode2";
inherit (source) version src;
sourceRoot = "package";
nativeBuildInputs = [ makeWrapper ] ++ lib.optionals stdenv.hostPlatform.isLinux [ formatelf ];
# The native addons embedded in the Bun executable cannot be patched: the
# file watcher needs libstdc++ and OpenTUI dlopen()s libwayland-client and
# libxcb for the clipboard. Unlike DT_RUNPATH, the executable's DT_RPATH also
# applies to lookups made by the libraries it loads.
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
formatelf --force-rpath --set-rpath ${
lib.makeLibraryPath [
stdenv.cc.cc.lib
wayland
libxcb
]
} $out/bin/.opencode2-wrapped
'';
dontBuild = true;
# Bun-compiled executable; stripping corrupts the embedded payload.
dontStrip = true;
# Install only the executable; the tarball also contains ~49 MiB of source
# maps that are not needed at runtime.
installPhase = ''
runHook preInstall
# Upstream's binary is `opencode`; install as opencode2 so it can coexist
# with the v1 `opencode` package.
install -Dm755 bin/opencode $out/bin/opencode2
wrapProgram $out/bin/opencode2 \
--prefix PATH : ${lib.makeBinPath [ ripgrep ]}
runHook postInstall
'';
doInstallCheck = true;
nativeInstallCheckInputs = [
versionCheckHook
versionCheckHomeHook
];
versionCheckProgramArg = "--version";
passthru.category = "AI Coding Agents";
passthru.updater = mkUpdater (
source.updater
// {
versionSource = {
type = "npm";
package = "@opencode/cli";
# No tag: the npm source defaults to `latest`, the stable 2.x line.
};
}
);
meta = {
description = "OpenCode 2 CLI";
longDescription = ''
OpenCode 2 is OpenCode's next-generation CLI. The single
executable includes the terminal interface and server, and can run with
a private server, reuse a background service, or connect to a remote
server.
'';
homepage = "https://opencode.ai";
changelog = "https://github.com/anomalyco/opencode/commits/v2";
downloadPage = "https://www.npmjs.com/package/@opencode/cli?activeTab=versions";
license = lib.licenses.mit;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
maintainers = with flake.lib.maintainers; [ iainlane ];
mainProgram = "opencode2";
platforms = source.platforms;
};
}