Files
nixos/home/modules/zed/default.nix
2025-03-03 09:03:10 +02:00

179 lines
4.6 KiB
Nix

{
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" ];
};
};
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;
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;
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;
};
};
}