-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(nix): preliminary desktop app flake integration #6135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jerome-benoit
wants to merge
6
commits into
sst:dev
Choose a base branch
from
jerome-benoit:feat/nix-desktop
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+214
−13
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10f8563
feat(nix): add desktop app integration
jerome-benoit 611320a
refactor(nix): rename mkPackage to mkOpencode
jerome-benoit 971c3fd
fix(nix): address desktop flake review
jerome-benoit 08ecd97
ci: catch nix desktop build regressions on macOS/Linux
jerome-benoit d40562a
fix(nix): drop legacy darwin apple_sdk frameworks
jerome-benoit e386012
Merge branch 'dev' into feat/nix-desktop
jerome-benoit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: nix desktop | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [dev] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-desktop: | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: | ||
| - blacksmith-4vcpu-ubuntu-2404 | ||
| - macos-latest | ||
| runs-on: ${{ matrix.os }} | ||
| timeout-minutes: 60 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup Nix | ||
| uses: DeterminateSystems/nix-installer-action@v21 | ||
|
|
||
| - name: Build desktop via flake | ||
| run: | | ||
| set -euo pipefail | ||
| nix --version | ||
| nix build .#desktop -L |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| { | ||
| lib, | ||
| stdenv, | ||
| rustPlatform, | ||
| bun, | ||
| pkg-config, | ||
| dbus ? null, | ||
| openssl, | ||
| glib ? null, | ||
| gtk3 ? null, | ||
| libsoup_3 ? null, | ||
| webkitgtk_4_1 ? null, | ||
| librsvg ? null, | ||
| libappindicator-gtk3 ? null, | ||
| cargo, | ||
| rustc, | ||
| makeBinaryWrapper, | ||
| nodejs, | ||
| jq, | ||
| }: | ||
| args: | ||
| let | ||
| scripts = args.scripts; | ||
| mkModules = | ||
| attrs: | ||
| args.mkNodeModules ( | ||
| attrs | ||
| // { | ||
| canonicalizeScript = scripts + "/canonicalize-node-modules.ts"; | ||
| normalizeBinsScript = scripts + "/normalize-bun-binaries.ts"; | ||
| } | ||
| ); | ||
| in | ||
| rustPlatform.buildRustPackage rec { | ||
| pname = "opencode-desktop"; | ||
| version = args.version; | ||
|
|
||
| src = args.src; | ||
|
|
||
| # We need to set the root for cargo, but we also need access to the whole repo. | ||
| postUnpack = '' | ||
| # Update sourceRoot to point to the tauri app | ||
| sourceRoot+=/packages/desktop/src-tauri | ||
| ''; | ||
|
|
||
| cargoLock = { | ||
| lockFile = ../packages/desktop/src-tauri/Cargo.lock; | ||
| allowBuiltinFetchGit = true; | ||
| }; | ||
|
|
||
| node_modules = mkModules { | ||
| version = version; | ||
| src = src; | ||
| }; | ||
|
|
||
| nativeBuildInputs = [ | ||
| pkg-config | ||
| bun | ||
| makeBinaryWrapper | ||
| cargo | ||
| rustc | ||
| nodejs | ||
| jq | ||
| ]; | ||
|
|
||
| buildInputs = [ | ||
| openssl | ||
| ] | ||
| ++ lib.optionals stdenv.isLinux [ | ||
| dbus | ||
| glib | ||
| gtk3 | ||
| libsoup_3 | ||
| webkitgtk_4_1 | ||
| librsvg | ||
| libappindicator-gtk3 | ||
| ]; | ||
|
|
||
| preBuild = '' | ||
| # Restore node_modules | ||
| pushd ../../.. | ||
|
|
||
| # Copy node_modules from the fixed-output derivation | ||
| # We use cp -r --no-preserve=mode to ensure we can write to them if needed, | ||
| # though we usually just read. | ||
| cp -r ${node_modules}/node_modules . | ||
| cp -r ${node_modules}/packages . | ||
|
|
||
| # Ensure node_modules is writable so patchShebangs can update script headers | ||
| chmod -R u+w node_modules | ||
| # Ensure workspace packages are writable for tsgo incremental outputs (.tsbuildinfo) | ||
| chmod -R u+w packages | ||
| # Patch shebangs so scripts can run | ||
| patchShebangs node_modules | ||
|
|
||
| # Copy sidecar | ||
| mkdir -p packages/desktop/src-tauri/sidecars | ||
| targetTriple=${stdenv.hostPlatform.rust.rustcTarget} | ||
| cp ${args.opencode}/bin/opencode packages/desktop/src-tauri/sidecars/opencode-cli-$targetTriple | ||
|
|
||
| # Merge prod config into tauri.conf.json | ||
| if ! jq -s '.[0] * .[1]' \ | ||
| packages/desktop/src-tauri/tauri.conf.json \ | ||
| packages/desktop/src-tauri/tauri.prod.conf.json \ | ||
| > packages/desktop/src-tauri/tauri.conf.json.tmp; then | ||
| echo "Error: failed to merge tauri.conf.json with tauri.prod.conf.json" >&2 | ||
| exit 1 | ||
| fi | ||
| mv packages/desktop/src-tauri/tauri.conf.json.tmp packages/desktop/src-tauri/tauri.conf.json | ||
|
|
||
| # Build the frontend | ||
| cd packages/desktop | ||
|
|
||
| # The 'build' script runs 'bun run typecheck && vite build'. | ||
| bun run build | ||
|
|
||
| popd | ||
| ''; | ||
|
|
||
| # Tauri bundles the assets during the rust build phase (which happens after preBuild). | ||
| # It looks for them in the location specified in tauri.conf.json. | ||
|
|
||
| postInstall = lib.optionalString stdenv.isLinux '' | ||
| # Wrap the binary to ensure it finds the libraries | ||
| wrapProgram $out/bin/opencode-desktop \ | ||
| --prefix LD_LIBRARY_PATH : ${ | ||
| lib.makeLibraryPath [ | ||
| gtk3 | ||
| webkitgtk_4_1 | ||
| librsvg | ||
| glib | ||
| libsoup_3 | ||
| ] | ||
| } | ||
| ''; | ||
|
|
||
| meta = with lib; { | ||
| description = "OpenCode Desktop App"; | ||
| homepage = "https://opencode.ai"; | ||
| license = licenses.mit; | ||
| maintainers = with maintainers; [ ]; | ||
| mainProgram = "opencode-desktop"; | ||
| platforms = platforms.linux ++ platforms.darwin; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.