Unverified Commit 731f1c7f authored by Liam Murphy's avatar Liam Murphy
Browse files

zed-editor: make $out/bin/zed the CLI, not the main binary

The CLI allows opening new files/folders while the app is still running, as well
as starting the app in the background without taking up your terminal.

This matches the official bundle-linux script: https://github.com/zed-industries/zed/blob/main/script/bundle-linux

Before:

```sh
$ zed flake.nix
zed is already running
```

After:

```sh
$ zed flake.nix
$ # works!
```

I'm not sure what the current status of this package's Darwin support is; the
new code I added should probably be Linux-only, but so should the .desktop file
generation which is currently run unconditionally, so I left it as running
unconditionally for now.
parent 7e4cda72
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -113,6 +113,10 @@ rustPlatform.buildRustPackage rec {
      ]
    );

  cargoBuildFlags = [
    "--package=zed"
    "--package=cli"
  ];
  buildFeatures = [ "gpui/runtime_shaders" ];

  env = {
@@ -129,8 +133,8 @@ rustPlatform.buildRustPackage rec {
  gpu-lib = if withGLES then libglvnd else vulkan-loader;

  postFixup = lib.optionalString stdenv.isLinux ''
    patchelf --add-rpath ${gpu-lib}/lib $out/bin/*
    patchelf --add-rpath ${wayland}/lib $out/bin/*
    patchelf --add-rpath ${gpu-lib}/lib $out/libexec/*
    patchelf --add-rpath ${wayland}/lib $out/libexec/*
  '';

  checkFlags = lib.optionals stdenv.hostPlatform.isLinux [
@@ -138,7 +142,13 @@ rustPlatform.buildRustPackage rec {
    "--skip=test_open_paths_action"
  ];

  postInstall = ''
  installPhase = ''
    runHook preInstall

    mkdir -p $out/bin $out/libexec
    cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed $out/libexec/zed-editor
    cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $out/bin/zed

    install -D ${src}/crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
    install -D ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png

@@ -151,6 +161,8 @@ rustPlatform.buildRustPackage rec {
      mkdir -p "$out/share/applications"
      ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/zed.desktop"
    )

    runHook postInstall
  '';

  passthru.updateScript = nix-update-script {