43 assert withGLES -> stdenv.hostPlatform.isLinux;
46 executableName = "zeditor";
48 # Zed allows for users to download and use extensions
49 # which often include the usage of pre-built binaries.
52 # buildFHSEnv allows for users to use the existing Zed
53 # extension tooling without significant pain.
56 additionalPkgs ? pkgs: [ ],
59 # also determines the name of the wrapped command
60 name = executableName;
62 # additional libraries which are commonly needed for extensions
66 # ld-linux-x86-64-linux.so.2 and others
69 ++ additionalPkgs pkgs;
71 # symlink shared assets, including icons and desktop entries
72 extraInstallCommands = ''
73 ln -s "${zed-editor}/share" "$out/"
76 runScript = "${zed-editor}/bin/${executableName}";
79 inherit executableName;
80 inherit (zed-editor) pname version;
83 meta = zed-editor.meta // {
85 Wrapped variant of ${zed-editor.pname} which launches in a FHS compatible environment.
86 Should allow for easy usage of extensions without nix-specific modifications.
91 rustPlatform.buildRustPackage rec {
95 src = fetchFromGitHub {
96 owner = "zed-industries";
98 rev = "refs/tags/v${version}";
99 hash = "sha256-AkfMAGkxo4ZQVqR+8T9IgBMXvSyFd15jU5hCoAWDk0A=";
104 # Zed uses cargo-install to install cargo-about during the script execution.
105 # We provide cargo-about ourselves and can skip this step.
106 # Until https://github.com/zed-industries/zed/issues/19971 is fixed,
107 # we also skip any crate for which the license cannot be determined.
108 ./0001-generate-licenses.patch
110 ++ lib.optionals stdenv.hostPlatform.isDarwin [
111 # The Swift variant of livekit currently used inside Zed requires
112 # Swift 6, which is not available in nixpkgs yet:
113 # https://github.com/NixOS/nixpkgs/issues/343210
114 # The Rust variant of livekit for Zed is still pending and there is no
115 # schedule when it will be finished:
116 # https://github.com/zed-industries/zed/pull/13343
117 ./0002-disable-livekit-darwin.patch
120 useFetchCargoVendor = true;
121 cargoHash = "sha256-Ol7GPWACb8jGhki3rlLxNw3486+LOR2fyh7qVXWkGJ0=";
132 rustPlatform.bindgenHook
135 ++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ]
136 ++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ];
138 dontUseCmakeConfigure = true;
151 ++ lib.optionals stdenv.hostPlatform.isLinux [
157 ++ lib.optionals stdenv.hostPlatform.isDarwin [
159 # This will need to be increased to 12.3 once
160 # https://github.com/zed-industries/zed/pull/13343
161 # is merged and released, as ScreenCaptureKit is only available on 12.3 and up:
162 # https://developer.apple.com/documentation/screencapturekit
163 (darwinMinVersionHook "10.15")
171 # Required on darwin because we don't have access to the
172 # proprietary Metal shader compiler.
173 buildFeatures = lib.optionals stdenv.hostPlatform.isDarwin [ "gpui/runtime_shaders" ];
176 ZSTD_SYS_USE_PKG_CONFIG = true;
177 FONTCONFIG_FILE = makeFontsConf {
179 "${src}/assets/fonts/plex-mono"
180 "${src}/assets/fonts/plex-sans"
183 # Setting this environment variable allows to disable auto-updates
184 # https://zed.dev/docs/development/linux#notes-for-packaging-zed
185 ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled.";
186 # Used by `zed --version`
187 RELEASE_VERSION = version;
190 RUSTFLAGS = if withGLES then "--cfg gles" else "";
191 gpu-lib = if withGLES then libglvnd else vulkan-loader;
194 bash script/generate-licenses
197 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
198 patchelf --add-rpath ${gpu-lib}/lib $out/libexec/*
199 patchelf --add-rpath ${wayland}/lib $out/libexec/*
200 wrapProgram $out/libexec/zed-editor --suffix PATH : ${lib.makeBinPath [ nodejs_22 ]}
204 export HOME=$(mktemp -d);
209 # Flaky: unreliably fails on certain hosts (including Hydra)
210 "--skip=zed::tests::test_window_edit_state_restoring_enabled"
212 ++ lib.optionals stdenv.hostPlatform.isLinux [
213 # Fails on certain hosts (including Hydra) for unclear reason
214 "--skip=test_open_paths_action"
218 if stdenv.hostPlatform.isDarwin then
222 # cargo-bundle expects the binary in target/release
223 mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed target/release/zed
227 # Note that this is GNU sed, while Zed's bundle-mac uses BSD sed
228 sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml
229 export CARGO_BUNDLE_SKIP_BUILD=true
230 app_path=$(cargo bundle --release | xargs)
232 # We're not using Zed's fork of cargo-bundle, so we must manually append their plist extensions
233 # Remove closing tags from Info.plist (last two lines)
234 head -n -2 $app_path/Contents/Info.plist > Info.plist
236 cat resources/info/*.plist >> Info.plist
238 printf "</dict>\n</plist>\n" >> Info.plist
239 mv Info.plist $app_path/Contents/Info.plist
243 mkdir -p $out/Applications $out/bin
244 # Zed expects git next to its own binary
245 ln -s ${git}/bin/git $app_path/Contents/MacOS/git
246 mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $app_path/Contents/MacOS/cli
247 mv $app_path $out/Applications/
249 # Physical location of the CLI must be inside the app bundle as this is used
250 # to determine which app to start
251 ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zeditor
259 mkdir -p $out/bin $out/libexec
260 cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed $out/libexec/zed-editor
261 cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $out/bin/zeditor
263 install -D ${src}/crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
264 install -D ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png
266 # extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst)
267 # and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name)
269 export DO_STARTUP_NOTIFY="true"
270 export APP_CLI="zeditor"
271 export APP_ICON="zed"
272 export APP_NAME="Zed"
274 mkdir -p "$out/share/applications"
275 ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
281 nativeInstallCheckInputs = [
284 versionCheckProgram = "${placeholder "out"}/bin/zeditor";
285 versionCheckProgramArg = [ "--version" ];
286 doInstallCheck = true;
289 updateScript = gitUpdater {
291 ignoredVersions = "pre";
294 fhsWithPackages = f: fhs { additionalPkgs = f; };
298 description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";
299 homepage = "https://zed.dev";
300 changelog = "https://github.com/zed-industries/zed/releases/tag/v${version}";
301 license = lib.licenses.gpl3Only;
302 maintainers = with lib.maintainers; [
306 mainProgram = "zeditor";
307 platforms = lib.platforms.linux ++ lib.platforms.darwin;