Zed Editor is a promising new code editor built with performance in mind. Below, I’ll share how I configured Zed using Nix and Home Manager to create a consistent and reproducible development environment.

File Structure

First, let’s look at how the configuration files are organized:

nix-config/
└── modules/
    └── darwin/
        └── programs/
            └── zed-editor/
                ├── default.nix
                ├── extensions.nix
                ├── lsp.nix
                ├── settings.nix
                └── terminal.nix

Integration with Home Manager

To use this configuration with Home Manager, you’ll need to import it in your Home Manager configuration. Here’s how you can set it up:

# home.nix or similar
{ config, pkgs, ... }:

{
  programs.zed-editor = import ./modules/darwin/programs/zed-editor {
    inherit pkgs;
  };
}

Configuration Breakdown

Main Configuration (default.nix)

Many of the default options for Zed is borrowed from the NixOS Wiki.

The main configuration file ties everything together:

{pkgs}: let
  extentions = import ./extensions.nix;
  terminal = import ./terminal.nix;
  lsp = import ./lsp.nix;
  settings = import ./settings.nix;
in {
  enable = true;
  extensions = extentions;
  userSettings =
    settings
    // {
      terminal = terminal;
      lsp = lsp;
    };
}

Core Settings (settings.nix)

The core settings define the basic behavior of the editor:

{
  assistant.enabled = true;
  assistant.version = "2";
  assistant.default_model = {
    provider = "copilot_chat";
    model = "claude-3-5-sonnet";
  };
  hour_format = "hour24";
  vim_mode = false;
  load_direnv = "shell_hook";
  base_keymap = "VSCode";
  show_whitespaces = "trailing";
  ui_font_size = 14;
  buffer_font_size = 12;
}

Notable configurations include:

  • AI assistance using Claude 3 Sonnet via Copilot Chat
  • direnv integration for project-specific environments
  • VSCode-like keybindings for familiarity
  • Comfortable font sizes for UI and code

Language Support and Extensions (extensions.nix)

[
  "nix"
  "toml"
  "elixir"
  "make"
  "dockerfile"
  "docker-compose"
  "html"
  "helm"
]

LSP Configuration (lsp.nix)

{
  nil = {
    binary = {
      path_lookup = true;
    };
    settings = {
      formatting = {
        command = ["alejandra"];
      };
      diagnostics = {
        ignored = [
          "unused_binding"
        ];
      };
    };
  };
}

Terminal Integration (terminal.nix)

{
  alternate_scroll = "off";
  blinking = "off";
  copy_on_select = false;
  dock = "bottom";
  detect_venv = {
    on = {
      directories = [".env" "env" ".venv" "venv"];
      activate_script = "default";
    };
  };
  env = {
    TERM = "ghostty";
  };
  font_family = "0xProto Nerd Font Mono";
  working_directory = "current_project_directory";
}

Installation and Usage

  1. First, ensure you have Home Manager installed and configured.
  2. Copy the entire zed-editor directory structure into your Nix configuration.
  3. Import the configuration in your Home Manager configuration file as shown above.
  4. Run home-manager switch or darwin-rebuild to apply the changes.

Benefits of This Setup

  1. Reproducibility: Using Nix ensures the configuration is consistent across machines.
  2. Modularity: The configuration is split into logical components, making it easier to maintain.
  3. Integration: The setup works well with modern development tools like direnv and LSPs.
  4. AI-Assisted: Built-in AI assistance with Claude 3 Sonnet helps boost productivity.
  5. Home Manager Integration: Easy to manage as part of your broader system configuration.

Customization

The modular structure makes it easy to customize the configuration:

  • Modify extensions.nix to add or remove language support
  • Adjust settings.nix for editor preferences
  • Configure LSP settings in lsp.nix for different languages
  • Customize terminal behavior in terminal.nix

Conclusion

This Nix-based Zed configuration provides a solid foundation for modern development. It combines the power of Nix’s reproducibility with Zed’s performance and features, all managed through Home Manager. The modular approach makes it easy to modify and extend the configuration as needs evolve.

You can find the complete configuration in the file structure shown above. Feel free to use this as a starting point for your own Zed setup, adjusting it to your specific needs and preferences.

Remember to check the Home Manager options and Zed documentation for more configuration possibilities.