pull/16163/merge
Caleb Norton 2026-04-08 05:28:21 +00:00 committed by GitHub
commit d9117da0fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 104 additions and 14 deletions

View File

@ -37,16 +37,17 @@
node_modules = final.callPackage ./nix/node_modules.nix {
inherit rev;
};
in
rec {
opencode = final.callPackage ./nix/opencode.nix {
inherit node_modules;
};
desktop = final.callPackage ./nix/desktop.nix {
opencode-desktop = final.callPackage ./nix/desktop.nix {
inherit opencode;
};
opencode-electron = final.callPackage ./nix/desktop-electron.nix {
inherit opencode;
};
in
{
inherit opencode;
opencode-desktop = desktop;
};
};
@ -56,16 +57,18 @@
node_modules = pkgs.callPackage ./nix/node_modules.nix {
inherit rev;
};
in
rec {
default = opencode;
opencode = pkgs.callPackage ./nix/opencode.nix {
inherit node_modules;
};
desktop = pkgs.callPackage ./nix/desktop.nix {
opencode-desktop = pkgs.callPackage ./nix/desktop.nix {
inherit opencode;
};
opencode-electron = pkgs.callPackage ./nix/desktop-electron.nix {
inherit opencode;
};
in
{
default = opencode;
inherit opencode desktop;
# Updater derivation with fakeHash - build fails and reveals correct hash
node_modules_updater = node_modules.override {
hash = pkgs.lib.fakeHash;

View File

@ -0,0 +1,89 @@
{
lib,
stdenv,
bun,
nodejs,
electron_40,
makeWrapper,
writableTmpDirAsHomeHook,
opencode,
}:
let
electron = electron_40;
in
stdenv.mkDerivation (finalAttrs: {
pname = "opencode-electron";
inherit (opencode) version src node_modules;
nativeBuildInputs = [
bun
nodejs
makeWrapper
writableTmpDirAsHomeHook
];
env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
# https://github.com/electron/electron/issues/31121
postPatch = lib.optionalString stdenv.isLinux ''
BASE_PATH=packages/desktop-electron
FILES=(src/main/cli.ts src/main/windows.ts)
for file in "''${FILES[@]}"; do
substituteInPlace $BASE_PATH/$file \
--replace-fail "process.resourcesPath" "'$out/opt/opencode-electron/resources'"
done
'';
preBuild = ''
cp -r "${electron.dist}" $HOME/.electron-dist
chmod -R u+w $HOME/.electron-dist
cp -R ${finalAttrs.node_modules}/. .
patchShebangs node_modules
patchShebangs packages/desktop-electron/node_modules
cp ${lib.getExe opencode} packages/desktop-electron/resources/opencode-cli
'';
buildPhase = ''
runHook preBuild
cd packages/desktop-electron
bun run build
npx electron-builder --dir \
--config electron-builder.config.ts \
--config.mac.identity=null \
--config.electronDist="$HOME/.electron-dist"
runHook postBuild
'';
installPhase =
''
runHook preInstall
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
mkdir -p $out/Applications
mv dist/mac*/*.app $out/Applications
makeWrapper "$out/Applications/OpenCode Dev.app/Contents/MacOS/OpenCode Dev" $out/bin/opencode-electron
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
mkdir -p $out/opt/opencode-electron
cp -r dist/linux*-unpacked/{resources,LICENSE*} $out/opt/opencode-electron
makeWrapper ${lib.getExe electron} $out/bin/opencode-electron \
--inherit-argv0 \
--set ELECTRON_FORCE_IS_PACKAGED 1 \
--add-flags $out/opt/opencode-electron/resources/app.asar \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
''
+ ''
runHook postInstall
'';
meta = {
description = "OpenCode Electron Desktop App";
mainProgram = "opencode-electron";
inherit (opencode.meta) homepage license platforms;
};
})

View File

@ -92,9 +92,7 @@ rustPlatform.buildRustPackage (finalAttrs: {
meta = {
description = "OpenCode Desktop App";
homepage = "https://opencode.ai";
license = lib.licenses.mit;
mainProgram = "opencode-desktop";
inherit (opencode.meta) platforms;
inherit (opencode.meta) homepage license platforms;
};
})

View File

@ -55,6 +55,7 @@ stdenvNoCC.mkDerivation {
--filter './packages/opencode' \
--filter './packages/desktop' \
--filter './packages/app' \
--filter './packages/desktop-electron' \
--frozen-lockfile \
--ignore-scripts \
--no-progress

View File

@ -40,7 +40,6 @@ stdenvNoCC.mkDerivation (finalAttrs: {
env.MODELS_DEV_API_JSON = "${models-dev}/dist/_api.json";
env.OPENCODE_DISABLE_MODELS_FETCH = true;
env.OPENCODE_VERSION = finalAttrs.version;
env.OPENCODE_CHANNEL = "local";
buildPhase = ''
runHook preBuild