Skip to content

Commit 7027221

Browse files
authored
zed-editor: add remote_server (NixOS#370017)
2 parents 4fb742d + b4c31cf commit 7027221

File tree

1 file changed

+73
-63
lines changed

1 file changed

+73
-63
lines changed

pkgs/by-name/ze/zed-editor/package.nix

Lines changed: 73 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939
libX11,
4040
libXext,
4141
livekit-libwebrtc,
42+
testers,
4243

4344
withGLES ? false,
45+
buildRemoteServer ? true,
4446
}:
4547

4648
assert withGLES -> stdenv.hostPlatform.isLinux;
@@ -95,6 +97,8 @@ rustPlatform.buildRustPackage rec {
9597
pname = "zed-editor";
9698
version = "0.169.2";
9799

100+
outputs = [ "out" ] ++ lib.optional buildRemoteServer "remote_server";
101+
98102
src = fetchFromGitHub {
99103
owner = "zed-industries";
100104
repo = "zed";
@@ -168,7 +172,7 @@ rustPlatform.buildRustPackage rec {
168172
cargoBuildFlags = [
169173
"--package=zed"
170174
"--package=cli"
171-
];
175+
] ++ lib.optional buildRemoteServer "--package=remote_server";
172176

173177
# Required on darwin because we don't have access to the
174178
# proprietary Metal shader compiler.
@@ -218,68 +222,68 @@ rustPlatform.buildRustPackage rec {
218222
];
219223

220224
installPhase =
221-
if stdenv.hostPlatform.isDarwin then
222-
''
223-
runHook preInstall
224-
225-
# cargo-bundle expects the binary in target/release
226-
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed target/release/zed
227-
228-
pushd crates/zed
229-
230-
# Note that this is GNU sed, while Zed's bundle-mac uses BSD sed
231-
sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml
232-
export CARGO_BUNDLE_SKIP_BUILD=true
233-
app_path=$(cargo bundle --release | xargs)
234-
235-
# We're not using Zed's fork of cargo-bundle, so we must manually append their plist extensions
236-
# Remove closing tags from Info.plist (last two lines)
237-
head -n -2 $app_path/Contents/Info.plist > Info.plist
238-
# Append extensions
239-
cat resources/info/*.plist >> Info.plist
240-
# Add closing tags
241-
printf "</dict>\n</plist>\n" >> Info.plist
242-
mv Info.plist $app_path/Contents/Info.plist
243-
244-
popd
245-
246-
mkdir -p $out/Applications $out/bin
247-
# Zed expects git next to its own binary
248-
ln -s ${git}/bin/git $app_path/Contents/MacOS/git
249-
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $app_path/Contents/MacOS/cli
250-
mv $app_path $out/Applications/
251-
252-
# Physical location of the CLI must be inside the app bundle as this is used
253-
# to determine which app to start
254-
ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zeditor
255-
256-
runHook postInstall
257-
''
258-
else
259-
''
260-
runHook preInstall
261-
262-
mkdir -p $out/bin $out/libexec
263-
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed $out/libexec/zed-editor
264-
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $out/bin/zeditor
265-
266-
install -D ${src}/crates/zed/resources/[email protected] $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
267-
install -D ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png
268-
269-
# extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst)
270-
# and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name)
271-
(
272-
export DO_STARTUP_NOTIFY="true"
273-
export APP_CLI="zeditor"
274-
export APP_ICON="zed"
275-
export APP_NAME="Zed"
276-
export APP_ARGS="%U"
277-
mkdir -p "$out/share/applications"
278-
${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
279-
)
280-
281-
runHook postInstall
282-
'';
225+
''
226+
runHook preInstall
227+
228+
release_target="target/${stdenv.hostPlatform.rust.cargoShortTarget}/release"
229+
''
230+
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
231+
# cargo-bundle expects the binary in target/release
232+
mv $release_target/zed target/release/zed
233+
234+
pushd crates/zed
235+
236+
# Note that this is GNU sed, while Zed's bundle-mac uses BSD sed
237+
sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml
238+
export CARGO_BUNDLE_SKIP_BUILD=true
239+
app_path=$(cargo bundle --release | xargs)
240+
241+
# We're not using Zed's fork of cargo-bundle, so we must manually append their plist extensions
242+
# Remove closing tags from Info.plist (last two lines)
243+
head -n -2 $app_path/Contents/Info.plist > Info.plist
244+
# Append extensions
245+
cat resources/info/*.plist >> Info.plist
246+
# Add closing tags
247+
printf "</dict>\n</plist>\n" >> Info.plist
248+
mv Info.plist $app_path/Contents/Info.plist
249+
250+
popd
251+
252+
mkdir -p $out/Applications $out/bin
253+
# Zed expects git next to its own binary
254+
ln -s ${lib.getExe git} $app_path/Contents/MacOS/git
255+
mv $release_target/cli $app_path/Contents/MacOS/cli
256+
mv $app_path $out/Applications/
257+
258+
# Physical location of the CLI must be inside the app bundle as this is used
259+
# to determine which app to start
260+
ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zeditor
261+
''
262+
+ lib.optionalString stdenv.hostPlatform.isLinux ''
263+
install -Dm755 $release_target/zed $out/libexec/zed-editor
264+
install -Dm755 $release_target/cli $out/bin/zeditor
265+
266+
install -Dm644 ${src}/crates/zed/resources/[email protected] $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
267+
install -Dm644 ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png
268+
269+
# extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst)
270+
# and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name)
271+
(
272+
export DO_STARTUP_NOTIFY="true"
273+
export APP_CLI="zeditor"
274+
export APP_ICON="zed"
275+
export APP_NAME="Zed"
276+
export APP_ARGS="%U"
277+
mkdir -p "$out/share/applications"
278+
${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
279+
)
280+
''
281+
+ lib.optionalString buildRemoteServer ''
282+
install -Dm755 $release_target/remote_server $remote_server/bin/zed-remote-server-stable-$version
283+
''
284+
+ ''
285+
runHook postInstall
286+
'';
283287

284288
nativeInstallCheckInputs = [
285289
versionCheckHook
@@ -305,6 +309,12 @@ rustPlatform.buildRustPackage rec {
305309
};
306310
fhs = fhs { };
307311
fhsWithPackages = f: fhs { additionalPkgs = f; };
312+
tests = {
313+
remoteServerVersion = testers.testVersion {
314+
package = zed-editor.remote_server;
315+
command = "zed-remote-server-stable-${version} version";
316+
};
317+
};
308318
};
309319

310320
meta = {

0 commit comments

Comments
 (0)