From 4a7c84f490b6ab7d1ba1628ed0dc5433f18dcceb Mon Sep 17 00:00:00 2001 From: Julia Ryan Date: Mon, 10 Mar 2025 01:06:11 -0700 Subject: [PATCH] Fix nix build (#26270) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR includes lots of small fixes to get our `build.nix` and `shell.nix` back to a working state. I've tested this by running `cargo run` (inside the devshell) and `nix run` on x86 nixos and arm64 darwin machines. I'd appreciate it if others could test building inside the devshell to double-check that it's not just working because I happen to have some system-level packages installed, as well as seeing if it works on other platforms (non-nixos linux, arm linux, x86 darwin). I couldn't get the full test suite (`cargo nextest run --workspace`) passing in the devshell on darwin, but they _are_ all passing on nixos. nixpkgs [disables some of our tests](https://github.com/NixOS/nixpkgs/blob/92d11f06d5cfa80901ef8eea11ee294520fae485/pkgs/by-name/ze/zed-editor/package.nix#L226-L234) that apparently fail or are flakey on hydra, but they don't know why. I'm going to punt on debugging those for now, especially given that they seem to be working for me. I'm also unsure of whether we actually want the nix checkPhase to run the full test suite (it's currently not passing `--workspace`) given that we have separate CI that should enforce that those pass on all PRs. Here's an overview of the changes made: - Fix our `generate-licenses` script - Relaxes the `cargo-about` version requirement slightly so it doesn't try to install an older binary when the nixpkgs one is newer than our requirement - Add a workaround for [this cargo-about issue](https://github.com/zed-industries/zed/issues/19971) obviating the need for the patching done in the nixpkgs package - Set the new `--frozen` flag to avoid network access/mutating the lockfile - Use dynamic webrtc lib from nixpkgs, and fixes up the build script in webrtc-sys that hardcodes it to be statically linked. - Use `inputsFrom` in `shell.nix` and avoid duplicating everything from `build.nix` - Add a temporary workaround for an [upstream crane bug](https://github.com/ipetkov/crane/issues/808). - Fix shebangs in our `script` dir to not hard-code `/bin/bash` There are still a bunch of issues that aren't resolved here, I'll make a tracking issue for those and try to land this first just to get back to an unbroken state. Eventually among other things I'd like to use a `libgit2` from `staticPkgs` and musl cross compilation to build the remote server under nix, and then add that as a separate flake output and include it in the shell's `inputsFrom` list. Thanks @niklaskorz, @GaetanLepage, @bbigras and all the other nixpkgs maintainers that have kept the `zed-editor` package working and up to date! I seriously considered just making our flake `overrideAttrs` the package in nixpkgs given how well maintained it is. Thanks @WeetHet for your volunteer maintinance of this flake. I referenced #24953 while working on these fixes, and I'd love to collaborate on adding some of those pieces like treefmt and a github action. If you're interested I'd really appreciate some help debugging why crane's `buildDepsOnly` isn't working for us. I'm assuming it'd make our `nix build` times go way down from the improved dep caching if we could get it working. Thanks @rrbutani for all the help on this PR 💙. Release Notes: - N/A --------- Co-authored-by: Rahul Butani Co-authored-by: Rahul Butani --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/terminal_view/scripts/print256color.sh | 2 +- crates/terminal_view/scripts/truecolor.sh | 2 +- default.nix | 25 +- flake.lock | 18 +- flake.nix | 3 +- nix/build.nix | 327 ++++++++++-------- nix/shell.nix | 111 +++--- rust-toolchain.toml | 9 +- script/bump-extension-cli | 2 +- script/bump-nightly | 2 +- script/bump-zed-minor-versions | 2 +- script/bump-zed-patch-version | 2 +- script/check-rust-livekit-macos | 2 +- script/clear-target-dir-if-larger-than | 2 +- script/collab-flamegraph | 2 +- script/crate-dep-graph | 2 +- script/deploy-collab | 2 +- script/deploy-postgrest | 2 +- script/drop-test-dbs | 2 +- script/generate-licenses | 23 +- script/generate-licenses-csv | 16 +- script/generate-terms-rtf | 2 +- script/get-crate-version | 2 +- script/get-released-version | 2 +- script/import-themes | 2 +- script/kube-shell | 2 +- script/lib/bump-version.sh | 2 +- script/metal-debug | 2 +- script/new-crate | 2 +- script/prompts | 2 +- script/run-local-minio | 4 +- script/seed-db | 2 +- script/storybook | 2 +- script/trigger-release | 2 +- script/what-is-deployed | 2 +- shell.nix | 25 +- 38 files changed, 331 insertions(+), 286 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82fc8b1bfe7c0cba939c0a716c6740b22f512bce..3995e9518b76bb7af774f7556d2edf30ad4a435f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,7 +84,7 @@ dependencies = [ [[package]] name = "alacritty_terminal" version = "0.25.1-dev" -source = "git+https://github.com/zed-industries/alacritty.git?rev=03c2907b44b4189aac5fdeaea331f5aab5c7072e#03c2907b44b4189aac5fdeaea331f5aab5c7072e" +source = "git+https://github.com/zed-industries/alacritty.git?branch=add-hush-login-flag#828457c9ff1f7ea0a0469337cc8a37ee3a1b0590" dependencies = [ "base64 0.22.1", "bitflags 2.8.0", diff --git a/Cargo.toml b/Cargo.toml index 7f2824c038a2166ac8d163d909f0c7c5371d51a5..859beb2b2864edd043490e1011a8c56a87815abc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -370,7 +370,7 @@ zeta = { path = "crates/zeta" } # aho-corasick = "1.1" -alacritty_terminal = { git = "https://github.com/zed-industries/alacritty.git", rev = "03c2907b44b4189aac5fdeaea331f5aab5c7072e" } +alacritty_terminal = { git = "https://github.com/zed-industries/alacritty.git", branch = "add-hush-login-flag" } any_vec = "0.14" anyhow = "1.0.86" arrayvec = { version = "0.7.4", features = ["serde"] } diff --git a/crates/terminal_view/scripts/print256color.sh b/crates/terminal_view/scripts/print256color.sh index 8a53f3bc025842d900b5b4797eefc6d8a0946120..9cb3b1c47cf112a2fc90494e9dae1684d7ac60c4 100755 --- a/crates/terminal_view/scripts/print256color.sh +++ b/crates/terminal_view/scripts/print256color.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Tom Hale, 2016. MIT Licence. # Print out 256 colours, with each number printed in its corresponding colour diff --git a/crates/terminal_view/scripts/truecolor.sh b/crates/terminal_view/scripts/truecolor.sh index c11037b10031619d1abc2fe3eb3208d400d0c5d8..622051f2429277e475b2603139f72f6c189f23c2 100755 --- a/crates/terminal_view/scripts/truecolor.sh +++ b/crates/terminal_view/scripts/truecolor.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copied from: https://unix.stackexchange.com/a/696756 # Based on: https://gist.github.com/XVilka/8346728 and https://unix.stackexchange.com/a/404415/395213 diff --git a/default.nix b/default.nix index 2b625713d6c219acabcd123692ad69e50fe1cdd6..1d976a357629ddff8747d676131cd2fc52b7e434 100644 --- a/default.nix +++ b/default.nix @@ -1,14 +1,11 @@ -( - import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - {src = ./.;} -) -.defaultNix +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = + lock.nodes.flake-compat.locked.url + or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } +) { src = ./.; }).defaultNix diff --git a/flake.lock b/flake.lock index 54da7c2dce8e79fa9c41618cfac018cd5fe7c3e3..614bcfd0d0fe9b99be77f436d00169d719f9dd72 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "crane": { "locked": { - "lastModified": 1739936662, - "narHash": "sha256-x4syUjNUuRblR07nDPeLDP7DpphaBVbUaSoeZkFbGSk=", + "lastModified": 1741148495, + "narHash": "sha256-EV8KUaIZ2/CdBXlutXrHoZYbWPeB65p5kKZk71gvDRI=", "owner": "ipetkov", "repo": "crane", - "rev": "19de14aaeb869287647d9461cbd389187d8ecdb7", + "rev": "75390a36cd0c2cdd5f1aafd8a9f827d7107f2e53", "type": "github" }, "original": { @@ -32,11 +32,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1740695751, - "narHash": "sha256-D+R+kFxy1KsheiIzkkx/6L63wEHBYX21OIwlFV8JvDs=", + "lastModified": 1741246872, + "narHash": "sha256-Q6pMP4a9ed636qilcYX8XUguvKl/0/LGXhHcRI91p0U=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6313551cd05425cd5b3e63fe47dbc324eabb15e4", + "rev": "10069ef4cf863633f57238f179a0297de84bd8d3", "type": "github" }, "original": { @@ -61,11 +61,11 @@ ] }, "locked": { - "lastModified": 1740882709, - "narHash": "sha256-VC+8GxWK4p08jjIbmsNfeFQajW2lsiOR/XQiOOvqgvs=", + "lastModified": 1741314698, + "narHash": "sha256-6Yp0CTwAY/jq/F81Sa8NM0Zi1EwxAdASO6y4A5neGuc=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "f4d5a693c18b389f0d58f55b6f7be6ef85af186f", + "rev": "4e9af61c1a631886cdc7e13032af4fc9e75bb76b", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index f797227fba2be38d48fba99f6ef61b9826eb1497..69060662601843a7ee5a8775482786b875558879 100644 --- a/flake.nix +++ b/flake.nix @@ -50,12 +50,11 @@ in { packages = forAllSystems (pkgs: { - zed-editor = pkgs.zed-editor; default = pkgs.zed-editor; }); devShells = forAllSystems (pkgs: { - default = import ./nix/shell.nix { inherit pkgs; }; + default = pkgs.callPackage ./nix/shell.nix { }; }); formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style); diff --git a/nix/build.nix b/nix/build.nix index e78025dffdef2e753c2e3c45a0d8e23aaf11e626..e07148f405dda7008d6e5f94b8050c453738bb65 100644 --- a/nix/build.nix +++ b/nix/build.nix @@ -2,11 +2,12 @@ lib, crane, rustToolchain, - fetchpatch, - clang, + rustPlatform, cmake, copyDesktopItems, + fetchFromGitHub, curl, + clang, perl, pkg-config, protobuf, @@ -29,11 +30,12 @@ cargo-about, cargo-bundle, git, + livekit-libwebrtc, apple-sdk_15, + darwin, darwinMinVersionHook, makeWrapper, nodejs_22, - nix-gitignore, withGLES ? false, }: @@ -41,176 +43,208 @@ assert withGLES -> stdenv.hostPlatform.isLinux; let - includeFilter = - path: type: + mkIncludeFilter = + root': path: type: let - baseName = baseNameOf (toString path); - parentDir = dirOf path; - inRootDir = type == "directory" && parentDir == ../.; + # note: under lazy-trees this introduces an extra copy + root = toString root' + "/"; + relPath = lib.removePrefix root path; + topLevelIncludes = [ + "crates" + "assets" + "extensions" + "script" + "tooling" + "Cargo.toml" + ".config" # nextest? + ]; + firstComp = builtins.head (lib.path.subpath.components relPath); in - !( - inRootDir - && (baseName == "docs" || baseName == ".github" || baseName == ".git" || baseName == "target") - ); + builtins.elem firstComp topLevelIncludes; + craneLib = crane.overrideToolchain rustToolchain; - commonSrc = lib.cleanSourceWith { - src = nix-gitignore.gitignoreSource [ ] ../.; - filter = includeFilter; - name = "source"; - }; - commonArgs = rec { - pname = "zed-editor"; - version = "nightly"; - - src = commonSrc; - - nativeBuildInputs = - [ - clang - cmake - copyDesktopItems - curl - perl - pkg-config - protobuf - cargo-about - ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ]; - - buildInputs = - [ - curl - fontconfig - freetype - libgit2 - openssl - sqlite - zlib - zstd - ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ - alsa-lib - libxkbcommon - wayland - xorg.libxcb - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - apple-sdk_15 - (darwinMinVersionHook "10.15") - ]; + gpu-lib = if withGLES then libglvnd else vulkan-loader; + commonArgs = + let + zedCargoLock = builtins.fromTOML (builtins.readFile ../crates/zed/Cargo.toml); + in + rec { + pname = "zed-editor"; + version = zedCargoLock.package.version + "-nightly"; + src = builtins.path { + path = ../.; + filter = mkIncludeFilter ../.; + name = "source"; + }; + + cargoLock = ../Cargo.lock; + + nativeBuildInputs = + [ + clang # TODO: use pkgs.clangStdenv or ignore cargo config? + cmake + copyDesktopItems + curl + perl + pkg-config + protobuf + cargo-about + rustPlatform.bindgenHook + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + # TODO: move to overlay so it's usable in the shell + (cargo-bundle.overrideAttrs (old: { + version = "0.6.0-zed"; + src = fetchFromGitHub { + owner = "zed-industries"; + repo = "cargo-bundle"; + rev = "zed-deploy"; + hash = "sha256-OxYdTSiR9ueCvtt7Y2OJkvzwxxnxu453cMS+l/Bi5hM="; + }; + })) + ]; - env = { - ZSTD_SYS_USE_PKG_CONFIG = true; - FONTCONFIG_FILE = makeFontsConf { - fontDirectories = [ - "${src}/assets/fonts/plex-mono" - "${src}/assets/fonts/plex-sans" + buildInputs = + [ + curl + fontconfig + freetype + # TODO: need staticlib of this for linking the musl remote server. + # should make it a separate derivation/flake output + # see https://crane.dev/examples/cross-musl.html + libgit2 + openssl + sqlite + zlib + zstd + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + alsa-lib + libxkbcommon + wayland + gpu-lib + xorg.libxcb + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + apple-sdk_15 + darwin.apple_sdk.frameworks.System + (darwinMinVersionHook "10.15") ]; + + cargoExtraArgs = "--package=zed --package=cli --features=gpui/runtime_shaders"; + + env = { + ZSTD_SYS_USE_PKG_CONFIG = true; + FONTCONFIG_FILE = makeFontsConf { + fontDirectories = [ + ../assets/fonts/plex-mono + ../assets/fonts/plex-sans + ]; + }; + ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled."; + RELEASE_VERSION = version; + RUSTFLAGS = if withGLES then "--cfg gles" else ""; + # TODO: why are these not handled by the linker given that they're in buildInputs? + NIX_LDFLAGS = "-rpath ${ + lib.makeLibraryPath [ + gpu-lib + wayland + ] + }"; + LK_CUSTOM_WEBRTC = livekit-libwebrtc; + }; + + cargoVendorDir = craneLib.vendorCargoDeps { + inherit src cargoLock; + overrideVendorGitCheckout = + let + hasWebRtcSys = builtins.any (crate: crate.name == "webrtc-sys"); + # `webrtc-sys` expects a staticlib; nixpkgs' `livekit-webrtc` has been patched to + # produce a `dylib`... patching `webrtc-sys`'s build script is the easier option + # TODO: send livekit sdk a PR to make this configurable + postPatch = '' + substituteInPlace webrtc-sys/build.rs --replace-fail \ + "cargo:rustc-link-lib=static=webrtc" "cargo:rustc-link-lib=dylib=webrtc" + ''; + in + crates: drv: + if hasWebRtcSys crates then + drv.overrideAttrs (o: { + postPatch = (o.postPatch or "") + postPatch; + }) + else + drv; }; - ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled."; - RELEASE_VERSION = version; }; - }; - cargoArtifacts = craneLib.buildDepsOnly commonArgs; + cargoArtifacts = craneLib.buildDepsOnly ( + commonArgs + // { + # TODO: figure out why the main derivation is still rebuilding deps... + # disable pre-building the deps for now + buildPhaseCargoCommand = "true"; + + # forcibly inhibit `doInstallCargoArtifacts`... + # https://github.com/ipetkov/crane/blob/1d19e2ec7a29dcc25845eec5f1527aaf275ec23e/lib/setupHooks/installCargoArtifactsHook.sh#L111 + # + # it is, unfortunately, not overridable in `buildDepsOnly`: + # https://github.com/ipetkov/crane/blob/1d19e2ec7a29dcc25845eec5f1527aaf275ec23e/lib/buildDepsOnly.nix#L85 + preBuild = "postInstallHooks=()"; + doCheck = false; + } + ); in craneLib.buildPackage ( - commonArgs - // rec { + lib.recursiveUpdate commonArgs { inherit cargoArtifacts; - patches = - [ - # Zed uses cargo-install to install cargo-about during the script execution. - # We provide cargo-about ourselves and can skip this step. - # Until https://github.com/zed-industries/zed/issues/19971 is fixed, - # we also skip any crate for which the license cannot be determined. - (fetchpatch { - url = "https://raw.githubusercontent.com/NixOS/nixpkgs/1fd02d90c6c097f91349df35da62d36c19359ba7/pkgs/by-name/ze/zed-editor/0001-generate-licenses.patch"; - hash = "sha256-cLgqLDXW1JtQ2OQFLd5UolAjfy7bMoTw40lEx2jA2pk="; - }) - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ - # Livekit requires Swift 6 - # We need this until livekit-rust sdk is used - (fetchpatch { - url = "https://raw.githubusercontent.com/NixOS/nixpkgs/1fd02d90c6c097f91349df35da62d36c19359ba7/pkgs/by-name/ze/zed-editor/0002-disable-livekit-darwin.patch"; - hash = "sha256-whZ7RaXv8hrVzWAveU3qiBnZSrvGNEHTuyNhxgMIo5w="; - }) - ]; - - cargoExtraArgs = "--package=zed --package=cli --features=gpui/runtime_shaders"; + patches = lib.optionals stdenv.hostPlatform.isDarwin [ + # Livekit requires Swift 6 + # We need this until livekit-rust sdk is used + ../script/patches/use-cross-platform-livekit.patch + ]; dontUseCmakeConfigure = true; - preBuild = '' - bash script/generate-licenses - ''; - postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' - patchelf --add-rpath ${gpu-lib}/lib $out/libexec/* - patchelf --add-rpath ${wayland}/lib $out/libexec/* - wrapProgram $out/libexec/zed-editor --suffix PATH : ${lib.makeBinPath [ nodejs_22 ]} + # without the env var generate-licenses fails due to crane's fetchCargoVendor, see: + # https://github.com/zed-industries/zed/issues/19971#issuecomment-2688455390 + preBuild = '' + ALLOW_MISSING_LICENSES=yes bash script/generate-licenses + echo nightly > crates/zed/RELEASE_CHANNEL ''; - RUSTFLAGS = if withGLES then "--cfg gles" else ""; - gpu-lib = if withGLES then libglvnd else vulkan-loader; + # TODO: try craneLib.cargoNextest separate output and doCheck=false + # do we even care about running our test suite in the nix sandbox? - preCheck = '' - export HOME=$(mktemp -d); - ''; - - cargoTestExtraArgs = - "-- " - + lib.concatStringsSep " " ( - [ - # Flaky: unreliably fails on certain hosts (including Hydra) - "--skip=zed::tests::test_window_edit_state_restoring_enabled" - ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ - # Fails on certain hosts (including Hydra) for unclear reason - "--skip=test_open_paths_action" - ] - ); + # see crane bug: https://github.com/ipetkov/crane/issues/808 + doNotRemoveReferencesToRustToolchain = true; + doNotRemoveReferencesToVendorDir = true; installPhase = if stdenv.hostPlatform.isDarwin then '' runHook preInstall - # cargo-bundle expects the binary in target/release - mv target/release/zed target/release/zed - pushd crates/zed - - # Note that this is GNU sed, while Zed's bundle-mac uses BSD sed - sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml + sed -i "s/package.metadata.bundle-nightly/package.metadata.bundle/" Cargo.toml export CARGO_BUNDLE_SKIP_BUILD=true - app_path=$(cargo bundle --release | xargs) - - # We're not using the fork of cargo-bundle, so we must manually append plist extensions - # Remove closing tags from Info.plist (last two lines) - head -n -2 $app_path/Contents/Info.plist > Info.plist - # Append extensions - cat resources/info/*.plist >> Info.plist - # Add closing tags - printf "\n\n" >> Info.plist - mv Info.plist $app_path/Contents/Info.plist - + app_path="$(cargo bundle --release | xargs)" popd mkdir -p $out/Applications $out/bin # Zed expects git next to its own binary - ln -s ${git}/bin/git $app_path/Contents/MacOS/git - mv target/release/cli $app_path/Contents/MacOS/cli - mv $app_path $out/Applications/ + ln -s ${git}/bin/git "$app_path/Contents/MacOS/git" + mv target/release/cli "$app_path/Contents/MacOS/cli" + mv "$app_path" $out/Applications/ # Physical location of the CLI must be inside the app bundle as this is used # to determine which app to start - ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zed + ln -s "$out/Applications/Zed Nightly.app/Contents/MacOS/cli" $out/bin/zed runHook postInstall '' else + # TODO: icons should probably be named "zed-nightly". fix bundle-linux first '' runHook preInstall @@ -218,24 +252,31 @@ craneLib.buildPackage ( cp target/release/zed $out/libexec/zed-editor cp target/release/cli $out/bin/zed - install -D ${commonSrc}/crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png - install -D ${commonSrc}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png + install -D "crates/zed/resources/app-icon-nightly@2x.png" \ + "$out/share/icons/hicolor/1024x1024@2x/apps/zed.png" + install -D crates/zed/resources/app-icon-nightly.png \ + $out/share/icons/hicolor/512x512/apps/zed.png - # extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst) - # and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name) + # extracted from ../script/bundle-linux (envsubst) and + # ../script/install.sh (final desktop file name) ( export DO_STARTUP_NOTIFY="true" export APP_CLI="zed" export APP_ICON="zed" - export APP_NAME="Zed" + export APP_NAME="Zed Nightly" export APP_ARGS="%U" mkdir -p "$out/share/applications" - ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop" + ${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed-Nightly.desktop" ) runHook postInstall ''; + # TODO: why isn't this also done on macOS? + postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' + wrapProgram $out/libexec/zed-editor --suffix PATH : ${lib.makeBinPath [ nodejs_22 ]} + ''; + meta = { description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter"; homepage = "https://zed.dev"; diff --git a/nix/shell.nix b/nix/shell.nix index edfa2f442c3bd2b25ddd6904b9e6391c62c5039f..8471de99c3798269ad0e1d72548335620f8c99b6 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -1,65 +1,62 @@ { - pkgs ? import { }, + lib, + mkShell, + stdenv, + stdenvAdapters, + makeFontsConf, + + zed-editor, + + rust-analyzer, + cargo-nextest, + nixfmt-rfc-style, + protobuf, + nodejs_22, }: let - inherit (pkgs) lib; + moldStdenv = stdenvAdapters.useMoldLinker stdenv; + mkShell' = + if stdenv.hostPlatform.isLinux then mkShell.override { stdenv = moldStdenv; } else mkShell; in -pkgs.mkShell rec { - packages = - [ - pkgs.clang - pkgs.curl - pkgs.cmake - pkgs.perl - pkgs.pkg-config - pkgs.protobuf - pkgs.rustPlatform.bindgenHook - pkgs.rust-analyzer - ] - ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ - pkgs.mold - ]; - - buildInputs = - [ - pkgs.bzip2 - pkgs.curl - pkgs.fontconfig - pkgs.freetype - pkgs.libgit2 - pkgs.openssl - pkgs.sqlite - pkgs.stdenv.cc.cc - pkgs.zlib - pkgs.zstd - pkgs.rustToolchain - ] - ++ lib.optionals pkgs.stdenv.hostPlatform.isLinux [ - pkgs.alsa-lib - pkgs.libxkbcommon - pkgs.wayland - pkgs.xorg.libxcb - pkgs.vulkan-loader - ] - ++ lib.optional pkgs.stdenv.hostPlatform.isDarwin pkgs.apple-sdk_15; - - LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; +mkShell' { + inputsFrom = [ zed-editor ]; + packages = [ + rust-analyzer + cargo-nextest + nixfmt-rfc-style + # TODO: package protobuf-language-server for editing zed.proto + # TODO: add other tools used in our scripts - PROTOC="${pkgs.protobuf}/bin/protoc"; + # `build.nix` adds this to the `zed-editor` wrapper (see `postFixup`) + # we'll just put it on `$PATH`: + nodejs_22 + ]; - # We set SDKROOT and DEVELOPER_DIR to the Xcode ones instead of the nixpkgs ones, - # because we need Swift 6.0 and nixpkgs doesn't have it. - # Xcode is required for development anyways - shellHook = lib.optionalString pkgs.stdenv.hostPlatform.isDarwin '' - export SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"; - export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"; - ''; + # We set SDKROOT and DEVELOPER_DIR to the Xcode ones instead of the nixpkgs ones, because + # we need Swift 6.0 and nixpkgs doesn't have it + shellHook = lib.optionalString stdenv.hostPlatform.isDarwin '' + export SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk"; + export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"; + ''; - FONTCONFIG_FILE = pkgs.makeFontsConf { - fontDirectories = [ - "./assets/fonts/zed-mono" - "./assets/fonts/zed-sans" - ]; - }; - ZSTD_SYS_USE_PKG_CONFIG = true; + env = + let + baseEnvs = + (zed-editor.overrideAttrs (attrs: { + passthru = { inherit (attrs) env; }; + })).env; # exfil `env`; it's not in drvAttrs + in + # unsetting this var so we download the staticlib during the build + (removeAttrs baseEnvs [ "LK_CUSTOM_WEBRTC" ]) + // { + # note: different than `$FONTCONFIG_FILE` in `build.nix` – this refers to relative paths + # outside the nix store instead of to `$src` + FONTCONFIG_FILE = makeFontsConf { + fontDirectories = [ + "./assets/fonts/plex-mono" + "./assets/fonts/plex-sans" + ]; + }; + PROTOC = "${protobuf}/bin/protoc"; + }; } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index cf9e0ee6ea31474a4cce3be584ae4e1c3212f5b4..9d4fa8262b4da61d5f0ca3915f06c63cbb1c2e61 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,4 +2,11 @@ channel = "1.85" profile = "minimal" components = [ "rustfmt", "clippy" ] -targets = [ "x86_64-apple-darwin", "aarch64-apple-darwin", "x86_64-unknown-linux-gnu", "wasm32-wasip1", "x86_64-pc-windows-msvc" ] +targets = [ + "x86_64-apple-darwin", + "aarch64-apple-darwin", + "x86_64-unknown-linux-gnu", + "x86_64-pc-windows-msvc", + "wasm32-wasip1", # extensions + "x86_64-unknown-linux-musl", # remote server +] diff --git a/script/bump-extension-cli b/script/bump-extension-cli index ca6a24a8d95fc388ee5376b727bdd0843eb114d6..ee7ea6f8c418ac0422c648c99f81d841fd802294 100755 --- a/script/bump-extension-cli +++ b/script/bump-extension-cli @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/script/bump-nightly b/script/bump-nightly index cea00fd1ebb9c40439809bcb0ec562120c81941e..241996238774b4958cd1266490adb0f63e9fc67b 100755 --- a/script/bump-nightly +++ b/script/bump-nightly @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/script/bump-zed-minor-versions b/script/bump-zed-minor-versions index fa30530184b82d6ebbbe2c8d658535cec05f91f2..4e59b293ff6ab0a9d4038ac5af02b2599bfa62b7 100755 --- a/script/bump-zed-minor-versions +++ b/script/bump-zed-minor-versions @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu diff --git a/script/bump-zed-patch-version b/script/bump-zed-patch-version index b52feff72f1cb41b88ce329ac3299b0f74d7914a..8a44ae6eddf17297e390361e01a82ce76ab9fdac 100755 --- a/script/bump-zed-patch-version +++ b/script/bump-zed-patch-version @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash channel=$(cat crates/zed/RELEASE_CHANNEL) diff --git a/script/check-rust-livekit-macos b/script/check-rust-livekit-macos index e2d0f9cf62d696102193d274162cbd028b2b5b5b..1afdc81b22ad3a5cb51deb364d53eef5dc36c0cb 100755 --- a/script/check-rust-livekit-macos +++ b/script/check-rust-livekit-macos @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -exuo pipefail diff --git a/script/clear-target-dir-if-larger-than b/script/clear-target-dir-if-larger-than index 691ff42ffd9a5bac91175b1b6de6e00e2abdcaf8..b77b4cff0f3d2bf22756538a49e38e8a11c200ef 100755 --- a/script/clear-target-dir-if-larger-than +++ b/script/clear-target-dir-if-larger-than @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu diff --git a/script/collab-flamegraph b/script/collab-flamegraph index a8310b1ea64972d4c73667ee655828eee5fc8ccb..058c3a9f44bc5d5acbe7c25931e911a7c34deb56 100755 --- a/script/collab-flamegraph +++ b/script/collab-flamegraph @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Notes for fixing this script if it's broken: # - if you see an error about "can't find perf_6.1" you need to install `linux-perf` from the diff --git a/script/crate-dep-graph b/script/crate-dep-graph index 25285cc097c01331e36ea34a9b5a9ef622f43342..54170a998604baa93fb722cedb3104054f1b5b39 100755 --- a/script/crate-dep-graph +++ b/script/crate-dep-graph @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/script/deploy-collab b/script/deploy-collab index d0139a084f3fe84c7a8103eae23584ea3eedf46c..f9006fd700f2af391ed3f64e2c69a9e3f706d588 100755 --- a/script/deploy-collab +++ b/script/deploy-collab @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu source script/lib/deploy-helpers.sh diff --git a/script/deploy-postgrest b/script/deploy-postgrest index 2a0b21a991c8bba181ba27a6adfd4f2fee0ab847..ca8f3686468e52c41977624e6198e69ca3718a25 100755 --- a/script/deploy-postgrest +++ b/script/deploy-postgrest @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu source script/lib/deploy-helpers.sh diff --git a/script/drop-test-dbs b/script/drop-test-dbs index 72d6ff5f79a0d7375f38dfd84f400efba9253805..d96f1bd1f0fbf7758fce1c3e25457a0c64c9041c 100755 --- a/script/drop-test-dbs +++ b/script/drop-test-dbs @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash databases=$(psql --tuples-only --command " SELECT diff --git a/script/generate-licenses b/script/generate-licenses index 368f63b7c03413f1872935b50fa42b1bf2971806..21ad6113bd780e92a5e9549e835b81feae965ea9 100755 --- a/script/generate-licenses +++ b/script/generate-licenses @@ -2,11 +2,11 @@ set -euo pipefail -CARGO_ABOUT_VERSION="0.6.6" +CARGO_ABOUT_VERSION="0.6" OUTPUT_FILE="${1:-$(pwd)/assets/licenses.md}" TEMPLATE_FILE="script/licenses/template.md.hbs" -echo -n "" > "$OUTPUT_FILE" +echo -n "" >"$OUTPUT_FILE" { echo -e "# ###### THEME LICENSES ######\n" @@ -16,21 +16,24 @@ echo -n "" > "$OUTPUT_FILE" cat assets/icons/LICENSES echo -e "\n# ###### CODE LICENSES ######\n" -} >> "$OUTPUT_FILE" +} >>"$OUTPUT_FILE" -if ! cargo install --list | grep "cargo-about v$CARGO_ABOUT_VERSION" > /dev/null; then - echo "Installing cargo-about@$CARGO_ABOUT_VERSION..." - cargo install "cargo-about@$CARGO_ABOUT_VERSION" +if ! cargo about --version | grep "cargo-about $CARGO_ABOUT_VERSION" >/dev/null; then + echo "Installing cargo-about@^$CARGO_ABOUT_VERSION..." + cargo install "cargo-about@^$CARGO_ABOUT_VERSION" else - echo "cargo-about@$CARGO_ABOUT_VERSION is already installed." + echo "cargo-about@^$CARGO_ABOUT_VERSION is already installed." fi echo "Generating cargo licenses" - +if [ -z "${ALLOW_MISSING_LICENSES-}" ]; then FAIL_FLAG=--fail; else FAIL_FLAG=""; fi +set -x cargo about generate \ - --fail \ + $FAIL_FLAG \ + --frozen \ -c script/licenses/zed-licenses.toml \ - "$TEMPLATE_FILE" >> "$OUTPUT_FILE" + "$TEMPLATE_FILE" >>"$OUTPUT_FILE" +set +x sed -i.bak 's/"/"/g' "$OUTPUT_FILE" sed -i.bak 's/'/'\''/g' "$OUTPUT_FILE" # The ` '\'' ` thing ends the string, appends a single quote, and re-opens the string diff --git a/script/generate-licenses-csv b/script/generate-licenses-csv index 75d988462c22c1fa808a4b2a699a5d7f64d25207..155406934f3df769d5f1b45b737acd64b477c385 100755 --- a/script/generate-licenses-csv +++ b/script/generate-licenses-csv @@ -2,24 +2,26 @@ set -euo pipefail -CARGO_ABOUT_VERSION="0.6.6" +CARGO_ABOUT_VERSION="0.6" OUTPUT_FILE="${1:-$(pwd)/assets/licenses.csv}" TEMPLATE_FILE="script/licenses/template.csv.hbs" -if ! cargo install --list | grep "cargo-about v$CARGO_ABOUT_VERSION" > /dev/null; then - echo "Installing cargo-about@$CARGO_ABOUT_VERSION..." - cargo install "cargo-about@$CARGO_ABOUT_VERSION" +if ! cargo about --version | grep "cargo-about $CARGO_ABOUT_VERSION" > /dev/null; then + echo "Installing cargo-about@^$CARGO_ABOUT_VERSION..." + cargo install "cargo-about@^$CARGO_ABOUT_VERSION" else - echo "cargo-about@$CARGO_ABOUT_VERSION is already installed." + echo "cargo-about@^$CARGO_ABOUT_VERSION is already installed." fi echo "Generating cargo licenses" - +set -x cargo about generate \ --fail \ + --frozen \ -c script/licenses/zed-licenses.toml \ - "$TEMPLATE_FILE" \ + $TEMPLATE_FILE \ | awk 'NR==1{print;next} NF{print | "sort"}' \ > "$OUTPUT_FILE" +set +x echo "generate-licenses-csv completed. See $OUTPUT_FILE" diff --git a/script/generate-terms-rtf b/script/generate-terms-rtf index 3c0ff85787fa08f767a3364af9e900f22160b652..ddfaee95a5a965f3b7db3a276827a4b488bc4c77 100755 --- a/script/generate-terms-rtf +++ b/script/generate-terms-rtf @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e diff --git a/script/get-crate-version b/script/get-crate-version index 0a35e4d49d7e9d8f3a0af17f32d3b9faadfb080c..d642eb08677fcf1bd844e2381d362548e6eee519 100755 --- a/script/get-crate-version +++ b/script/get-crate-version @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu diff --git a/script/get-released-version b/script/get-released-version index 357de7c240a9c0717ebfb109b2d2baef92995566..547026d003e9ec896254fa0ab02830735fc1c61e 100755 --- a/script/get-released-version +++ b/script/get-released-version @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash channel="$1" diff --git a/script/import-themes b/script/import-themes index 8f07df2ef3746b0e776b81382f4b068daf3a7d5a..14b844abc83249232bf80d441874300e0b0ae022 100755 --- a/script/import-themes +++ b/script/import-themes @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash cargo run -p theme_importer -- "$@" diff --git a/script/kube-shell b/script/kube-shell index 0ca77acdd0fb9751c313978b7ef0a3665a6be3a5..67f9fc2a6bff873103c40736b8bd943891358a2b 100755 --- a/script/kube-shell +++ b/script/kube-shell @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [[ $# -ne 1 ]]; then echo "Usage: $0 [production|staging|...]" diff --git a/script/lib/bump-version.sh b/script/lib/bump-version.sh index ce955369505dbfd1e9fdbacd64321c0c7bc6d405..5d83dd6f964ad6e9887d7d92fefd9dc43d7d6014 100755 --- a/script/lib/bump-version.sh +++ b/script/lib/bump-version.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu diff --git a/script/metal-debug b/script/metal-debug index de8476f3e37b37af0106813fddc1f2a58787e798..0dd32680631565559aaebb5abb27f36d23f1e455 100755 --- a/script/metal-debug +++ b/script/metal-debug @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash export GPUTOOLS_LOAD_GTMTLCAPTURE=1 export DYLD_LIBRARY_PATH="/usr/lib/system/introspection" diff --git a/script/new-crate b/script/new-crate index 099a9870b4ecfa82441edca4a6ed4afc724c2c89..44b5a6e5c8de2444354e6959e4539b3261547aea 100755 --- a/script/new-crate +++ b/script/new-crate @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Try to make sure we are in the zed repo root if [ ! -d "crates" ] || [ ! -d "script" ]; then diff --git a/script/prompts b/script/prompts index 52784c71dc71282c6e16a9efb7ba01df5fdbf449..5486600c1ee2283db25e2c84fec9a16ded017a2a 100755 --- a/script/prompts +++ b/script/prompts @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This script manages prompt overrides for the Zed editor. # diff --git a/script/run-local-minio b/script/run-local-minio index 292e676c9db6004c8378291eadf9a6b12843fcbb..3454eedae5387f04d7723237b2c669267152eb8e 100755 --- a/script/run-local-minio +++ b/script/run-local-minio @@ -1,4 +1,6 @@ -#!/bin/bash -e +#!/usr/bin/env bash + +set -e which minio > /dev/null || (echo "installing minio..."; brew install minio/stable/minio) mkdir -p .blob_store/the-extensions-bucket diff --git a/script/seed-db b/script/seed-db index 3b329c054cf4ed179aaecea7bfe4e3c47f971e1e..4ae8977d149c76fbca40744bdba57562db6d3dac 100755 --- a/script/seed-db +++ b/script/seed-db @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e cargo run -p collab migrate diff --git a/script/storybook b/script/storybook index 82694f228fab5cf8dd0574b6d6d53a7b165a16d2..20a81008d1c24abbe6ab092551e34d161cf5a4c2 100755 --- a/script/storybook +++ b/script/storybook @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash if [ -z "$1" ]; then cargo run -p storybook diff --git a/script/trigger-release b/script/trigger-release index 870cb6a9dc3acf4563081592961aa5f1410a8102..457a1f29f77fc23c903cf8fe77007c52c4192d84 100755 --- a/script/trigger-release +++ b/script/trigger-release @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -euo pipefail which gh >/dev/null || brew install gh diff --git a/script/what-is-deployed b/script/what-is-deployed index 6af82acd2d93c9de83a7dbee048cf5c4ce242f23..c7c4b3ad6352449a1a31a66676945c46f90b54a2 100755 --- a/script/what-is-deployed +++ b/script/what-is-deployed @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -eu source script/lib/deploy-helpers.sh diff --git a/shell.nix b/shell.nix index d7c46b9ef8850d565bac8598b9fa4128a3f55154..d1783071f97941c949e5bf6b7ccc3214f6523ab4 100644 --- a/shell.nix +++ b/shell.nix @@ -1,14 +1,11 @@ -( - import - ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - {src = ./.;} -) -.shellNix +(import ( + let + lock = builtins.fromJSON (builtins.readFile ./flake.lock); + in + fetchTarball { + url = + lock.nodes.flake-compat.locked.url + or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } +) { src = ./.; }).shellNix