|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + bun, |
| 5 | + nodejs, |
| 6 | + electron_40, |
| 7 | + makeWrapper, |
| 8 | + writableTmpDirAsHomeHook, |
| 9 | + opencode, |
| 10 | +}: |
| 11 | +let |
| 12 | + electron = electron_40; |
| 13 | +in |
| 14 | +stdenv.mkDerivation (finalAttrs: { |
| 15 | + pname = "opencode-electron"; |
| 16 | + inherit (opencode) version src node_modules; |
| 17 | + |
| 18 | + nativeBuildInputs = [ |
| 19 | + bun |
| 20 | + nodejs |
| 21 | + makeWrapper |
| 22 | + writableTmpDirAsHomeHook |
| 23 | + ]; |
| 24 | + |
| 25 | + env = opencode.env // { |
| 26 | + ELECTRON_SKIP_BINARY_DOWNLOAD = "1"; |
| 27 | + }; |
| 28 | + |
| 29 | + # https://github.com/electron/electron/issues/31121 |
| 30 | + # mac builds use a .app bundle which doesnt have this issue |
| 31 | + postPatch = lib.optionalString stdenv.isLinux '' |
| 32 | + BASE_PATH=packages/desktop-electron |
| 33 | + FILES=(src/main/windows.ts) |
| 34 | + for file in "''${FILES[@]}"; do |
| 35 | + substituteInPlace $BASE_PATH/$file \ |
| 36 | + --replace-fail "process.resourcesPath" "'$out/opt/opencode-electron/resources'" |
| 37 | + done |
| 38 | + ''; |
| 39 | + |
| 40 | + preBuild = '' |
| 41 | + cp -r "${electron.dist}" $HOME/.electron-dist |
| 42 | + chmod -R u+w $HOME/.electron-dist |
| 43 | +
|
| 44 | + cp -R ${finalAttrs.node_modules}/. . |
| 45 | + patchShebangs node_modules |
| 46 | + patchShebangs packages/*/node_modules |
| 47 | + ''; |
| 48 | + |
| 49 | + buildPhase = '' |
| 50 | + runHook preBuild |
| 51 | +
|
| 52 | + cd packages/desktop-electron |
| 53 | +
|
| 54 | + bun run build |
| 55 | + npx electron-builder --dir \ |
| 56 | + --config electron-builder.config.ts \ |
| 57 | + --config.mac.identity=null \ |
| 58 | + --config.electronDist="$HOME/.electron-dist" |
| 59 | +
|
| 60 | + runHook postBuild |
| 61 | + ''; |
| 62 | + |
| 63 | + installPhase = |
| 64 | + '' |
| 65 | + runHook preInstall |
| 66 | + '' |
| 67 | + + lib.optionalString stdenv.hostPlatform.isDarwin '' |
| 68 | + mkdir -p $out/Applications |
| 69 | + mv dist/mac*/*.app $out/Applications |
| 70 | + makeWrapper "$out/Applications/OpenCode.app/Contents/MacOS/OpenCode" $out/bin/opencode-electron |
| 71 | + '' |
| 72 | + + lib.optionalString stdenv.hostPlatform.isLinux '' |
| 73 | + mkdir -p $out/opt/opencode-electron |
| 74 | + cp -r dist/linux*-unpacked/{resources,LICENSE*} $out/opt/opencode-electron |
| 75 | + makeWrapper ${lib.getExe electron} $out/bin/opencode-electron \ |
| 76 | + --inherit-argv0 \ |
| 77 | + --set ELECTRON_FORCE_IS_PACKAGED 1 \ |
| 78 | + --add-flags $out/opt/opencode-electron/resources/app.asar \ |
| 79 | + --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" |
| 80 | + '' |
| 81 | + + '' |
| 82 | + runHook postInstall |
| 83 | + ''; |
| 84 | + |
| 85 | + meta = { |
| 86 | + description = "OpenCode Electron Desktop App"; |
| 87 | + mainProgram = "opencode-electron"; |
| 88 | + inherit (opencode.meta) homepage license platforms; |
| 89 | + }; |
| 90 | +}) |
0 commit comments