From 5e1c6908887e5172f4cf3724ee2d058fa48f30aa Mon Sep 17 00:00:00 2001 From: killian <26600206+xtrm-en@users.noreply.github.com> Date: Tue, 9 Jul 2024 09:21:42 +0200 Subject: [PATCH] Add Nix/NixOS dev-shell (#13407) This PR adds a Nix/NixOS development-shell (`shell.nix`), which is based on the upstream [nixpkgs](https://github.com/NixOS/nixpkgs/blob/c5d4d458115263ec3ee0efd974e6aeb2f787a0ed/pkgs/by-name/ze/zed-editor/package.nix), as well as its corresponding `flake.nix` file. To use it, run either the `nix-shell` command (uses the `shell.nix` file), or the newer but experimental `nix develop` command (uses `flake.nix`) ~~This has not been tested on macOS, tho preliminary code is there to try and support it, feel free to report any issues.~~ Zed unfortunately doesn't build on nix-darwin (see https://github.com/NixOS/nixpkgs/issues/320084), so this PR doesn't aim to add darwin support. --- Release Notes: - N/A --------- Signed-off-by: xtrm Co-authored-by: Niklas Korz --- .gitignore | 1 + flake.lock | 27 ++++++++++++++++++++++++++ flake.nix | 31 ++++++++++++++++++++++++++++++ shell.nix | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index e0dfc13d37..de15d0abc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/.direnv .idea **/target **/cargo-target diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..ca353b3445 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1719690277, + "narHash": "sha256-0xSej1g7eP2kaUF+JQp8jdyNmpmCJKRpO12mKl/36Kc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2741b4b489b55df32afac57bc4bfd220e8bf617e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..f24dd9cf30 --- /dev/null +++ b/flake.nix @@ -0,0 +1,31 @@ +{ + description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable"; + }; + + outputs = + { self, nixpkgs }: + let + inherit (self) outputs; + systems = [ + "aarch64-linux" + "x86_64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + forAllSystems = nixpkgs.lib.genAttrs systems; + in + { + devShells = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + default = import ./shell.nix { inherit pkgs; }; + } + ); + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000000..be2dcb2f88 --- /dev/null +++ b/shell.nix @@ -0,0 +1,56 @@ +{ + pkgs ? import { }, +}: + +let + stdenv = pkgs.stdenvAdapters.useMoldLinker pkgs.llvmPackages_18.stdenv; +in +if pkgs.stdenv.isDarwin then + # See https://github.com/NixOS/nixpkgs/issues/320084 + throw "zed: nix dev-shell isn't supported on darwin yet." +else + (pkgs.mkShell.override { inherit stdenv; }) rec { + nativeBuildInputs = with pkgs; [ + copyDesktopItems + curl + perl + pkg-config + protobuf + rustPlatform.bindgenHook + ]; + + buildInputs = with pkgs; [ + curl + fontconfig + freetype + libgit2 + openssl + sqlite + zlib + zstd + + alsa-lib + libxkbcommon + wayland + xorg.libxcb + ]; + + env = { + LD_LIBRARY_PATH = + with pkgs; + lib.makeLibraryPath ( + buildInputs + ++ [ + stdenv.cc.cc.lib + vulkan-loader + ] + ); + ZSTD_SYS_USE_PKG_CONFIG = true; + FONTCONFIG_FILE = pkgs.makeFontsConf { + fontDirectories = [ + "assets/fonts/zed-mono" + "assets/fonts/zed-sans" + ]; + }; + }; + }