1{
2 lib,
3 craneLib,
4 rustPlatform,
5 clang,
6 llvmPackages_18,
7 mold-wrapped,
8 copyDesktopItems,
9 curl,
10 perl,
11 pkg-config,
12 protobuf,
13 fontconfig,
14 freetype,
15 libgit2,
16 openssl,
17 sqlite,
18 zlib,
19 zstd,
20 alsa-lib,
21 libxkbcommon,
22 wayland,
23 libglvnd,
24 xorg,
25 makeFontsConf,
26 vulkan-loader,
27 envsubst,
28 stdenvAdapters,
29 nix-gitignore,
30 withGLES ? false,
31}: let
32 includeFilter = path: type: let
33 baseName = baseNameOf (toString path);
34 parentDir = dirOf path;
35 inRootDir = type == "directory" && parentDir == ../.;
36 in
37 !(inRootDir && (baseName == "docs" || baseName == ".github" || baseName == "script" || baseName == ".git" || baseName == "target"));
38
39 src = lib.cleanSourceWith {
40 src = nix-gitignore.gitignoreSource [] ../.;
41 filter = includeFilter;
42 name = "source";
43 };
44
45 stdenv = stdenvAdapters.useMoldLinker llvmPackages_18.stdenv;
46
47 commonArgs =
48 craneLib.crateNameFromCargoToml {cargoToml = ../crates/zed/Cargo.toml;}
49 // {
50 inherit src stdenv;
51
52 nativeBuildInputs = [
53 clang
54 copyDesktopItems
55 curl
56 mold-wrapped
57 perl
58 pkg-config
59 protobuf
60 rustPlatform.bindgenHook
61 ];
62
63 buildInputs = [
64 curl
65 fontconfig
66 freetype
67 libgit2
68 openssl
69 sqlite
70 zlib
71 zstd
72
73 alsa-lib
74 libxkbcommon
75 wayland
76 xorg.libxcb
77 ];
78
79 ZSTD_SYS_USE_PKG_CONFIG = true;
80 FONTCONFIG_FILE = makeFontsConf {
81 fontDirectories = [
82 "../assets/fonts/zed-mono"
83 "../assets/fonts/zed-sans"
84 ];
85 };
86 ZED_UPDATE_EXPLANATION = "zed has been installed using nix. Auto-updates have thus been disabled.";
87 };
88
89 cargoArtifacts = craneLib.buildDepsOnly commonArgs;
90
91 gpu-lib =
92 if withGLES
93 then libglvnd
94 else vulkan-loader;
95
96 zed = craneLib.buildPackage (commonArgs
97 // {
98 inherit cargoArtifacts;
99 cargoExtraArgs = "--package=zed --package=cli";
100 buildFeatures = ["gpui/runtime_shaders"];
101 doCheck = false;
102
103 RUSTFLAGS =
104 if withGLES
105 then "--cfg gles"
106 else "";
107
108 postFixup = ''
109 patchelf --add-rpath ${gpu-lib}/lib $out/libexec/*
110 patchelf --add-rpath ${wayland}/lib $out/libexec/*
111 '';
112
113 postInstall = ''
114 mkdir -p $out/bin $out/libexec
115 mv $out/bin/zed $out/libexec/zed-editor
116 mv $out/bin/cli $out/bin/zed
117
118 install -D crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
119 install -D crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png
120
121 export DO_STARTUP_NOTIFY="true"
122 export APP_CLI="zed"
123 export APP_ICON="zed"
124 export APP_NAME="Zed"
125 export APP_ARGS="%U"
126 mkdir -p "$out/share/applications"
127 ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
128 '';
129 });
130in
131 zed
132 // {
133 meta = with lib; {
134 description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";
135 homepage = "https://zed.dev";
136 changelog = "https://zed.dev/releases/preview";
137 license = licenses.gpl3Only;
138 mainProgram = "zed";
139 platforms = platforms.linux;
140 };
141 }