{ inputs, config, lib, pkgs, ... }: let cfg = config.programs.zed-editor; in { options.programs.zed-editor = { userTasks = lib.mkOption { type = lib.types.listOf lib.types.attrs; default = [ ]; }; defaultEditor = lib.mkOption { type = lib.types.bool; default = false; }; }; config = lib.mkIf cfg.enable { programs.zed-editor = { package = inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.zed-editor; extensions = [ "ruby" "crystal" "nix" "svelte" ]; userSettings = { node = { path = lib.getExe pkgs.nodejs_latest; npm_path = lib.getExe' pkgs.nodejs_latest "npm"; }; assistant = { enabled = true; version = "2"; default = "zed.dev"; default_model = { provider = "zed.dev"; model = "claude-3-7-sonnet-latest"; }; }; autoUpdate = false; telemetry = { diagnostics = false; metrics = false; }; vim_mode = true; languages = { Ruby = { language_servers = [ "ruby-lsp" "rubocop" "!solargraph" ]; formatter.external = { command = pkgs.writeShellScript "rufo" '' bundle exec rufo "$@" if [ $? -eq 1 ]; then exit 1 fi ''; arguments = [ "--filename" "{buffer_path}" ]; }; }; Nix = { formatter.external = { command = lib.getExe pkgs.nixfmt-rfc-style; arguments = [ "-q" ]; }; }; Rust = { formatter.external = { command = lib.getExe pkgs.rustfmt; arguments = [ "--edition" "2018" ]; }; }; }; lsp = with pkgs; { nixd.binary.path = lib.getExe nixd; nil.binary.path = lib.getExe nil; ruby-lsp.binary.path = lib.getExe ruby-lsp; rubocop = { binary = { path = "bundle"; arguments = [ "exec" "rubocop" "--lsp" ]; }; }; yaml-language-server.binary = { path = lib.getExe yaml-language-server; arguments = [ "--stdio" ]; }; json-language-server.binary = { path = lib.getExe nodePackages.vscode-json-languageserver; arguments = [ "--stdio" ]; }; package-version-server.binary.path = lib.getExe inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}.package-version-server; eslint.settings.onIgnoredFiles = "off"; crystalline.binary.path = lib.getExe crystalline; rust-analyzer.binary.path = lib.getExe rust-analyzer; }; load_direnv = "shell_hook"; theme = { mode = "system"; light = "One Light"; dark = "One Dark"; }; terminal = { line_height = "standard"; font_family = "IosevkaTerm Nerd Font"; }; show_edit_predictions = true; edit_predictions.mode = "eager_preview"; features = { "edit_prediction_provider" = "zed"; }; buffer_font_family = "Iosevka Nerd Font"; buffer_font_size = 16; ui_font_size = 17; relative_line_numbers = true; file_types = { JSONC = [ "tsconfig.json" "tsconfig.*.json" ]; }; }; userKeymaps = [ { context = "VimControl && !menu"; bindings = { "space g" = [ "task::Spawn" { task_name = "lazygit"; reveal_target = "center"; } ]; "space r" = "pane::DeploySearch"; "space f" = [ "file_finder::Toggle" { separate_history = true; } ]; "space :" = "task::Spawn"; "g R" = "editor::FindAllReferences"; }; } { context = "Dock || Pane || Editor"; bindings = { "ctrl-h" = [ "workspace::ActivatePaneInDirection" "Left" ]; "ctrl-j" = [ "workspace::ActivatePaneInDirection" "Down" ]; "ctrl-k" = [ "workspace::ActivatePaneInDirection" "Up" ]; "ctrl-l" = [ "workspace::ActivatePaneInDirection" "Right" ]; }; } { context = "Terminal"; bindings = { "ctrl-p" = [ "terminal::SendKeystroke" "ctrl-p" ]; }; } ]; userTasks = [ { label = "lazygit"; command = lib.getExe config.programs.lazygit.package; env = { EDITOR = lib.getExe cfg.package; }; args = [ "-p" "$ZED_WORKTREE_ROOT" ]; reveal = "always"; allow_concurrent_runs = true; use_new_terminal = false; hide = "on_success"; } ]; }; xdg.configFile."zed/tasks.json".text = builtins.toJSON cfg.userTasks; home.sessionVariables = lib.mkIf cfg.defaultEditor { EDITOR = lib.getExe cfg.package; }; }; }