Skip to content

nix: Use flake-parts, partitions, and treefmt-nix#45321

Merged
kubkon merged 9 commits intozed-industries:mainfrom
doprz:refactor/nix-flake-parts
Feb 2, 2026
Merged

nix: Use flake-parts, partitions, and treefmt-nix#45321
kubkon merged 9 commits intozed-industries:mainfrom
doprz:refactor/nix-flake-parts

Conversation

@doprz
Copy link
Contributor

@doprz doprz commented Dec 19, 2025

Hi @zed-industries team! Thank you for building such an amazing editor. Zed has become my daily driver and a key part of my development workflow. I really like the performance, vim-support, and collaboration features. Excited to make my first contribution! 🚀

Release Notes:

Refactored:

  • Use flake-parts modules
  • nix/shell.nix -> nix/modules/devshells.nix

Added:

  • Use flake-parts.partitions to isolate dev dependencies so that flakes that use zed-editor don't fetch dev-only inputs such as treefmt-nix
  • treefmt-nix
    • nixfmt
    • rustfmt

Fixed:

  • shell.nix and default.nix fetching flake-compat from flake.lock which added an extra and unnecessary input/dependency to flake.nix. Fixed by setting a fixed rev and sha256 instead.
  • nixfmt-rfc-style is deprecated and is now nixfmt
  • Fixes Nix dev shell takes a very long time to load #45338 by using rust-overlay toolchain directly
    • Previously, the devShell included rustup which caused slow startup
      times as Nix would build rustup from source (including running its test
      suite). Additionally, rust tooling (cargo, rustfmt, clippy, rust-analyzer) wasn't available in the dev shell.
    • cargo, rustc, and rust-toolchain.toml components included in rustToolchain

Chore:

  • Update flake.lock
  • Format Rust code with rustfmt via treefmt-nix

@cla-bot
Copy link

cla-bot bot commented Dec 19, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @doprz on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@doprz
Copy link
Contributor Author

doprz commented Dec 19, 2025

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Dec 19, 2025
@cla-bot
Copy link

cla-bot bot commented Dec 19, 2025

The cla-bot has been summoned, and re-checked this pull request!

@doprz doprz force-pushed the refactor/nix-flake-parts branch from a150599 to afb16d2 Compare December 19, 2025 01:34
@maxdeviant maxdeviant changed the title refactor(nix): use flake-parts, partitions, and treefmt-nix nix: Use flake-parts, partitions, and treefmt-nix Dec 19, 2025
@doprz
Copy link
Contributor Author

doprz commented Dec 19, 2025

There seems to be a mismatch between cargo fmt --all -- --check and nix fmt. Checking to see what the issue is.

It seems that these commands differ even if the edition = "2024" is set correctly via cli args. See: https://github.com/rust-lang/rustfmt?tab=readme-ov-file#rusts-editions

When running cargo fmt, the edition is automatically read from the Cargo.toml file. However, when running rustfmt directly, the edition defaults to 2015. For consistent parsing between rustfmt and cargo fmt, you should configure the edition in your rustfmt.toml file.


Update: I was able to resolve this by creating rustfmt.toml and setting it to:

edition = "2024"
style_edition = "2024"

@doprz doprz marked this pull request as draft December 19, 2025 02:25
@doprz doprz marked this pull request as ready for review December 19, 2025 03:29
@doprz
Copy link
Contributor Author

doprz commented Dec 19, 2025

This PR is now complete and ready for review!

@doprz
Copy link
Contributor Author

doprz commented Dec 30, 2025

I'm also considering using crate2nix rather than crane as it can:

save time by only rebuilding changed crates hermetically...

However, it uses import from derivation (IFD) which can disable build parallelism. Open to thoughts on this issue. I think it's out of scope for this PR but something we should revisit in the future.

@doprz
Copy link
Contributor Author

doprz commented Jan 5, 2026

Bump @P1n3appl3

@P1n3appl3
Copy link
Contributor

Sorry for the delay, unfortunately I no longer help maintain Zed. @kubkon should be able to review this.

@doprz
Copy link
Contributor Author

doprz commented Jan 13, 2026

Sorry for the delay, unfortunately I no longer help maintain Zed. @kubkon should be able to review this.

Thank you for the update!

@GustavoWidman
Copy link

this looks amazing, builds are probably going to end up much faster now (for nix users). just a question (or suggestion), wouldn't it also we worth to start regularly building and pushing the release candidates to the nix cache instead of just the nightlies? i'd really like to just plug in zed and have a "stable" and/or "pre" tag (like we have with the nightly branch) and be able to easily update zed to the latest and greatest from github with a simple flake input update.

@doprz
Copy link
Contributor Author

doprz commented Jan 14, 2026

this looks amazing, builds are probably going to end up much faster now (for nix users). just a question (or suggestion), wouldn't it also we worth to start regularly building and pushing the release candidates to the nix cache instead of just the nightlies? i'd really like to just plug in zed and have a "stable" and/or "pre" tag (like we have with the nightly branch) and be able to easily update zed to the latest and greatest from github with a simple flake input update.

Thanks! That is a great idea and also one of my use cases. I run both the a nightly and stable version of Zed but it would be nice to be able to pull a cached release candidate on another Nix machine. Not sure who is in charge of nix-related changes in Zed so that is a question/request geared towards them.

@doprz
Copy link
Contributor Author

doprz commented Jan 24, 2026

cc: @osiewicz and @kubkon

doprz and others added 9 commits February 2, 2026 15:02
Previously, the dev shell included `rustup` which caused slow startup
times as Nix would build rustup from source (including running its test
suite). Additionally, rust tooling (cargo, rustfmt, clippy, rust-analyzer) wasn't
properly available in the dev shell.

This change:
- Removes unnecessary `rustup` dependency significantly improving `nix develop` startup time
- Directly includes `rustToolchain` from rust-overlay in packages
- Provides cargo, rustc, and all rust-toolchain.toml components
@kubkon kubkon force-pushed the refactor/nix-flake-parts branch from 79a1b72 to afeef2c Compare February 2, 2026 14:06
@zed-industries-bot
Copy link
Contributor

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against afeef2c

@kubkon kubkon enabled auto-merge (squash) February 2, 2026 14:10
@kubkon kubkon merged commit cfbf6eb into zed-industries:main Feb 2, 2026
27 checks passed
@jrobsonchase
Copy link
Contributor

I think this broke my rust-analyzer and its ability to locate the RUST_SRC. Previously, I don't believe rust-analyzer was getting installed by the flake, and was "doing its own thing" as far as the rust src was concerned. Not 100% correct, but "good enough."

Now though, it's failing to find it and giving me 400+ errors in weird places like the editor tests where it's resolving the update method to the Itertools trait rather than a concrete one. Probably due to a missing RUST_SRC breaking proc macro analysis.

@doprz doprz deleted the refactor/nix-flake-parts branch February 5, 2026 02:02
adb-sh pushed a commit to adb-sh/zed that referenced this pull request Feb 5, 2026
Release Notes:

Refactored:
- Use [flake-parts](https://flake.parts/index.html) modules
- `nix/shell.nix` -> `nix/modules/devshells.nix`

Added:
- Use
[flake-parts.partitions](https://flake.parts/options/flake-parts-partitions.html)
to isolate dev dependencies so that flakes that use `zed-editor` don't
fetch dev-only inputs such as `treefmt-nix`
- [treefmt-nix](https://github.com/numtide/treefmt-nix)
  - nixfmt
  - rustfmt

Fixed:
- `shell.nix` and `default.nix` fetching `flake-compat` from
`flake.lock` which added an extra and unnecessary input/dependency to
`flake.nix`. Fixed by setting a fixed rev and sha256 instead.
- `nixfmt-rfc-style` is deprecated and is now `nixfmt`
- Fixes zed-industries#45338 by using rust-overlay toolchain directly
  - Previously, the devShell included `rustup` which caused slow startup
times as Nix would build rustup from source (including running its test
suite). Additionally, rust tooling (cargo, rustfmt, clippy,
rust-analyzer) wasn't available in the dev shell.
- cargo, rustc, and rust-toolchain.toml components included in
`rustToolchain`

Chore:
- Update `flake.lock`
- Format Rust code with `rustfmt` via `treefmt-nix`

---------

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nix dev shell takes a very long time to load

6 participants