Skip to content

Commit b95fe7b

Browse files
jerome-benoitTest User
andauthored
fix(nix): restore desktop integration (anomalyco#37197)
Co-authored-by: Test User <test@test.com>
1 parent 9da9ed9 commit b95fe7b

1 file changed

Lines changed: 49 additions & 23 deletions

File tree

nix/desktop.nix

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
makeWrapper,
99
writableTmpDirAsHomeHook,
1010
autoPatchelfHook,
11+
copyDesktopItems,
12+
makeDesktopItem,
1113
opencode,
1214
}:
1315
let
@@ -27,9 +29,12 @@ stdenv.mkDerivation (finalAttrs: {
2729
nodejs
2830
makeWrapper
2931
writableTmpDirAsHomeHook
30-
] ++ lib.optionals stdenv.hostPlatform.isLinux [
32+
]
33+
++ lib.optionals stdenv.hostPlatform.isLinux [
3134
autoPatchelfHook
32-
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
35+
copyDesktopItems
36+
]
37+
++ lib.optionals stdenv.hostPlatform.isDarwin [
3338
# Ad-hoc sign the .app: --config.mac.identity=null below skips signing.
3439
darwin.autoSignDarwinBinariesHook
3540
];
@@ -38,6 +43,16 @@ stdenv.mkDerivation (finalAttrs: {
3843
(lib.getLib stdenv.cc.cc)
3944
];
4045

46+
desktopItems = lib.optional stdenv.hostPlatform.isLinux (makeDesktopItem {
47+
name = "ai.opencode.desktop";
48+
desktopName = "OpenCode";
49+
exec = "opencode-desktop %U";
50+
icon = "ai.opencode.desktop";
51+
# Electron 41 derives X11 WM_CLASS from app.name.
52+
startupWMClass = "OpenCode";
53+
categories = [ "Development" ];
54+
});
55+
4156
env = opencode.env // {
4257
ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
4358
};
@@ -83,27 +98,38 @@ stdenv.mkDerivation (finalAttrs: {
8398
runHook postBuild
8499
'';
85100

86-
installPhase =
87-
''
88-
runHook preInstall
89-
''
90-
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
91-
mkdir -p $out/Applications
92-
mv dist/mac*/*.app $out/Applications
93-
makeWrapper "$out/Applications/OpenCode.app/Contents/MacOS/OpenCode" $out/bin/opencode-desktop
94-
''
95-
+ lib.optionalString stdenv.hostPlatform.isLinux ''
96-
mkdir -p $out/opt/opencode-desktop
97-
cp -r dist/linux*-unpacked/{resources,LICENSE*} $out/opt/opencode-desktop
98-
makeWrapper ${lib.getExe electron} $out/bin/opencode-desktop \
99-
--inherit-argv0 \
100-
--set ELECTRON_FORCE_IS_PACKAGED 1 \
101-
--add-flags $out/opt/opencode-desktop/resources/app.asar \
102-
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
103-
''
104-
+ ''
105-
runHook postInstall
106-
'';
101+
installPhase = ''
102+
runHook preInstall
103+
''
104+
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
105+
mkdir -p $out/Applications
106+
mv dist/mac*/*.app $out/Applications
107+
makeWrapper "$out/Applications/OpenCode.app/Contents/MacOS/OpenCode" $out/bin/opencode-desktop
108+
''
109+
+ lib.optionalString stdenv.hostPlatform.isLinux ''
110+
mkdir -p $out/opt/opencode-desktop
111+
cp -r dist/linux*-unpacked/{resources,LICENSE*} $out/opt/opencode-desktop
112+
install -Dm644 resources/icons/32x32.png \
113+
"$out/share/icons/hicolor/32x32/apps/ai.opencode.desktop.png"
114+
install -Dm644 resources/icons/64x64.png \
115+
"$out/share/icons/hicolor/64x64/apps/ai.opencode.desktop.png"
116+
install -Dm644 resources/icons/128x128.png \
117+
"$out/share/icons/hicolor/128x128/apps/ai.opencode.desktop.png"
118+
install -Dm644 resources/icons/128x128@2x.png \
119+
"$out/share/icons/hicolor/256x256/apps/ai.opencode.desktop.png"
120+
install -Dm644 resources/icons/icon.png \
121+
"$out/share/icons/hicolor/512x512/apps/ai.opencode.desktop.png"
122+
install -Dm644 resources/ai.opencode.desktop.metainfo.xml \
123+
"$out/share/metainfo/ai.opencode.desktop.metainfo.xml"
124+
makeWrapper ${lib.getExe electron} $out/bin/opencode-desktop \
125+
--inherit-argv0 \
126+
--set ELECTRON_FORCE_IS_PACKAGED 1 \
127+
--add-flags $out/opt/opencode-desktop/resources/app.asar \
128+
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
129+
''
130+
+ ''
131+
runHook postInstall
132+
'';
107133

108134
autoPatchelfIgnoreMissingDeps = [
109135
"libc.musl-x86_64.so.1"

0 commit comments

Comments
 (0)