Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
nix: Use flake-parts, partitions, and treefmt-nix (#45321)
Diego Perezcfbf6ebe96c0
diff --git a/crates/codestral/src/codestral.rs b/crates/codestral/src/codestral.rsindex 8c1b0e65c07..327a8b06c1b 100644--- a/crates/codestral/src/codestral.rs+++ b/crates/codestral/src/codestral.rs@@ -6,7 +6,7 @@ use gpui::{App, Context, Entity, Task};use http_client::HttpClient;use icons::IconName;use language::{- language_settings::all_language_settings, Anchor, Buffer, BufferSnapshot, EditPreview, ToPoint,+ Anchor, Buffer, BufferSnapshot, EditPreview, ToPoint, language_settings::all_language_settings,};use language_models::MistralLanguageModelProvider;use mistral::CODESTRAL_API_URL;diff --git a/crates/collab/src/completion.rs b/crates/collab/src/completion.rsindex dd1f4b3be64..634355b4674 100644--- a/crates/collab/src/completion.rs+++ b/crates/collab/src/completion.rs@@ -1,2 +1,2 @@-use anyhow::{anyhow, Result};+use anyhow::{Result, anyhow};use rpc::proto;diff --git a/crates/gpui/src/platform/mac/status_item.rs b/crates/gpui/src/platform/mac/status_item.rsindex 21cc86090c8..a52e6b4ce44 100644--- a/crates/gpui/src/platform/mac/status_item.rs+++ b/crates/gpui/src/platform/mac/status_item.rs@@ -1,18 +1,17 @@use crate::{+ Scene,geometry::{rect::RectF,- vector::{vec2f, Vector2F},+ vector::{Vector2F, vec2f},},platform::{- self,+ self, Event, FontSystem, WindowBounds,mac::{platform::NSViewLayerContentsRedrawDuringViewResize, renderer::Renderer},- Event, FontSystem, WindowBounds,},- Scene,};use cocoa::{appkit::{NSScreen, NSSquareStatusItemLength, NSStatusBar, NSStatusItem, NSView, NSWindow},- base::{id, nil, YES},+ base::{YES, id, nil},foundation::{NSPoint, NSRect, NSSize},};use ctor::ctor;diff --git a/crates/ui/src/components/ai/copilot_configuration_callout.rs b/crates/ui/src/components/ai/copilot_configuration_callout.rsindex e69de29bb2d..8b137891791 100644--- a/crates/ui/src/components/ai/copilot_configuration_callout.rs+++ b/crates/ui/src/components/ai/copilot_configuration_callout.rs@@ -0,0 +1 @@+diff --git a/default.nix b/default.nixindex 1d976a35762..b1565619300 100644--- a/default.nix+++ b/default.nix@@ -1,11 +1,10 @@(import (let- lock = builtins.fromJSON (builtins.readFile ./flake.lock);+ rev = "v1.1.0";+ sha256 = "sha256:19d2z6xsvpxm184m41qrpi1bplilwipgnzv9jy17fgw421785q1m";infetchTarball {- 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;+ inherit sha256;+ url = "https://github.com/NixOS/flake-compat/archive/${rev}.tar.gz";}) { src = ./.; }).defaultNixdiff --git a/flake.lock b/flake.lockindex 5bfb03ffd1a..ce974047d69 100644--- a/flake.lock+++ b/flake.lock@@ -2,11 +2,11 @@"nodes": {"crane": {"locked": {- "lastModified": 1768873933,- "narHash": "sha256-CfyzdaeLNGkyAHp3kT5vjvXhA1pVVK7nyDziYxCPsNk=",+ "lastModified": 1769737823,+ "narHash": "sha256-DrBaNpZ+sJ4stXm+0nBX7zqZT9t9P22zbk6m5YhQxS4=","owner": "ipetkov","repo": "crane",- "rev": "0bda7e7d005ccb5522a76d11ccfbf562b71953ca",+ "rev": "b2f45c3830aa96b7456a4c4bc327d04d7a43e1ba","type": "github"},"original": {@@ -15,38 +15,59 @@"type": "github"}},- "flake-compat": {+ "flake-parts": {+ "inputs": {+ "nixpkgs-lib": "nixpkgs-lib"+ },"locked": {- "lastModified": 1767039857,- "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=",- "owner": "edolstra",- "repo": "flake-compat",- "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",+ "lastModified": 1769996383,+ "narHash": "sha256-AnYjnFWgS49RlqX7LrC4uA+sCCDBj0Ry/WOJ5XWAsa0=",+ "owner": "hercules-ci",+ "repo": "flake-parts",+ "rev": "57928607ea566b5db3ad13af0e57e921e6b12381","type": "github"},"original": {- "owner": "edolstra",- "repo": "flake-compat",+ "owner": "hercules-ci",+ "repo": "flake-parts","type": "github"}},"nixpkgs": {"locked": {- "lastModified": 1768875095,- "narHash": "sha256-XH6awru9NnBc/m+2YhRNT8r1PAKEiPGF3gs//F3ods0=",- "rev": "ed142ab1b3a092c4d149245d0c4126a5d7ea00b0",- "type": "tarball",- "url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.05pre930822.ed142ab1b3a0/nixexprs.tar.xz"+ "lastModified": 1769789167,+ "narHash": "sha256-kKB3bqYJU5nzYeIROI82Ef9VtTbu4uA3YydSk/Bioa8=",+ "owner": "NixOS",+ "repo": "nixpkgs",+ "rev": "62c8382960464ceb98ea593cb8321a2cf8f9e3e5",+ "type": "github"},"original": {- "type": "tarball",- "url": "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz"+ "owner": "NixOS",+ "ref": "nixos-unstable",+ "repo": "nixpkgs",+ "type": "github"+ }+ },+ "nixpkgs-lib": {+ "locked": {+ "lastModified": 1769909678,+ "narHash": "sha256-cBEymOf4/o3FD5AZnzC3J9hLbiZ+QDT/KDuyHXVJOpM=",+ "owner": "nix-community",+ "repo": "nixpkgs.lib",+ "rev": "72716169fe93074c333e8d0173151350670b824c",+ "type": "github"+ },+ "original": {+ "owner": "nix-community",+ "repo": "nixpkgs.lib",+ "type": "github"}},"root": {"inputs": {"crane": "crane",- "flake-compat": "flake-compat",+ "flake-parts": "flake-parts","nixpkgs": "nixpkgs","rust-overlay": "rust-overlay"}@@ -58,11 +79,11 @@]},"locked": {- "lastModified": 1769136478,- "narHash": "sha256-8UNd5lmGf8phCr/aKxagJ4kNsF0pCHLish2G4ZKCFFY=",+ "lastModified": 1770001842,+ "narHash": "sha256-ZAyTeILfdWwDp1nuF0RK3McBduMi49qnJvrS+3Ezpac=","owner": "oxalica","repo": "rust-overlay",- "rev": "470ee44393bb19887056b557ea2c03fc5230bd5a",+ "rev": "5018343419ea808f8a413241381976b7e60951f2","type": "github"},"original": {diff --git a/flake.nix b/flake.nixindex 744ca708a3a..e671d8ff7eb 100644--- a/flake.nix+++ b/flake.nix@@ -2,23 +2,18 @@description = "High-performance, multiplayer code editor from the creators of Atom and Tree-sitter";inputs = {- nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz";+ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";+ flake-parts.url = "github:hercules-ci/flake-parts";+ crane.url = "github:ipetkov/crane";rust-overlay = {url = "github:oxalica/rust-overlay";inputs.nixpkgs.follows = "nixpkgs";};- crane.url = "github:ipetkov/crane";- flake-compat.url = "github:edolstra/flake-compat";};outputs =- {- nixpkgs,- rust-overlay,- crane,- ...- }:- let+ inputs@{ flake-parts, ... }:+ flake-parts.lib.mkFlake { inherit inputs; } {systems = ["x86_64-linux""x86_64-darwin"@@ -26,31 +21,11 @@"aarch64-darwin"];- forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});- mkZed =- pkgs:- let- rustBin = rust-overlay.lib.mkRustBin { } pkgs;- in- pkgs.callPackage ./nix/build.nix {- crane = crane.mkLib pkgs;- rustToolchain = rustBin.fromRustupToolchainFile ./rust-toolchain.toml;- };- in- {- packages = forAllSystems (pkgs: rec {- default = mkZed pkgs;- debug = default.override { profile = "dev"; };- });- devShells = forAllSystems (pkgs: {- default = pkgs.callPackage ./nix/shell.nix {- zed-editor = mkZed pkgs;- };- });- formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);- overlays.default = final: _: {- zed-editor = mkZed final;- };+ imports = [+ ./nix/modules/overlays.nix+ ./nix/modules/packages.nix+ ./nix/modules/partitions.nix+ ];};nixConfig = {diff --git a/nix/dev/flake.lock b/nix/dev/flake.locknew file mode 100644index 00000000000..bdb585dde4c--- /dev/null+++ b/nix/dev/flake.lock@@ -0,0 +1,45 @@+{+ "nodes": {+ "nixpkgs": {+ "locked": {+ "lastModified": 1761236834,+ "narHash": "sha256-+pthv6hrL5VLW2UqPdISGuLiUZ6SnAXdd2DdUE+fV2Q=",+ "owner": "nixos",+ "repo": "nixpkgs",+ "rev": "d5faa84122bc0a1fd5d378492efce4e289f8eac1",+ "type": "github"+ },+ "original": {+ "owner": "nixos",+ "ref": "nixpkgs-unstable",+ "repo": "nixpkgs",+ "type": "github"+ }+ },+ "root": {+ "inputs": {+ "treefmt-nix": "treefmt-nix"+ }+ },+ "treefmt-nix": {+ "inputs": {+ "nixpkgs": "nixpkgs"+ },+ "locked": {+ "lastModified": 1766000401,+ "narHash": "sha256-+cqN4PJz9y0JQXfAK5J1drd0U05D5fcAGhzhfVrDlsI=",+ "owner": "numtide",+ "repo": "treefmt-nix",+ "rev": "42d96e75aa56a3f70cab7e7dc4a32868db28e8fd",+ "type": "github"+ },+ "original": {+ "owner": "numtide",+ "repo": "treefmt-nix",+ "type": "github"+ }+ }+ },+ "root": "root",+ "version": 7+}diff --git a/nix/dev/flake.nix b/nix/dev/flake.nixnew file mode 100644index 00000000000..b508417b62c--- /dev/null+++ b/nix/dev/flake.nix@@ -0,0 +1,10 @@+{+ description = "Private inputs for development purposes. These are used by the top level flake in the `dev` partition, but do not appear in consumers' lock files.";++ inputs = {+ treefmt-nix.url = "github:numtide/treefmt-nix";+ };++ # This flake is only used for its inputs.+ outputs = { ... }: { };+}diff --git a/nix/modules/devshells.nix b/nix/modules/devshells.nixnew file mode 100644index 00000000000..7b89aceec28--- /dev/null+++ b/nix/modules/devshells.nix@@ -0,0 +1,60 @@+{ inputs, ... }:+{+ perSystem =+ { pkgs, ... }:+ let+ # NOTE: Duplicated because this is in a separate flake-parts partition+ # than ./packages.nix+ mkZed = import ../toolchain.nix { inherit inputs; };+ zed-editor = mkZed pkgs;++ rustBin = inputs.rust-overlay.lib.mkRustBin { } pkgs;+ rustToolchain = rustBin.fromRustupToolchainFile ../../rust-toolchain.toml;++ baseEnv =+ (zed-editor.overrideAttrs (attrs: {+ passthru.env = attrs.env;+ })).env; # exfil `env`; it's not in drvAttrs+ in+ {+ devShells.default = (pkgs.mkShell.override { inherit (zed-editor) stdenv; }) {+ name = "zed-editor-dev";+ inputsFrom = [ zed-editor ];++ packages = with pkgs; [+ rustToolchain # cargo, rustc, and rust-toolchain.toml components included+ cargo-nextest+ cargo-hakari+ cargo-machete+ cargo-zigbuild+ # TODO: package protobuf-language-server for editing zed.proto+ # TODO: add other tools used in our scripts++ # `build.nix` adds this to the `zed-editor` wrapper (see `postFixup`)+ # we'll just put it on `$PATH`:+ nodejs_22+ zig+ ];++ env =+ (removeAttrs baseEnv [+ "LK_CUSTOM_WEBRTC" # download the staticlib during the build as usual+ "ZED_UPDATE_EXPLANATION" # allow auto-updates+ "CARGO_PROFILE" # let you specify the profile+ "TARGET_DIR"+ ])+ // {+ # note: different than `$FONTCONFIG_FILE` in `build.nix` – this refers to relative paths+ # outside the nix store instead of to `$src`+ FONTCONFIG_FILE = pkgs.makeFontsConf {+ fontDirectories = [+ "./assets/fonts/lilex"+ "./assets/fonts/ibm-plex-sans"+ ];+ };+ PROTOC = "${pkgs.protobuf}/bin/protoc";+ ZED_ZSTD_MUSL_LIB = "${pkgs.pkgsCross.musl64.pkgsStatic.zstd.out}/lib";+ };+ };+ };+}diff --git a/nix/modules/overlays.nix b/nix/modules/overlays.nixnew file mode 100644index 00000000000..f0fd39db318--- /dev/null+++ b/nix/modules/overlays.nix@@ -0,0 +1,11 @@+{ inputs, ... }:+{+ flake.overlays.default =+ final: _:+ let+ mkZed = import ../toolchain.nix { inherit inputs; };+ in+ {+ zed-editor = mkZed final;+ };+}diff --git a/nix/modules/packages.nix b/nix/modules/packages.nixnew file mode 100644index 00000000000..1d2228c8cfa--- /dev/null+++ b/nix/modules/packages.nix@@ -0,0 +1,15 @@+{ inputs, ... }:+{+ perSystem =+ { pkgs, ... }:+ let+ mkZed = import ../toolchain.nix { inherit inputs; };+ zed-editor = mkZed pkgs;+ in+ {+ packages = {+ default = zed-editor;+ debug = zed-editor.override { profile = "dev"; };+ };+ };+}diff --git a/nix/modules/partitions.nix b/nix/modules/partitions.nixnew file mode 100644index 00000000000..d491514b4cf--- /dev/null+++ b/nix/modules/partitions.nix@@ -0,0 +1,25 @@+{ inputs, ... }:+{+ imports = [+ inputs.flake-parts.flakeModules.partitions+ ];++ partitionedAttrs = {+ devShells = "dev";+ formatter = "dev";+ checks = "dev";+ };++ partitions.dev = {+ extraInputsFlake = ../dev;+ module =+ { inputs, ... }:+ {+ imports = [+ inputs.treefmt-nix.flakeModule+ ./devshells.nix+ ./treefmt.nix+ ];+ };+ };+}diff --git a/nix/modules/treefmt.nix b/nix/modules/treefmt.nixnew file mode 100644index 00000000000..9024315035b--- /dev/null+++ b/nix/modules/treefmt.nix@@ -0,0 +1,10 @@+{+ perSystem =+ { pkgs, ... }:+ {+ treefmt = {+ programs.nixfmt.enable = true;+ programs.rustfmt.enable = true;+ };+ };+}diff --git a/nix/shell.nix b/nix/shell.nixdeleted file mode 100644index 6956de8e8ab..00000000000--- a/nix/shell.nix+++ /dev/null@@ -1,63 +0,0 @@-{- mkShell,- makeFontsConf,- pkgsCross,-- zed-editor,-- rust-analyzer,- rustup,- cargo-nextest,- cargo-hakari,- cargo-machete,- cargo-zigbuild,- nixfmt-rfc-style,- protobuf,- nodejs_22,- zig,-}:-(mkShell.override { inherit (zed-editor) stdenv; }) {- inputsFrom = [ zed-editor ];- packages = [- rust-analyzer- rustup- cargo-nextest- cargo-hakari- cargo-machete- cargo-zigbuild- nixfmt-rfc-style- # TODO: package protobuf-language-server for editing zed.proto- # TODO: add other tools used in our scripts-- # `build.nix` adds this to the `zed-editor` wrapper (see `postFixup`)- # we'll just put it on `$PATH`:- nodejs_22- zig- ];-- env =- let- baseEnvs =- (zed-editor.overrideAttrs (attrs: {- passthru = { inherit (attrs) env; };- })).env; # exfil `env`; it's not in drvAttrs- in- (removeAttrs baseEnvs [- "LK_CUSTOM_WEBRTC" # download the staticlib during the build as usual- "ZED_UPDATE_EXPLANATION" # allow auto-updates- "CARGO_PROFILE" # let you specify the profile- "TARGET_DIR"- ])- // {- # 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/lilex"- "./assets/fonts/ibm-plex-sans"- ];- };- PROTOC = "${protobuf}/bin/protoc";- ZED_ZSTD_MUSL_LIB = "${pkgsCross.musl64.pkgsStatic.zstd.out}/lib";- };-}diff --git a/nix/toolchain.nix b/nix/toolchain.nixnew file mode 100644index 00000000000..6ef22e2a6b0--- /dev/null+++ b/nix/toolchain.nix@@ -0,0 +1,9 @@+{ inputs, ... }:+pkgs:+let+ rustBin = inputs.rust-overlay.lib.mkRustBin { } pkgs;+in+pkgs.callPackage ./build.nix {+ crane = inputs.crane.mkLib pkgs;+ rustToolchain = rustBin.fromRustupToolchainFile ../rust-toolchain.toml;+}diff --git a/rust-toolchain.toml b/rust-toolchain.tomlindex 3d058f5212a..e5c12d9efd5 100644--- a/rust-toolchain.toml+++ b/rust-toolchain.toml@@ -1,7 +1,7 @@[toolchain]channel = "1.93"profile = "minimal"-components = [ "rustfmt", "clippy" ]+components = [ "rustfmt", "clippy", "rust-analyzer" ]targets = ["wasm32-wasip2", # extensions"x86_64-unknown-linux-musl", # remote serverdiff --git a/rustfmt.toml b/rustfmt.tomlnew file mode 100644index 00000000000..7a89b919fc0--- /dev/null+++ b/rustfmt.toml@@ -0,0 +1,3 @@+# https://github.com/rust-lang/rustfmt?tab=readme-ov-file#rusts-editions+edition = "2024"+style_edition = "2024"diff --git a/shell.nix b/shell.nixindex d1783071f97..5dab565e68d 100644--- a/shell.nix+++ b/shell.nix@@ -1,11 +1,10 @@(import (let- lock = builtins.fromJSON (builtins.readFile ./flake.lock);+ rev = "v1.1.0";+ sha256 = "sha256:19d2z6xsvpxm184m41qrpi1bplilwipgnzv9jy17fgw421785q1m";infetchTarball {- 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;+ inherit sha256;+ url = "https://github.com/NixOS/flake-compat/archive/${rev}.tar.gz";}) { src = ./.; }).shellNix