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-mbBETOZVXTcfS+yGWPqEh+NEjo6UMTvk3XMghd8+s/s=";
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
121 lockFile = ./Cargo.lock;
123 "alacritty_terminal-0.24.1-dev" = "sha256-b4oSDhsAAYjpYGfFgA1Q1642JoJQ9k5RTsPgFUpAFmc=";
124 "async-pipe-0.1.3" = "sha256-g120X88HGT8P6GNCrzpS5SutALx5H+45Sf4iSSxzctE=";
125 "async-stripe-0.40.0" = "sha256-kVdYCmlM8DilSrcOGxI1tvSiUjSrXdnmKqBA9WUJgMw=";
126 "blade-graphics-0.5.0" = "sha256-j/JI34ZPD7RAHNHu3krgDLnIq4QmmZaZaU1FwD7f2FM=";
127 "cosmic-text-0.11.2" = "sha256-TLPDnqixuW+aPAhiBhSvuZIa69vgV3xLcw32OlkdCcM=";
128 "font-kit-0.14.1" = "sha256-qUKvmi+RDoyhMrZ7T6SoVAyMc/aasQ9Y/okzre4SzXo=";
129 "lsp-types-0.95.1" = "sha256-N4MKoU9j1p/Xeowki/+XiNQPwIcTm9DgmfM/Eieq4js=";
130 "nvim-rs-0.8.0-pre" = "sha256-VA8zIynflul1YKBlSxGCXCwa2Hz0pT3mH6OPsfS7Izo=";
131 "pet-0.1.0" = "sha256-RxwisvRC5I3TCMAOT+kPasijuf66F+VFok1O9Ep8tGE=";
132 "reqwest-0.12.8" = "sha256-mjO6SPYOMiw1H0ZEbd4BlPivPtaLVNftpsCu+M2i3Qw=";
133 "tree-sitter-gomod-1.0.2" = "sha256-FCb8ndKSFiLY7/nTX7tWF8c4KcSvoBU1QB5R4rdOgT0=";
134 "tree-sitter-gowork-0.0.1" = "sha256-WRMgGjOlJ+bT/YnSBeSLRTLlltA5WwTvV0Ow/949+BE=";
135 "tree-sitter-heex-0.0.1" = "sha256-SnjhL0WVsHOKuUp3dkTETnCgC/Z7WN0XmpQdJPBeBhw=";
136 "tree-sitter-md-0.3.2" = "sha256-q2/aJx+385B8HiU0soZ1vtRvjkE21ABGzIyR1qwKFOU=";
137 "tree-sitter-yaml-0.6.1" = "sha256-95u/bq74SiUHW8lVp3RpanmYS/lyVPW0Inn8gR7N3IQ=";
138 "xim-0.4.0" = "sha256-BXyaIBoqMNbzaSJqMadmofdjtlEVSoU6iogF66YP6a4=";
139 "xkbcommon-0.7.0" = "sha256-2RjZWiAaz8apYTrZ82qqH4Gv20WyCtPT+ldOzm0GWMo=";
152 rustPlatform.bindgenHook
155 ++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ]
156 ++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ];
158 dontUseCmakeConfigure = true;
171 ++ lib.optionals stdenv.hostPlatform.isLinux [
177 ++ lib.optionals stdenv.hostPlatform.isDarwin [
179 # This will need to be increased to 12.3 once
180 # https://github.com/zed-industries/zed/pull/13343
181 # is merged and released, as ScreenCaptureKit is only available on 12.3 and up:
182 # https://developer.apple.com/documentation/screencapturekit
183 (darwinMinVersionHook "10.15")
191 # Required on darwin because we don't have access to the
192 # proprietary Metal shader compiler.
193 buildFeatures = lib.optionals stdenv.hostPlatform.isDarwin [ "gpui/runtime_shaders" ];
196 ZSTD_SYS_USE_PKG_CONFIG = true;
197 FONTCONFIG_FILE = makeFontsConf {
199 "${src}/assets/fonts/plex-mono"
200 "${src}/assets/fonts/plex-sans"
203 # Setting this environment variable allows to disable auto-updates
204 # https://zed.dev/docs/development/linux#notes-for-packaging-zed
205 ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled.";
206 # Used by `zed --version`
207 RELEASE_VERSION = version;
208 # Required until `-isysroot` can be used with libclang in nixpkgs on darwin, otherwise
209 # rust bindgen will not work as expected
210 NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-F${apple-sdk_15.sdkroot}/System/Library/Frameworks";
213 RUSTFLAGS = if withGLES then "--cfg gles" else "";
214 gpu-lib = if withGLES then libglvnd else vulkan-loader;
217 bash script/generate-licenses
220 postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
221 patchelf --add-rpath ${gpu-lib}/lib $out/libexec/*
222 patchelf --add-rpath ${wayland}/lib $out/libexec/*
223 wrapProgram $out/libexec/zed-editor --suffix PATH : ${
224 lib.makeBinPath [ nodePackages_latest.nodejs ]
229 export HOME=$(mktemp -d);
234 # Flaky: unreliably fails on certain hosts (including Hydra)
235 "--skip=zed::tests::test_window_edit_state_restoring_enabled"
237 ++ lib.optionals stdenv.hostPlatform.isLinux [
238 # Fails on certain hosts (including Hydra) for unclear reason
239 "--skip=test_open_paths_action"
243 if stdenv.hostPlatform.isDarwin then
247 # cargo-bundle expects the binary in target/release
248 mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed target/release/zed
252 # Note that this is GNU sed, while Zed's bundle-mac uses BSD sed
253 sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml
254 export CARGO_BUNDLE_SKIP_BUILD=true
255 app_path=$(cargo bundle --release | xargs)
257 # We're not using Zed's fork of cargo-bundle, so we must manually append their plist extensions
258 # Remove closing tags from Info.plist (last two lines)
259 head -n -2 $app_path/Contents/Info.plist > Info.plist
261 cat resources/info/*.plist >> Info.plist
263 printf "</dict>\n</plist>\n" >> Info.plist
264 mv Info.plist $app_path/Contents/Info.plist
268 mkdir -p $out/Applications $out/bin
269 # Zed expects git next to its own binary
270 ln -s ${git}/bin/git $app_path/Contents/MacOS/git
271 mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $app_path/Contents/MacOS/cli
272 mv $app_path $out/Applications/
274 # Physical location of the CLI must be inside the app bundle as this is used
275 # to determine which app to start
276 ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zeditor
284 mkdir -p $out/bin $out/libexec
285 cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed $out/libexec/zed-editor
286 cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $out/bin/zeditor
288 install -D ${src}/crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
289 install -D ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png
291 # extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst)
292 # and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name)
294 export DO_STARTUP_NOTIFY="true"
295 export APP_CLI="zeditor"
296 export APP_ICON="zed"
297 export APP_NAME="Zed"
299 mkdir -p "$out/share/applications"
300 ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
306 nativeInstallCheckInputs = [
309 versionCheckProgram = "${placeholder "out"}/bin/zeditor";
310 versionCheckProgramArg = [ "--version" ];
311 doInstallCheck = true;
314 updateScript = gitUpdater {
316 ignoredVersions = "pre";
319 fhsWithPackages = f: fhs { additionalPkgs = f; };
323 description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";
324 homepage = "https://zed.dev";
325 changelog = "https://github.com/zed-industries/zed/releases/tag/v${version}";
326 license = lib.licenses.gpl3Only;
327 maintainers = with lib.maintainers; [
331 mainProgram = "zeditor";
332 platforms = lib.platforms.linux ++ lib.platforms.darwin;