From a93d4afbcfd14ecf5b79c0050c0fe1908041275e Mon Sep 17 00:00:00 2001 From: Joakim Repomaa Date: Sat, 1 Mar 2025 13:20:40 +0200 Subject: [PATCH] radish: add zed --- home/common/default.nix | 12 ++- home/common/neovim/default.nix | 2 +- home/modules/zed/default.nix | 164 +++++++++++++++++++++++++++++++++ 3 files changed, 174 insertions(+), 4 deletions(-) create mode 100644 home/modules/zed/default.nix diff --git a/home/common/default.nix b/home/common/default.nix index da1794b..3a59985 100644 --- a/home/common/default.nix +++ b/home/common/default.nix @@ -5,6 +5,7 @@ ../custom-programs ./neovim ./dnote.nix + ../modules/zed inputs.hastebin.nixosModules.hm ]; @@ -110,7 +111,7 @@ enable = true; font = { name = "IosevkaTerm NFM"; - size = 12; + size = 14; }; shellIntegration.enableZshIntegration = true; themeFile = "Tomorrow_Night"; @@ -207,9 +208,10 @@ }; os = { edit = "$EDITOR {{filename}}"; - editAtLine = "$EDITOR +{{line}} {{filename}}"; - editAtLineAndWait = "$EDITOR --remote-wait +{{line}} {{filename}}"; + editAtLine = "$EDITOR {{filename}}:{{line}}"; + editAtLineAndWait = "$EDITOR --wait {{filename}}:{{line}}"; }; + promptToReturnFromSubprocess = false; customCommands = [ { key = ""; @@ -299,6 +301,10 @@ clipboard_command = "${pkgs.wl-copy-both}/bin/wl-copy"; }; }; + zed-editor = { + enable = true; + defaultEditor = true; + }; }; gnome = { diff --git a/home/common/neovim/default.nix b/home/common/neovim/default.nix index c73eb27..413bf22 100644 --- a/home/common/neovim/default.nix +++ b/home/common/neovim/default.nix @@ -9,7 +9,7 @@ in { enable = true; - defaultEditor = true; + defaultEditor = false; options = { number = true; expandtab = true; diff --git a/home/modules/zed/default.nix b/home/modules/zed/default.nix new file mode 100644 index 0000000..f90099c --- /dev/null +++ b/home/modules/zed/default.nix @@ -0,0 +1,164 @@ +{ + 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; + npm_path = lib.getExe' pkgs.nodejs "npm"; + }; + assistant = { + enabled = true; + version = "2"; + default = "zed.dev"; + default_model = { + provider = "zed.dev"; + model = "claude-3-5-sonnet-latest"; + }; + }; + autoUpdate = false; + telemetry = { + diagnostics = false; + metrics = false; + }; + vim_mode = true; + languages = { + Ruby = { + language_servers = [ + "ruby-lsp" + "!rubocop" + "!solargraph" + ]; + }; + Nix = { + formatter.external = { + command = lib.getExe pkgs.nixfmt-rfc-style; + arguments = [ "-q" ]; + }; + }; + }; + lsp = with pkgs; { + nixd.binary.path = lib.getExe nixd; + nil.binary.path = lib.getExe nil; + ruby-lsp.binary.path = lib.getExe ruby-lsp; + yaml-language-server.binary.path = lib.getExe yaml-language-server; + 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"; + }; + 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; + buffer_font_family = "Iosevka Nerd Font"; + buffer_font_size = 16; + ui_font_size = 17; + relative_line_numbers = true; + }; + 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 = with pkgs; [ + { + label = "lazygit"; + command = "${lib.getExe lazygit} -p $ZED_WORKTREE_ROOT"; + hide = "on_success"; + } + ]; + }; + + xdg.configFile."zed/tasks.json".text = builtins.toJSON cfg.userTasks; + + home.sessionVariables = lib.mkIf cfg.defaultEditor { + EDITOR = lib.getExe pkgs.zed-editor; + }; + }; +}