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