GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(nix): preliminary desktop app flake integration (#6135) · robertfall/opencode@e00621c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • nix-desktop.yml
  • flake.nix
  • nix
    • desktop.nix
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/nix-desktop.yml‎

Copy file name to clipboard
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: nix desktop
2+
3+
on:
4+
pull_request:
5+
branches: [dev]
6+
workflow_dispatch:
7+
8+
jobs:
9+
build-desktop:
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
os:
14+
- blacksmith-4vcpu-ubuntu-2404
15+
- macos-latest
16+
runs-on: ${{ matrix.os }}
17+
timeout-minutes: 60
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v6
21+
22+
- name: Setup Nix
23+
uses: DeterminateSystems/nix-installer-action@v21
24+
25+
- name: Build desktop via flake
26+
run: |
27+
set -euo pipefail
28+
nix --version
29+
nix build .#desktop -L
Collapse file

‎flake.nix‎

Copy file name to clipboardExpand all lines: flake.nix
+16-4Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,29 @@
6666
mkNodeModules = pkgs.callPackage ./nix/node-modules.nix {
6767
hash = nodeModulesHash;
6868
};
69-
mkPackage = pkgs.callPackage ./nix/opencode.nix { };
70-
in
71-
{
72-
default = mkPackage {
69+
mkOpencode = pkgs.callPackage ./nix/opencode.nix { };
70+
mkDesktop = pkgs.callPackage ./nix/desktop.nix { };
71+
72+
opencodePkg = mkOpencode {
7373
inherit (packageJson) version;
7474
src = ./.;
7575
scripts = ./nix/scripts;
7676
target = bunTarget.${system};
7777
modelsDev = "${modelsDev.${system}}/dist/_api.json";
7878
inherit mkNodeModules;
7979
};
80+
81+
desktopPkg = mkDesktop {
82+
inherit (packageJson) version;
83+
src = ./.;
84+
scripts = ./nix/scripts;
85+
mkNodeModules = mkNodeModules;
86+
opencode = opencodePkg;
87+
};
88+
in
89+
{
90+
default = opencodePkg;
91+
desktop = desktopPkg;
8092
}
8193
);
8294

Collapse file

‎nix/desktop.nix‎

Copy file name to clipboard
+145Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
{
2+
lib,
3+
stdenv,
4+
rustPlatform,
5+
bun,
6+
pkg-config,
7+
dbus ? null,
8+
openssl,
9+
glib ? null,
10+
gtk3 ? null,
11+
libsoup_3 ? null,
12+
webkitgtk_4_1 ? null,
13+
librsvg ? null,
14+
libappindicator-gtk3 ? null,
15+
cargo,
16+
rustc,
17+
makeBinaryWrapper,
18+
nodejs,
19+
jq,
20+
}:
21+
args:
22+
let
23+
scripts = args.scripts;
24+
mkModules =
25+
attrs:
26+
args.mkNodeModules (
27+
attrs
28+
// {
29+
canonicalizeScript = scripts + "/canonicalize-node-modules.ts";
30+
normalizeBinsScript = scripts + "/normalize-bun-binaries.ts";
31+
}
32+
);
33+
in
34+
rustPlatform.buildRustPackage rec {
35+
pname = "opencode-desktop";
36+
version = args.version;
37+
38+
src = args.src;
39+
40+
# We need to set the root for cargo, but we also need access to the whole repo.
41+
postUnpack = ''
42+
# Update sourceRoot to point to the tauri app
43+
sourceRoot+=/packages/desktop/src-tauri
44+
'';
45+
46+
cargoLock = {
47+
lockFile = ../packages/desktop/src-tauri/Cargo.lock;
48+
allowBuiltinFetchGit = true;
49+
};
50+
51+
node_modules = mkModules {
52+
version = version;
53+
src = src;
54+
};
55+
56+
nativeBuildInputs = [
57+
pkg-config
58+
bun
59+
makeBinaryWrapper
60+
cargo
61+
rustc
62+
nodejs
63+
jq
64+
];
65+
66+
buildInputs = [
67+
openssl
68+
]
69+
++ lib.optionals stdenv.isLinux [
70+
dbus
71+
glib
72+
gtk3
73+
libsoup_3
74+
webkitgtk_4_1
75+
librsvg
76+
libappindicator-gtk3
77+
];
78+
79+
preBuild = ''
80+
# Restore node_modules
81+
pushd ../../..
82+
83+
# Copy node_modules from the fixed-output derivation
84+
# We use cp -r --no-preserve=mode to ensure we can write to them if needed,
85+
# though we usually just read.
86+
cp -r ${node_modules}/node_modules .
87+
cp -r ${node_modules}/packages .
88+
89+
# Ensure node_modules is writable so patchShebangs can update script headers
90+
chmod -R u+w node_modules
91+
# Ensure workspace packages are writable for tsgo incremental outputs (.tsbuildinfo)
92+
chmod -R u+w packages
93+
# Patch shebangs so scripts can run
94+
patchShebangs node_modules
95+
96+
# Copy sidecar
97+
mkdir -p packages/desktop/src-tauri/sidecars
98+
targetTriple=${stdenv.hostPlatform.rust.rustcTarget}
99+
cp ${args.opencode}/bin/opencode packages/desktop/src-tauri/sidecars/opencode-cli-$targetTriple
100+
101+
# Merge prod config into tauri.conf.json
102+
if ! jq -s '.[0] * .[1]' \
103+
packages/desktop/src-tauri/tauri.conf.json \
104+
packages/desktop/src-tauri/tauri.prod.conf.json \
105+
> packages/desktop/src-tauri/tauri.conf.json.tmp; then
106+
echo "Error: failed to merge tauri.conf.json with tauri.prod.conf.json" >&2
107+
exit 1
108+
fi
109+
mv packages/desktop/src-tauri/tauri.conf.json.tmp packages/desktop/src-tauri/tauri.conf.json
110+
111+
# Build the frontend
112+
cd packages/desktop
113+
114+
# The 'build' script runs 'bun run typecheck && vite build'.
115+
bun run build
116+
117+
popd
118+
'';
119+
120+
# Tauri bundles the assets during the rust build phase (which happens after preBuild).
121+
# It looks for them in the location specified in tauri.conf.json.
122+
123+
postInstall = lib.optionalString stdenv.isLinux ''
124+
# Wrap the binary to ensure it finds the libraries
125+
wrapProgram $out/bin/opencode-desktop \
126+
--prefix LD_LIBRARY_PATH : ${
127+
lib.makeLibraryPath [
128+
gtk3
129+
webkitgtk_4_1
130+
librsvg
131+
glib
132+
libsoup_3
133+
]
134+
}
135+
'';
136+
137+
meta = with lib; {
138+
description = "OpenCode Desktop App";
139+
homepage = "https://opencode.ai";
140+
license = licenses.mit;
141+
maintainers = with maintainers; [ ];
142+
mainProgram = "opencode-desktop";
143+
platforms = platforms.linux ++ platforms.darwin;
144+
};
145+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.