evcc: 0.131.4 -> 0.131.5
[NixPkgs.git] / pkgs / by-name / ze / zed-editor / package.nix
blobe0c1383b6a64f2edccd62c31a3c588026db57d7f
2   lib,
3   rustPlatform,
4   fetchFromGitHub,
5   clang,
6   cmake,
7   copyDesktopItems,
8   curl,
9   perl,
10   pkg-config,
11   protobuf,
12   fontconfig,
13   freetype,
14   libgit2,
15   openssl,
16   sqlite,
17   zlib,
18   zstd,
19   alsa-lib,
20   libxkbcommon,
21   wayland,
22   libglvnd,
23   xorg,
24   stdenv,
25   makeFontsConf,
26   vulkan-loader,
27   envsubst,
28   gitUpdater,
29   cargo-about,
30   versionCheckHook,
31   zed-editor,
32   buildFHSEnv,
33   cargo-bundle,
34   git,
35   apple-sdk_15,
36   darwinMinVersionHook,
37   makeWrapper,
38   nodePackages_latest,
40   withGLES ? false,
43 assert withGLES -> stdenv.hostPlatform.isLinux;
45 let
46   executableName = "zeditor";
47   # Based on vscode.fhs
48   # Zed allows for users to download and use extensions
49   # which often include the usage of pre-built binaries.
50   # See #309662
51   #
52   # buildFHSEnv allows for users to use the existing Zed
53   # extension tooling without significant pain.
54   fhs =
55     {
56       additionalPkgs ? pkgs: [ ],
57     }:
58     buildFHSEnv {
59       # also determines the name of the wrapped command
60       name = executableName;
62       # additional libraries which are commonly needed for extensions
63       targetPkgs =
64         pkgs:
65         (with pkgs; [
66           # ld-linux-x86-64-linux.so.2 and others
67           glibc
68         ])
69         ++ additionalPkgs pkgs;
71       # symlink shared assets, including icons and desktop entries
72       extraInstallCommands = ''
73         ln -s "${zed-editor}/share" "$out/"
74       '';
76       runScript = "${zed-editor}/bin/${executableName}";
78       passthru = {
79         inherit executableName;
80         inherit (zed-editor) pname version;
81       };
83       meta = zed-editor.meta // {
84         description = ''
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.
87         '';
88       };
89     };
91 rustPlatform.buildRustPackage rec {
92   pname = "zed-editor";
93   version = "0.160.7";
95   src = fetchFromGitHub {
96     owner = "zed-industries";
97     repo = "zed";
98     rev = "refs/tags/v${version}";
99     hash = "sha256-mbBETOZVXTcfS+yGWPqEh+NEjo6UMTvk3XMghd8+s/s=";
100   };
102   patches =
103     [
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
109     ]
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
118     ];
120   cargoLock = {
121     lockFile = ./Cargo.lock;
122     outputHashes = {
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=";
140     };
141   };
143   nativeBuildInputs =
144     [
145       clang
146       cmake
147       copyDesktopItems
148       curl
149       perl
150       pkg-config
151       protobuf
152       rustPlatform.bindgenHook
153       cargo-about
154     ]
155     ++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ]
156     ++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ];
158   dontUseCmakeConfigure = true;
160   buildInputs =
161     [
162       curl
163       fontconfig
164       freetype
165       libgit2
166       openssl
167       sqlite
168       zlib
169       zstd
170     ]
171     ++ lib.optionals stdenv.hostPlatform.isLinux [
172       alsa-lib
173       libxkbcommon
174       wayland
175       xorg.libxcb
176     ]
177     ++ lib.optionals stdenv.hostPlatform.isDarwin [
178       apple-sdk_15
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")
184     ];
186   cargoBuildFlags = [
187     "--package=zed"
188     "--package=cli"
189   ];
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" ];
195   env = {
196     ZSTD_SYS_USE_PKG_CONFIG = true;
197     FONTCONFIG_FILE = makeFontsConf {
198       fontDirectories = [
199         "${src}/assets/fonts/plex-mono"
200         "${src}/assets/fonts/plex-sans"
201       ];
202     };
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";
211   };
213   RUSTFLAGS = if withGLES then "--cfg gles" else "";
214   gpu-lib = if withGLES then libglvnd else vulkan-loader;
216   preBuild = ''
217     bash script/generate-licenses
218   '';
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 ]
225     }
226   '';
228   preCheck = ''
229     export HOME=$(mktemp -d);
230   '';
232   checkFlags =
233     [
234       # Flaky: unreliably fails on certain hosts (including Hydra)
235       "--skip=zed::tests::test_window_edit_state_restoring_enabled"
236     ]
237     ++ lib.optionals stdenv.hostPlatform.isLinux [
238       # Fails on certain hosts (including Hydra) for unclear reason
239       "--skip=test_open_paths_action"
240     ];
242   installPhase =
243     if stdenv.hostPlatform.isDarwin then
244       ''
245         runHook preInstall
247         # cargo-bundle expects the binary in target/release
248         mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed target/release/zed
250         pushd crates/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
260         # Append extensions
261         cat resources/info/*.plist >> Info.plist
262         # Add closing tags
263         printf "</dict>\n</plist>\n" >> Info.plist
264         mv Info.plist $app_path/Contents/Info.plist
266         popd
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
278         runHook postInstall
279       ''
280     else
281       ''
282         runHook preInstall
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)
293         (
294           export DO_STARTUP_NOTIFY="true"
295           export APP_CLI="zeditor"
296           export APP_ICON="zed"
297           export APP_NAME="Zed"
298           export APP_ARGS="%U"
299           mkdir -p "$out/share/applications"
300           ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
301         )
303         runHook postInstall
304       '';
306   nativeInstallCheckInputs = [
307     versionCheckHook
308   ];
309   versionCheckProgram = "${placeholder "out"}/bin/zeditor";
310   versionCheckProgramArg = [ "--version" ];
311   doInstallCheck = true;
313   passthru = {
314     updateScript = gitUpdater {
315       rev-prefix = "v";
316       ignoredVersions = "pre";
317     };
318     fhs = fhs { };
319     fhsWithPackages = f: fhs { additionalPkgs = f; };
320   };
322   meta = {
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; [
328       GaetanLepage
329       niklaskorz
330     ];
331     mainProgram = "zeditor";
332     platforms = lib.platforms.linux ++ lib.platforms.darwin;
333   };