mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-23 18:32:17 +00:00
nix: Return to building with crane (#21292)
This removes .envrc, putting it into gitignore as well as building with crane, as it does not require an up to date hash for a FOD. Release Notes: - N/A cc @mrnugget @jaredramirez
This commit is contained in:
parent
73f546ea5f
commit
94faf9dd56
5 changed files with 193 additions and 182 deletions
2
.envrc
2
.envrc
|
@ -1,2 +0,0 @@
|
||||||
watch_file nix/shell.nix
|
|
||||||
use flake
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,5 @@
|
||||||
/.direnv
|
/.direnv
|
||||||
|
.envrc
|
||||||
.idea
|
.idea
|
||||||
**/target
|
**/target
|
||||||
**/cargo-target
|
**/cargo-target
|
||||||
|
|
16
flake.lock
16
flake.lock
|
@ -1,5 +1,20 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"crane": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1732407143,
|
||||||
|
"narHash": "sha256-qJOGDT6PACoX+GbNH2PPx2ievlmtT1NVeTB80EkRLys=",
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"rev": "f2b4b472983817021d9ffb60838b2b36b9376b20",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "ipetkov",
|
||||||
|
"repo": "crane",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"flake-compat": {
|
"flake-compat": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1696426674,
|
"lastModified": 1696426674,
|
||||||
|
@ -33,6 +48,7 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"crane": "crane",
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
|
|
14
flake.nix
14
flake.nix
|
@ -7,11 +7,17 @@
|
||||||
url = "github:oxalica/rust-overlay";
|
url = "github:oxalica/rust-overlay";
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
crane.url = "github:ipetkov/crane";
|
||||||
flake-compat.url = "github:edolstra/flake-compat";
|
flake-compat.url = "github:edolstra/flake-compat";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
{ nixpkgs, rust-overlay, ... }:
|
{
|
||||||
|
nixpkgs,
|
||||||
|
rust-overlay,
|
||||||
|
crane,
|
||||||
|
...
|
||||||
|
}:
|
||||||
let
|
let
|
||||||
systems = [
|
systems = [
|
||||||
"x86_64-linux"
|
"x86_64-linux"
|
||||||
|
@ -27,10 +33,8 @@
|
||||||
};
|
};
|
||||||
zed-editor = final: prev: {
|
zed-editor = final: prev: {
|
||||||
zed-editor = final.callPackage ./nix/build.nix {
|
zed-editor = final.callPackage ./nix/build.nix {
|
||||||
rustPlatform = final.makeRustPlatform {
|
crane = crane.mkLib final;
|
||||||
cargo = final.rustToolchain;
|
rustToolchain = final.rustToolchain;
|
||||||
rustc = final.rustToolchain;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
342
nix/build.nix
342
nix/build.nix
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
rustPlatform,
|
crane,
|
||||||
|
rustToolchain,
|
||||||
fetchpatch,
|
fetchpatch,
|
||||||
clang,
|
clang,
|
||||||
cmake,
|
cmake,
|
||||||
|
@ -26,7 +27,6 @@
|
||||||
vulkan-loader,
|
vulkan-loader,
|
||||||
envsubst,
|
envsubst,
|
||||||
cargo-about,
|
cargo-about,
|
||||||
versionCheckHook,
|
|
||||||
cargo-bundle,
|
cargo-bundle,
|
||||||
git,
|
git,
|
||||||
apple-sdk_15,
|
apple-sdk_15,
|
||||||
|
@ -50,207 +50,199 @@ let
|
||||||
in
|
in
|
||||||
!(
|
!(
|
||||||
inRootDir
|
inRootDir
|
||||||
&& (
|
&& (baseName == "docs" || baseName == ".github" || baseName == ".git" || baseName == "target")
|
||||||
baseName == "docs"
|
|
||||||
|| baseName == ".github"
|
|
||||||
|| baseName == "script"
|
|
||||||
|| baseName == ".git"
|
|
||||||
|| baseName == "target"
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
in
|
craneLib = crane.overrideToolchain rustToolchain;
|
||||||
rustPlatform.buildRustPackage rec {
|
commonSrc = lib.cleanSourceWith {
|
||||||
pname = "zed-editor";
|
|
||||||
version = "nightly";
|
|
||||||
|
|
||||||
src = lib.cleanSourceWith {
|
|
||||||
src = nix-gitignore.gitignoreSource [ ] ../.;
|
src = nix-gitignore.gitignoreSource [ ] ../.;
|
||||||
filter = includeFilter;
|
filter = includeFilter;
|
||||||
name = "source";
|
name = "source";
|
||||||
};
|
};
|
||||||
|
commonArgs = rec {
|
||||||
|
pname = "zed-editor";
|
||||||
|
version = "nightly";
|
||||||
|
|
||||||
patches =
|
src = commonSrc;
|
||||||
[
|
|
||||||
# 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=";
|
|
||||||
})
|
|
||||||
];
|
|
||||||
|
|
||||||
useFetchCargoVendor = true;
|
nativeBuildInputs =
|
||||||
cargoHash = "sha256-KURM1W9UP65BU9gbvEBgQj3jwSYfQT7X18gcSmOMguI=";
|
[
|
||||||
|
clang
|
||||||
|
cmake
|
||||||
|
copyDesktopItems
|
||||||
|
curl
|
||||||
|
perl
|
||||||
|
pkg-config
|
||||||
|
protobuf
|
||||||
|
cargo-about
|
||||||
|
]
|
||||||
|
++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ]
|
||||||
|
++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ];
|
||||||
|
|
||||||
nativeBuildInputs =
|
buildInputs =
|
||||||
[
|
[
|
||||||
clang
|
curl
|
||||||
cmake
|
fontconfig
|
||||||
copyDesktopItems
|
freetype
|
||||||
curl
|
libgit2
|
||||||
perl
|
openssl
|
||||||
pkg-config
|
sqlite
|
||||||
protobuf
|
zlib
|
||||||
rustPlatform.bindgenHook
|
zstd
|
||||||
cargo-about
|
]
|
||||||
]
|
++ lib.optionals stdenv.hostPlatform.isLinux [
|
||||||
++ lib.optionals stdenv.hostPlatform.isLinux [ makeWrapper ]
|
alsa-lib
|
||||||
++ lib.optionals stdenv.hostPlatform.isDarwin [ cargo-bundle ];
|
libxkbcommon
|
||||||
|
wayland
|
||||||
dontUseCmakeConfigure = true;
|
xorg.libxcb
|
||||||
|
]
|
||||||
buildInputs =
|
++ lib.optionals stdenv.hostPlatform.isDarwin [
|
||||||
[
|
apple-sdk_15
|
||||||
curl
|
(darwinMinVersionHook "10.15")
|
||||||
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")
|
|
||||||
];
|
|
||||||
|
|
||||||
cargoBuildFlags = [
|
|
||||||
"--package=zed"
|
|
||||||
"--package=cli"
|
|
||||||
];
|
|
||||||
|
|
||||||
buildFeatures = lib.optionals stdenv.hostPlatform.isDarwin [ "gpui/runtime_shaders" ];
|
|
||||||
|
|
||||||
env = {
|
|
||||||
ZSTD_SYS_USE_PKG_CONFIG = true;
|
|
||||||
FONTCONFIG_FILE = makeFontsConf {
|
|
||||||
fontDirectories = [
|
|
||||||
"${src}/assets/fonts/plex-mono"
|
|
||||||
"${src}/assets/fonts/plex-sans"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
env = {
|
||||||
|
ZSTD_SYS_USE_PKG_CONFIG = true;
|
||||||
|
FONTCONFIG_FILE = makeFontsConf {
|
||||||
|
fontDirectories = [
|
||||||
|
"${src}/assets/fonts/plex-mono"
|
||||||
|
"${src}/assets/fonts/plex-sans"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled.";
|
||||||
|
RELEASE_VERSION = version;
|
||||||
};
|
};
|
||||||
ZED_UPDATE_EXPLANATION = "Zed has been installed using Nix. Auto-updates have thus been disabled.";
|
|
||||||
RELEASE_VERSION = version;
|
|
||||||
};
|
};
|
||||||
|
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
|
||||||
|
in
|
||||||
|
craneLib.buildPackage (
|
||||||
|
commonArgs
|
||||||
|
// rec {
|
||||||
|
inherit cargoArtifacts;
|
||||||
|
|
||||||
RUSTFLAGS = if withGLES then "--cfg gles" else "";
|
patches =
|
||||||
gpu-lib = if withGLES then libglvnd else vulkan-loader;
|
[
|
||||||
|
# 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=";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
preBuild = ''
|
cargoExtraArgs = "--package=zed --package=cli --features=gpui/runtime_shaders";
|
||||||
bash script/generate-licenses
|
|
||||||
'';
|
|
||||||
|
|
||||||
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
|
dontUseCmakeConfigure = true;
|
||||||
patchelf --add-rpath ${gpu-lib}/lib $out/libexec/*
|
preBuild = ''
|
||||||
patchelf --add-rpath ${wayland}/lib $out/libexec/*
|
bash script/generate-licenses
|
||||||
wrapProgram $out/libexec/zed-editor --suffix PATH : ${lib.makeBinPath [ nodejs_22 ]}
|
'';
|
||||||
'';
|
|
||||||
|
|
||||||
preCheck = ''
|
postFixup = lib.optionalString stdenv.hostPlatform.isLinux ''
|
||||||
export HOME=$(mktemp -d);
|
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 ]}
|
||||||
|
'';
|
||||||
|
|
||||||
checkFlags =
|
RUSTFLAGS = if withGLES then "--cfg gles" else "";
|
||||||
[
|
gpu-lib = if withGLES then libglvnd else vulkan-loader;
|
||||||
# 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"
|
|
||||||
];
|
|
||||||
|
|
||||||
installPhase =
|
preCheck = ''
|
||||||
if stdenv.hostPlatform.isDarwin then
|
export HOME=$(mktemp -d);
|
||||||
''
|
'';
|
||||||
runHook preInstall
|
|
||||||
|
|
||||||
# cargo-bundle expects the binary in target/release
|
cargoTestExtraArgs =
|
||||||
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed target/release/zed
|
"-- "
|
||||||
|
+ 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"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
pushd crates/zed
|
installPhase =
|
||||||
|
if stdenv.hostPlatform.isDarwin then
|
||||||
|
''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
# Note that this is GNU sed, while Zed's bundle-mac uses BSD sed
|
# cargo-bundle expects the binary in target/release
|
||||||
sed -i "s/package.metadata.bundle-stable/package.metadata.bundle/" Cargo.toml
|
mv target/release/zed target/release/zed
|
||||||
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
|
pushd crates/zed
|
||||||
# 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 "</dict>\n</plist>\n" >> Info.plist
|
|
||||||
mv Info.plist $app_path/Contents/Info.plist
|
|
||||||
|
|
||||||
popd
|
# 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
|
||||||
|
export CARGO_BUNDLE_SKIP_BUILD=true
|
||||||
|
app_path=$(cargo bundle --release | xargs)
|
||||||
|
|
||||||
mkdir -p $out/Applications $out/bin
|
# We're not using the fork of cargo-bundle, so we must manually append plist extensions
|
||||||
# Zed expects git next to its own binary
|
# Remove closing tags from Info.plist (last two lines)
|
||||||
ln -s ${git}/bin/git $app_path/Contents/MacOS/git
|
head -n -2 $app_path/Contents/Info.plist > Info.plist
|
||||||
mv target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $app_path/Contents/MacOS/cli
|
# Append extensions
|
||||||
mv $app_path $out/Applications/
|
cat resources/info/*.plist >> Info.plist
|
||||||
|
# Add closing tags
|
||||||
|
printf "</dict>\n</plist>\n" >> Info.plist
|
||||||
|
mv Info.plist $app_path/Contents/Info.plist
|
||||||
|
|
||||||
# Physical location of the CLI must be inside the app bundle as this is used
|
popd
|
||||||
# to determine which app to start
|
|
||||||
ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zed
|
|
||||||
|
|
||||||
runHook postInstall
|
mkdir -p $out/Applications $out/bin
|
||||||
''
|
# Zed expects git next to its own binary
|
||||||
else
|
ln -s ${git}/bin/git $app_path/Contents/MacOS/git
|
||||||
''
|
mv target/release/cli $app_path/Contents/MacOS/cli
|
||||||
runHook preInstall
|
mv $app_path $out/Applications/
|
||||||
|
|
||||||
mkdir -p $out/bin $out/libexec
|
# Physical location of the CLI must be inside the app bundle as this is used
|
||||||
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/zed $out/libexec/zed-editor
|
# to determine which app to start
|
||||||
cp target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/cli $out/bin/zed
|
ln -s $out/Applications/Zed.app/Contents/MacOS/cli $out/bin/zed
|
||||||
|
|
||||||
install -D ${src}/crates/zed/resources/app-icon@2x.png $out/share/icons/hicolor/1024x1024@2x/apps/zed.png
|
runHook postInstall
|
||||||
install -D ${src}/crates/zed/resources/app-icon.png $out/share/icons/hicolor/512x512/apps/zed.png
|
''
|
||||||
|
else
|
||||||
|
''
|
||||||
|
runHook preInstall
|
||||||
|
|
||||||
# extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst)
|
mkdir -p $out/bin $out/libexec
|
||||||
# and https://github.com/zed-industries/zed/blob/v0.141.2/script/install.sh (final desktop file name)
|
cp target/release/zed $out/libexec/zed-editor
|
||||||
(
|
cp target/release/cli $out/bin/zed
|
||||||
export DO_STARTUP_NOTIFY="true"
|
|
||||||
export APP_CLI="zed"
|
|
||||||
export APP_ICON="zed"
|
|
||||||
export APP_NAME="Zed"
|
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
runHook postInstall
|
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
|
||||||
|
|
||||||
nativeInstallCheckInputs = [
|
# extracted from https://github.com/zed-industries/zed/blob/v0.141.2/script/bundle-linux (envsubst)
|
||||||
versionCheckHook
|
# and https://github.com/zed-industries/zed/blob/v0.141.2/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_ARGS="%U"
|
||||||
|
mkdir -p "$out/share/applications"
|
||||||
|
${lib.getExe envsubst} < "crates/zed/resources/zed.desktop.in" > "$out/share/applications/dev.zed.Zed.desktop"
|
||||||
|
)
|
||||||
|
|
||||||
meta = {
|
runHook postInstall
|
||||||
description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";
|
'';
|
||||||
homepage = "https://zed.dev";
|
|
||||||
changelog = "https://zed.dev/releases/preview";
|
meta = {
|
||||||
license = lib.licenses.gpl3Only;
|
description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";
|
||||||
mainProgram = "zed";
|
homepage = "https://zed.dev";
|
||||||
platforms = lib.platforms.linux ++ lib.platforms.darwin;
|
changelog = "https://zed.dev/releases/preview";
|
||||||
};
|
license = lib.licenses.gpl3Only;
|
||||||
}
|
mainProgram = "zed";
|
||||||
|
platforms = lib.platforms.linux ++ lib.platforms.darwin;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue