Something went wrong. Try again.
Noah's NUR repo
Something went wrong. Try again.
2.9 kB · 108 lines
Nix
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109{ autoPatchelfHook, fetchurl, lib, makeBinaryWrapper, ripgrep, stdenv, stdenvNoCC,}:
let version = "2.0.26"; artifacts = { "aarch64-darwin" = { artifact = "cli-darwin-arm64"; hash = "sha512-XklldeO6eWgG8vkPNLcdlBPEm1Y+/tyhEXGZvXbk8uytpPP7SEVV2R9oZ98NMSSPH9kBAO/+Xo4sKfvD6CHAsw=="; }; "x86_64-darwin" = { artifact = "cli-darwin-x64-baseline"; hash = "sha512-A4t57iwRo8gh4bKX/tyn/zTmVCdPZMPLNsoJeR+TbskpC1idpjc7qZsdYRPIBBTgzK++LjWhe9vyxqWOFglCXQ=="; }; "aarch64-linux" = { artifact = "cli-linux-arm64"; hash = "sha512-IG316I8wVqndohzFAoWNeH83eMA8sKQFRtMeuk2Wfg4DU1haCSgzAJz3/gbytjwh6bXdWR7V3FCSrfjoraKDgw=="; }; "x86_64-linux" = { artifact = "cli-linux-x64"; hash = "sha512-UIA2/1Ik8HaN54C4xp7H+OHgRfq995XUixrX+kLmFs8EPn1fAcmn3OoiN+3c3Vc3jEV/LHmj0Cy1SL6nW4wdGw=="; }; }; inherit (artifacts.${stdenvNoCC.hostPlatform.system}) artifact hash; wrapperArgs = [ "--prefix" "PATH" ":" (lib.makeBinPath [ ripgrep ]) ] ++ lib.optionals stdenv.hostPlatform.isLinux [ "--prefix" "LD_LIBRARY_PATH" ":" (lib.makeLibraryPath [ stdenv.cc.cc.lib ]) ] ++ [ "--set" "OPENCODE_DISABLE_AUTOUPDATE" "true" ];instdenvNoCC.mkDerivation { pname = "opencode-v2"; inherit version;
src = fetchurl { url = "https://registry.npmjs.org/@opencode/${artifact}/-/${artifact}-${version}.tgz"; inherit hash; };
sourceRoot = "package"; nativeBuildInputs = [ makeBinaryWrapper ] ++ lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]; buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ stdenv.cc.cc.lib ]; dontBuild = true; # Bun standalone executables store their application payload after the ELF # image. Stripping the binary discards that payload and leaves a plain Bun # runtime that only prints Bun's help. dontStrip = true; doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
installPhase = '' runHook preInstall
install -Dm755 bin/opencode $out/bin/opencode wrapProgram $out/bin/opencode ${lib.escapeShellArgs wrapperArgs}
runHook postInstall '';
installCheckPhase = '' export HOME="$TMPDIR" $out/bin/opencode --help > help.txt grep -q 'opencode' help.txt $out/bin/opencode serve --stdio > serve.txt grep -q '"url"' serve.txt if grep -q 'Bun is a fast JavaScript runtime' help.txt; then echo 'opencode payload was removed from the Bun standalone executable' >&2 exit 1 fi '';
meta = { description = "OpenCode 2.0"; homepage = "https://opencode.ai"; license = lib.licenses.mit; mainProgram = "opencode"; maintainers = [ { email = "noah@packetlost.dev"; github = "chiefnoah"; githubId = 3588683; name = "Noah Pederson"; } ]; platforms = builtins.attrNames artifacts; };}