dotfiles/modules/programs/nvim/default.nix

370 lines
12 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, inputs, ... }:
2022-07-15 13:11:54 +02:00
let
2024-06-17 09:59:39 +02:00
inherit (lib) mkEnableOption mkIf readFile;
2024-06-30 18:46:10 +02:00
cfg = config.my.programs.nvim;
2022-07-15 13:11:54 +02:00
in
{
2023-09-10 13:30:29 +02:00
imports = lib.my.listModulesRec ./plugins;
2023-06-10 21:52:57 +02:00
2023-09-17 09:35:10 +02:00
options.my.programs.nvim.enable = mkEnableOption "nvim";
2022-07-15 13:11:54 +02:00
config = mkIf cfg.enable {
2024-02-12 10:10:32 +01:00
home-manager.users.moritz = {
2024-02-10 18:22:09 +01:00
xdg.configFile."nvim/snippets" = {
recursive = true;
source = ./plugins/snippets;
};
2024-06-27 10:12:38 +02:00
home.packages = with pkgs; [
2024-06-30 18:46:10 +02:00
xdotool # for vimtex
2024-06-27 10:12:38 +02:00
];
2024-08-31 10:14:44 +02:00
# programs.neovim = {
# extraPackages = with pkgs;
# [
# alejandra
# checkmake
# codespell
# deadnix
# dotenv-linter
# fish
# jq
# nil
# nixd
# nixpkgs-fmt
# nodePackages.bash-language-server
# python3Packages.python-lsp-server
# shellcheck
# shfmt
# stable.yamlfix
# statix
# taplo
# yamllint
# ];
# };
2024-09-01 22:05:20 +02:00
programs.nixvim = lib.mkMerge [
{
enable = true;
package = inputs.neovim-nightly-overlay.packages.${pkgs.system}.default;
vimAlias = true;
extraConfigLuaPre = readFile ./options.lua;
performance = {
byteCompileLua = {
enable = true;
configs = true;
initLua = true;
nvimRuntime = true;
plugins = true;
};
combinePlugins.enable = true;
};
}
{
colorschemes.catppuccin = {
enable = true;
settings.flavour = "macchiato";
};
}
{
plugins.lualine.enable = true;
}
{
plugins.cmp = {
autoEnableSources = true;
enable = true;
settings.sources = [
{ priority = 1; name = "async_path"; }
{ priority = 1; name = "buffer"; }
{ priority = 2; name = "nvim_lsp"; }
{ priority = 3; name = "nvim_lsp_signature_help"; }
{ priority = 4; name = "luasnip"; }
{ priority = 4; name = "vimtex"; }
];
settings.mapping = {
__raw = ''
cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item({ behavior = cmp.SelectBehavior.Select })
elseif require("luasnip").locally_jumpable(1) then
require("luasnip").jump(1)
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item({ behavior = cmp.SelectBehavior.Select })
elseif require("luasnip").locally_jumpable(-1) then
require("luasnip").jump(-1)
else
fallback()
end
end, { "i", "s" }),
["<C-n>"] = cmp.mapping(function(fallback)
if require("luasnip").choice_active() then
require("luasnip").change_choice(1)
elseif require("luasnip").locally_jumpable(1) then
require("luasnip").jump(1)
else
fallback()
end
end, { "i", "s" }),
["<C-p>"] = cmp.mapping(function(fallback)
if require("luasnip").choice_active() then
require("luasnip").change_choice(-1)
elseif require("luasnip").locally_jumpable(-1) then
require("luasnip").jump(-1)
else
fallback()
end
end, { "i", "s" }),
})
'';
};
};
}
{
plugins.luasnip = {
enable = true;
settings = {
history = true;
update_events = "TextChanged,TextChangedI";
delete_check_events = "TextChanged";
ext_opts.__raw = ''{
2024-08-31 10:14:44 +02:00
[require("luasnip.util.types").choiceNode] = {
active = {
virt_text = { { "<--", "Error" } },
},
},
}'';
2024-09-01 22:05:20 +02:00
ft_func.__raw = ''require("luasnip.extras.filetype_functions").from_pos_or_filetype'';
2024-08-31 10:14:44 +02:00
};
};
2024-09-01 22:05:20 +02:00
}
{
plugins.lsp = {
enable = true;
inlayHints = true;
servers.nil-ls.enable = true;
servers.nixd.enable = true;
servers.nixd.extraOptions.settings.nixd = {
nixpkgs = {
expr = "import <nixpkgs> { }";
};
options = {
nixos = {
expr = ''(builtins.getFlake ("git+file://" + toString ./.)).nixosConfigurations.nixos-desktop.options'';
};
"flake-parts" = {
expr = ''(builtins.getFlake ("git+file://" + toString ./.)).debug.options'';
};
"flake-parts2" = {
expr = ''(builtins.getFlake ("git+file://" + toString ./.)).currentSystem.options'';
};
};
};
2024-08-31 10:14:44 +02:00
};
2024-09-01 22:05:20 +02:00
}
{
plugins.lspsaga = {
enable = true;
codeAction.keys.quit = "<esc>";
lightbulb.virtualText = false;
2024-08-31 10:14:44 +02:00
};
2024-09-01 22:05:20 +02:00
keymapsOnEvents = {
LspAttach = [
{
key = "<leader>cc";
action = "<cmd>Lspsaga code_action<cr>";
options.desc = "Code Action";
options.buffer = true;
}
{
key = "gd";
action = "<cmd>Lspsaga goto_definition<cr>";
options.desc = "Goto Definition";
options.buffer = true;
}
{
key = "<leader>cr";
action = "<cmd>Lspsaga rename<cr>";
options.desc = "Rename";
options.buffer = true;
}
{
key = "K";
action = "<cmd>Lspsaga hover_doc<cr>";
options.desc = "Hover";
options.buffer = true;
}
];
2024-08-31 10:14:44 +02:00
};
2024-09-01 22:05:20 +02:00
}
{
plugins.nvim-ufo.enable = true;
}
{
plugins.treesitter = {
enable = true;
folding = true;
nixvimInjections = true;
settings.indent.enable = true;
settings.highlight.enable = true;
2024-08-31 10:14:44 +02:00
};
2024-09-01 22:05:20 +02:00
performance.combinePlugins.standalonePlugins = [
"nvim-treesitter"
];
}
{ plugins.which-key.enable = true; }
{ plugins.lastplace.enable = true; }
{ plugins.comment.enable = true; }
{ plugins.ts-context-commentstring.enable = true; }
{
plugins.vimtex = {
enable = true;
settings.view_method = "zathura";
2024-08-31 10:14:44 +02:00
};
2024-09-01 22:05:20 +02:00
}
{
plugins.todo-comments = {
enable = true;
keymaps.todoTelescope.key = "<leader>fc";
2024-08-31 10:14:44 +02:00
};
2024-09-01 22:05:20 +02:00
}
{
plugins.conform-nvim = {
2024-08-31 10:14:44 +02:00
enable = true;
2024-09-01 22:05:20 +02:00
settings.formatters_by_ft = {
"*" = [ "codespell" "trim_whitespace" ];
elixir = [ "mix" ];
gleam = [ "gleam" ];
go = [ "gofmt" ];
json = [ "jq" ];
lua = [ "stylua" ];
nix.__raw = ''{ "nixpkgs_fmt", "alejandra", stop_after_first=true }'';
python.__raw = ''
function(bufnr)
return { first("ruff_organize_imports", "isort"), first("ruff_format", "black")}
end
'';
rust = [ "rustfmt" ];
sh = [ "shfmt" ];
tex = [ "latexindent" ];
toml = [ "taplo" ];
yaml = [ "yamlfix" ];
};
2024-08-31 10:14:44 +02:00
};
2024-09-01 22:05:20 +02:00
opts.formatexpr = "v:lua.require'conform'.formatexpr()";
extraConfigLuaPre = ''
---@param bufnr integer
---@param ... string
---@return string
local function first(bufnr, ...)
local conform = require("conform")
for i = 1, select("#", ...) do
local formatter = select(i, ...)
if conform.get_formatter_info(formatter, bufnr).available then
return formatter
end
end
return select(1, ...)
end
vim.api.nvim_create_user_command("Format", function(opts)
require("conform").format({ formatters = opts.fargs })
end, {
nargs = "+",
complete = function()
local formatters_by_ft = require("conform").formatters_by_ft
local names = formatters_by_ft[vim.bo.filetype] or formatters_by_ft["_"] or {}
names = vim.list_extend(names, formatters_by_ft["*"] or {})
names = vim.tbl_flatten(names)
local formatters = vim.tbl_map(require("conform").get_formatter_info, names)
formatters = vim.tbl_filter(function(formatter)
return formatter.available
end, formatters)
return vim.tbl_map(function(formatter_info)
return formatter_info.name
end, formatters)
end,
})
'';
performance.combinePlugins.standalonePlugins = [
2024-08-31 10:14:44 +02:00
"conform.nvim"
2023-07-24 18:44:03 +02:00
];
2024-09-01 22:05:20 +02:00
keymaps = [
{ key = "<leader>cf"; action.__raw = ''function() require("conform").format() end''; options.desc = "Format current file"; }
];
}
{
keymaps = [
{ key = "<esc>"; action = "<cmd>noh<cr><esc>"; options.desc = "Escape and clear hlsearch"; mode = [ "i" "n" ]; }
];
}
{ plugins.oil.enable = true; }
{
plugins.telescope = {
enable = true;
extensions.fzf-native.enable = true;
keymaps = {
"<leader>ff" = {
action = "find_files";
options.desc = "Find files";
};
"<leader>fb" = {
action = "buffers";
options.desc = "Find buffers";
};
"<leader>fl" = {
action = "current_buffer_fuzzy_find";
options.desc = "Search lines";
};
"<leader>fg" = {
action = "live_grep";
options.desc = "Live grep";
};
"<leader>fh" = {
action = "help_tags";
options.desc = "Help tags";
};
"<leader>fr" = {
action = "oldfiles";
options.desc = "Recent files";
};
};
};
}
{ plugins.nvim-autopairs.enable = true; }
{ plugins.surround.enable = true; }
{
plugins.lint.enable = true;
# TODO: add linters
plugins.lint.lintersByFt = { };
}
{
plugins.marks.enable = true;
plugins.marks.defaultMappings = false;
}
{
plugins.hmts.enable = true;
performance.combinePlugins.standalonePlugins = [ "hmts.nvim" ];
}
{ plugins.gitsigns.enable = true; }
{ plugins.fugitive.enable = true; }
{ plugins.friendly-snippets.enable = true; }
{ plugins.direnv.enable = true; }
{ plugins.crates-nvim.enable = true; }
];
2022-07-15 13:11:54 +02:00
};
};
}