From d79ec5ed83f609987d43c35ad3ec9c755879f5d6 Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Sat, 19 Oct 2024 22:58:23 +0200 Subject: [PATCH 1/2] zed-editor: fix darwin --- .../0002-disable-livekit-darwin.patch | 55 ++++++ pkgs/by-name/ze/zed-editor/package.nix | 160 +++++++++++------- 2 files changed, 158 insertions(+), 57 deletions(-) create mode 100644 pkgs/by-name/ze/zed-editor/0002-disable-livekit-darwin.patch diff --git a/pkgs/by-name/ze/zed-editor/0002-disable-livekit-darwin.patch b/pkgs/by-name/ze/zed-editor/0002-disable-livekit-darwin.patch new file mode 100644 index 000000000000..2c82a2d49b68 --- /dev/null +++ b/pkgs/by-name/ze/zed-editor/0002-disable-livekit-darwin.patch @@ -0,0 +1,55 @@ +diff --git a/crates/live_kit_client/Cargo.toml b/crates/live_kit_client/Cargo.toml +index e23c63453e..d0142b83d8 100644 +--- a/crates/live_kit_client/Cargo.toml ++++ b/crates/live_kit_client/Cargo.toml +@@ -40,10 +40,10 @@ nanoid = { workspace = true, optional = true} + parking_lot.workspace = true + postage.workspace = true + +-[target.'cfg(target_os = "macos")'.dependencies] ++[target.'cfg(target_os = "none")'.dependencies] + core-foundation.workspace = true + +-[target.'cfg(all(not(target_os = "macos")))'.dependencies] ++[target.'cfg(all(not(target_os = "none")))'.dependencies] + async-trait = { workspace = true } + collections = { workspace = true } + gpui = { workspace = true } +diff --git a/crates/live_kit_client/build.rs b/crates/live_kit_client/build.rs +index 2fdfd982bf..7272614b87 100644 +--- a/crates/live_kit_client/build.rs ++++ b/crates/live_kit_client/build.rs +@@ -36,7 +36,7 @@ const MACOS_TARGET_VERSION: &str = "10.15.7"; + + fn main() { + if cfg!(all( +- target_os = "macos", ++ target_os = "none", + not(any(test, feature = "test-support", feature = "no-webrtc")), + )) { + let swift_target = get_swift_target(); +diff --git a/crates/live_kit_client/src/live_kit_client.rs b/crates/live_kit_client/src/live_kit_client.rs +index 4820a4eedb..6179e6c55a 100644 +--- a/crates/live_kit_client/src/live_kit_client.rs ++++ b/crates/live_kit_client/src/live_kit_client.rs +@@ -2,16 +2,16 @@ + + use std::sync::Arc; + +-#[cfg(all(target_os = "macos", not(any(test, feature = "test-support"))))] ++#[cfg(all(target_os = "none", not(any(test, feature = "test-support"))))] + pub mod prod; + +-#[cfg(all(target_os = "macos", not(any(test, feature = "test-support"))))] ++#[cfg(all(target_os = "none", not(any(test, feature = "test-support"))))] + pub use prod::*; + +-#[cfg(any(test, feature = "test-support", not(target_os = "macos")))] ++#[cfg(any(test, feature = "test-support", not(target_os = "none")))] + pub mod test; + +-#[cfg(any(test, feature = "test-support", not(target_os = "macos")))] ++#[cfg(any(test, feature = "test-support", not(target_os = "none")))] + pub use test::*; + + pub type Sid = String; diff --git a/pkgs/by-name/ze/zed-editor/package.nix b/pkgs/by-name/ze/zed-editor/package.nix index d0845a4a702b..c2924f30187d 100644 --- a/pkgs/by-name/ze/zed-editor/package.nix +++ b/pkgs/by-name/ze/zed-editor/package.nix @@ -9,7 +9,6 @@ perl, pkg-config, protobuf, - xcbuild, fontconfig, freetype, libgit2, @@ -23,7 +22,6 @@ libglvnd, xorg, stdenv, - darwin, makeFontsConf, vulkan-loader, envsubst, @@ -32,6 +30,10 @@ versionCheckHook, zed-editor, buildFHSEnv, + cargo-bundle, + git, + apple-sdk_15, + darwinMinVersionHook, withGLES ? false, }: @@ -93,14 +95,23 @@ rustPlatform.buildRustPackage rec { repo = "zed"; rev = "refs/tags/v${version}"; hash = "sha256-xtSdlzj1AxhJN4aXLJ+Oy51LX4QduLwcuCfK42kthvE="; - fetchSubmodules = true; }; - patches = [ - # Zed uses cargo-install to install cargo-about during the script execution. - # We provide cargo-about ourselves and can skip this step. - ./0001-generate-licenses.patch - ]; + patches = + [ + # Zed uses cargo-install to install cargo-about during the script execution. + # We provide cargo-about ourselves and can skip this step. + ./0001-generate-licenses.patch + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # The Swift variant of livekit currently used inside Zed requires + # Swift 6, which is not available in nixpkgs yet: + # https://github.com/NixOS/nixpkgs/issues/343210 + # The Rust variant of livekit for Zed is still pending and there is no + # schedule when it will be finished: + # https://github.com/zed-industries/zed/pull/13343 + ./0002-disable-livekit-darwin.patch + ]; cargoLock = { lockFile = ./Cargo.lock; @@ -132,7 +143,7 @@ rustPlatform.buildRustPackage rec { protobuf rustPlatform.bindgenHook cargo-about - ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild.xcrun ]; + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ]; dontUseCmakeConfigure = true; @@ -153,30 +164,23 @@ rustPlatform.buildRustPackage rec { wayland xorg.libxcb ] - ++ lib.optionals stdenv.hostPlatform.isDarwin ( - with darwin.apple_sdk.frameworks; - [ - AppKit - CoreAudio - CoreFoundation - CoreGraphics - CoreMedia - CoreServices - CoreText - Foundation - IOKit - Metal - Security - SystemConfiguration - VideoToolbox - ] - ); + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + apple-sdk_15 + # This will need to be increased to 12.3 once + # https://github.com/zed-industries/zed/pull/13343 + # is merged and released, as ScreenCaptureKit is only available on 12.3 and up: + # https://developer.apple.com/documentation/screencapturekit + (darwinMinVersionHook "10.15") + ]; cargoBuildFlags = [ "--package=zed" "--package=cli" ]; - buildFeatures = [ "gpui/runtime_shaders" ]; + + # Required on darwin because we don't have access to the + # proprietary Metal shader compiler. + buildFeatures = lib.optionals stdenv.hostPlatform.isDarwin [ "gpui/runtime_shaders" ]; env = { ZSTD_SYS_USE_PKG_CONFIG = true; @@ -191,6 +195,9 @@ rustPlatform.buildRustPackage rec { ZED_UPDATE_EXPLANATION = "zed has been installed using nix. Auto-updates have thus been disabled."; # Used by `zed --version` RELEASE_VERSION = version; + # Required until `-isysroot` can be used with libclang in nixpkgs on darwin, otherwise + # rust bindgen will not work as expected + NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-F${apple-sdk_15.sdkroot}/System/Library/Frameworks"; }; RUSTFLAGS = if withGLES then "--cfg gles" else ""; @@ -209,38 +216,79 @@ rustPlatform.buildRustPackage rec { export HOME=$(mktemp -d); ''; - checkFlags = lib.optionals stdenv.hostPlatform.isLinux [ - # Fails on certain hosts (including Hydra) for unclear reason - "--skip=test_open_paths_action" + checkFlags = + [ + # Flaky: unreliably fails on certain hosts (including Hydra) + "--skip=zed::tests::test_window_edit_state_restoring_enabled" + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + # Fails on certain hosts (including Hydra) for unclear reason + "--skip=test_open_paths_action" + ]; - # Flaky: unreliably fails on certain hosts (including Hydra) - "--skip=zed::tests::test_window_edit_state_restoring_enabled" - ]; + installPhase = + if stdenv.hostPlatform.isDarwin then + '' + runHook preInstall - installPhase = '' - runHook preInstall + # cargo-bundle expects the binary in target/release + mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed target/release/zed - 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/zeditor + pushd crates/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 + # Note that this is GNU sed, while Zed's bundle-mac uses BSD sed + sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml + export CARGO_BUNDLE_SKIP_BUILD=true + app_path=$(cargo bundle --release | xargs) - # extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst) - # and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name) - ( - export DO_STARTUP_NOTIFY="true" - export APP_CLI="zeditor" - export APP_ICON="zed" - export APP_NAME="Zed" - export APP_ARGS="%U" - mkdir -p "$out/share/applications" - ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop" - ) + # We're not using Zed's fork of cargo-bundle, so we must manually append their plist extensions + # Remove closing tags from Info.plist (last two lines) + head -n -2 $app_path/Contents/Info.plist > Info.plist + # Append extensions + cat resources/info/*.plist >> Info.plist + # Add closing tags + printf "\n\n" >> Info.plist + mv Info.plist $app_path/Contents/Info.plist - runHook postInstall - ''; + popd + + mkdir -p $out/Applications $out/bin + # Zed expects git next to its own binary + ln -s ${git}/bin/git $app_path/Contents/MacOS/git + mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $app_path/Contents/MacOS/cli + mv $app_path $out/Applications/ + + # Physical location of the CLI must be inside the app bundle as this is used + # to determine which app to start + ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zeditor + + runHook postInstall + '' + else + '' + 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/zeditor + + 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 + + # extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst) + # and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name) + ( + export DO_STARTUP_NOTIFY="true" + export APP_CLI="zeditor" + export APP_ICON="zed" + export APP_NAME="Zed" + export APP_ARGS="%U" + mkdir -p "$out/share/applications" + ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop" + ) + + runHook postInstall + ''; nativeInstallCheckInputs = [ versionCheckHook @@ -268,8 +316,6 @@ rustPlatform.buildRustPackage rec { niklaskorz ]; mainProgram = "zeditor"; - platforms = lib.platforms.all; - # Currently broken on darwin: https://github.com/NixOS/nixpkgs/pull/303233#issuecomment-2048650618 - broken = stdenv.hostPlatform.isDarwin; + platforms = lib.platforms.linux ++ lib.platforms.darwin; }; } From 1d4e138222bb75317b4c77bbf89b191e44e10547 Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Sun, 20 Oct 2024 22:14:23 +0200 Subject: [PATCH 2/2] zed-editor: change auto-update message --- pkgs/by-name/ze/zed-editor/package.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/by-name/ze/zed-editor/package.nix b/pkgs/by-name/ze/zed-editor/package.nix index c2924f30187d..9863977f104c 100644 --- a/pkgs/by-name/ze/zed-editor/package.nix +++ b/pkgs/by-name/ze/zed-editor/package.nix @@ -192,7 +192,7 @@ rustPlatform.buildRustPackage rec { }; # Setting this environment variable allows to disable auto-updates # https://zed.dev/docs/development/linux#notes-for-packaging-zed - ZED_UPDATE_EXPLANATION = "zed has been installed using nix. Auto-updates have thus been disabled."; + ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled."; # Used by `zed --version` RELEASE_VERSION = version; # Required until `-isysroot` can be used with libclang in nixpkgs on darwin, otherwise