
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](92d11f06d5/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 <rrbutani@users.noreply.github.com>
Co-authored-by: Rahul Butani <rr.butani@gmail.com>
289 lines
8.7 KiB
Nix
289 lines
8.7 KiB
Nix
{
|
|
lib,
|
|
crane,
|
|
rustToolchain,
|
|
rustPlatform,
|
|
cmake,
|
|
copyDesktopItems,
|
|
fetchFromGitHub,
|
|
curl,
|
|
clang,
|
|
perl,
|
|
pkg-config,
|
|
protobuf,
|
|
fontconfig,
|
|
freetype,
|
|
libgit2,
|
|
openssl,
|
|
sqlite,
|
|
zlib,
|
|
zstd,
|
|
alsa-lib,
|
|
libxkbcommon,
|
|
wayland,
|
|
libglvnd,
|
|
xorg,
|
|
stdenv,
|
|
makeFontsConf,
|
|
vulkan-loader,
|
|
envsubst,
|
|
cargo-about,
|
|
cargo-bundle,
|
|
git,
|
|
livekit-libwebrtc,
|
|
apple-sdk_15,
|
|
darwin,
|
|
darwinMinVersionHook,
|
|
makeWrapper,
|
|
nodejs_22,
|
|
|
|
withGLES ? false,
|
|
}:
|
|
|
|
assert withGLES -> stdenv.hostPlatform.isLinux;
|
|
|
|
let
|
|
mkIncludeFilter =
|
|
root': path: type:
|
|
let
|
|
# 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
|
|
builtins.elem firstComp topLevelIncludes;
|
|
|
|
craneLib = crane.overrideToolchain rustToolchain;
|
|
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=";
|
|
};
|
|
}))
|
|
];
|
|
|
|
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;
|
|
};
|
|
};
|
|
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 (
|
|
lib.recursiveUpdate commonArgs {
|
|
inherit cargoArtifacts;
|
|
|
|
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;
|
|
|
|
# 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
|
|
'';
|
|
|
|
# TODO: try craneLib.cargoNextest separate output and doCheck=false
|
|
# do we even care about running our test suite in the nix sandbox?
|
|
|
|
# see crane bug: https://github.com/ipetkov/crane/issues/808
|
|
doNotRemoveReferencesToRustToolchain = true;
|
|
doNotRemoveReferencesToVendorDir = true;
|
|
|
|
installPhase =
|
|
if stdenv.hostPlatform.isDarwin then
|
|
''
|
|
runHook preInstall
|
|
|
|
pushd crates/zed
|
|
sed -i "s/package.metadata.bundle-nightly/package.metadata.bundle/" Cargo.toml
|
|
export CARGO_BUNDLE_SKIP_BUILD=true
|
|
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/
|
|
|
|
# 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 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
|
|
|
|
mkdir -p $out/bin $out/libexec
|
|
cp target/release/zed $out/libexec/zed-editor
|
|
cp target/release/cli $out/bin/zed
|
|
|
|
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 ../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 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-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";
|
|
changelog = "https://zed.dev/releases/preview";
|
|
license = lib.licenses.gpl3Only;
|
|
mainProgram = "zed";
|
|
platforms = lib.platforms.linux ++ lib.platforms.darwin;
|
|
};
|
|
}
|
|
)
|