{ den, modules, lib, inputs, ... }: { # Its in its own folder for future modulizaion efforts flake-file.inputs = { nixvim = { url = "github:nix-community/nixvim"; }; }; modules = { nixvim = { nixos = { home-manager, ... }: { }; homeManager = { pkgs, ... }: let tiny-code-action = pkgs.vimUtils.buildVimPlugin { name = "tiny-code-action.nvim"; src = pkgs.fetchFromGitHub { owner = "rachartier"; repo = "tiny-code-action.nvim"; rev = "0d040ed81f7953118b81cd12681fcdfcac069803"; hash = "sha256-UF9zeO5Uujdt2MEwy2d2Lhk6JRnEN4vrEvYslv0/zaA"; }; nvimSkipModules = [ "tiny-code-action.previewers.snacks" ]; }; cmp-lsp-rs = pkgs.vimUtils.buildVimPlugin { name = "nvim-cmp-lsp-rs"; src = pkgs.fetchFromGitHub { owner = "zjp-CN"; repo = "nvim-cmp-lsp-rs"; rev = "329075b806deb719d3ce4f55a7e443541ce5289d"; hash = "sha256-rBABhsShCrx7Gofm1mC6DQAL0KeNtQidW9eMr9kfwGI="; }; # nvim-cmp on rtp during the require check (cmp_lsp_rs requires cmp.types.lsp at load time) dependencies = [ pkgs.vimPlugins.nvim-cmp ]; }; in { imports = [ inputs.nixvim.homeModules.nixvim ]; programs.nixvim = { enable = true; defaultEditor = true; nixpkgs = { config = { allowUnfree = true; }; source = inputs.nixpkgs; }; colorschemes.gruvbox-material.enable = true; # colorschemes.melange = { # enable = true; # autoLoad = false; # }; dependencies.rust-analyzer.enable = false; extraPackages = with pkgs; [ # formatters nixfmt-rs rustfmt # misc ripgrep nixd tree-sitter # rust-analyzer # rustc # cargo ]; performance.byteCompileLua = { enable = true; plugins = true; nvimRuntime = true; luaLib = true; configs = true; }; plugins = { luasnip.enable = true; cmp_luasnip.enable = true; fidget.enable = true; mini-comment.enable = true; # cord.enable = true; todo-comments.enable = true; transparent.enable = true; which-key.enable = true; snacks.enable = true; conform-nvim = { enable = true; settings = { formatters_by_ft = { nix = [ "nixfmt" ]; rust = [ "rustfmt" ]; "_" = [ "squeeze_blanks" "trim_whitespace" "trim_newlines" ]; }; format_on_save = { timeout_ms = 500; lsp_format = "fallback"; }; }; }; # efmls-configs = { # enable = true; # languages = { # scss = { # formatter = "prettier"; # linter = "stylelint"; # }; # }; # }; rustaceanvim = { enable = true; settings = { server = { default_settings = { rust-analyzer = { cargo.targetDir = true; diagnostics.refresh_update = true; }; }; }; }; }; lsp = { enable = true; onAttach = '' if client.name == "rust-analyzer" then client.server_capabilities.semanticTokensProvider = nil end ''; servers = { # qmlls = { # enable = true; # config = { # cmd = "-E"; # }; # }; # rust_analyzer = { # enable = true; # installCargo = false; # installRustc = false; # }; nixd = { enable = true; settings = { nixd = { nixpkgs.expr = "import (builtins.getFlake \"${toString /home/doloro/dotfiles}\").inputs.nixpkgs { }"; }; }; }; astro = { enable = false; }; ts_ls = { enable = true; }; cssls = { enable = true; package = pkgs.vscode-langservers-extracted; }; svelte.enable = true; }; }; # mini-statusline.enable = true; lualine = { enable = true; settings = { sections = { lualine_a = [ "mode" ]; lualine_b = [ "branch" "diff" "diagnostics" ]; lualine_c = [ "filename" ]; lualine_x = [ "encoding" "fileformat" "filetype" ]; lualine_y = [ "progress" ]; lualine_z = [ "location" ]; }; inactive_sections = { lualine_a = [ ]; lualine_b = [ ]; lualine_c = [ "filename" ]; lualine_x = [ "location" ]; lualine_y = [ ]; lualine_z = [ ]; }; }; }; web-devicons.enable = true; lazygit.enable = true; mini-indentscope = { enable = true; settings = { draw = { delay = 10; }; }; }; mini-files = { enable = true; settings = { windows = { preview = true; }; }; }; trouble = { enable = true; settings = { auto_close = true; use_diagnostic_signs = true; }; }; cmp = { enable = true; autoEnableSources = true; cmdline = { ":" = { mapping.__raw = "cmp.mapping.preset.cmdline()"; sources = [ { name = "cmdline"; } ]; }; "/" = { mapping.__raw = "cmp.mapping.preset.cmdline()"; sources = [ { name = "buffer"; } ]; }; }; settings = { snippet.expand.__raw = "function(args) require('luasnip').lsp_expand(args.body) end"; sources = [ { name = "nvim_lsp"; priority = 100; entry_filter = "require('cmp_lsp_rs').filter_out.rust_entry_filter"; } { name = "luasnip"; priority = 75; } { name = "buffer"; priority = 50; } ]; mapping = { "" = "cmp.mapping.complete()"; "" = "cmp.mapping.scroll_docs(-4)"; "" = "cmp.mapping.close()"; "" = "cmp.mapping.scroll_docs(4)"; "" = "cmp.mapping.confirm({ select = true })"; "" = "cmp.mapping(function(fallback) if cmp.visible() then cmp.select_prev_item() elseif require('luasnip').jumpable(-1) then require('luasnip').jump(-1) else fallback() end end, {'i', 's'})"; "" = "cmp.mapping(function(fallback) if cmp.visible() then cmp.select_next_item() elseif require('luasnip').expand_or_jumpable() then require('luasnip').expand_or_jump() else fallback() end end, {'i', 's'})"; }; sorting = { comparators = [ "require('cmp.config.compare').exact" "require('cmp.config.compare').score" "require('cmp_lsp_rs').comparators.inscope_inherent_import" "require('cmp_lsp_rs').comparators.sort_by_label_but_underscore_last" ]; }; window = { completion = { border = "rounded"; winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,CursorLine:PmenuSel,Search:None"; }; documentation = { border = "rounded"; winhighlight = "Normal:Pmenu,FloatBorder:Pmenu"; }; }; }; }; lspkind.enable = true; tiny-inline-diagnostic.enable = true; # tiny-code-action.enable = true; # persisted.enable = true; wakatime.enable = true; treesitter = { enable = true; grammarPackages = with pkgs.vimPlugins.nvim-treesitter.builtGrammars; [ bash css html javascript json lua make markdown rust nix regex toml tsx typescript vim vimdoc xml yaml svelte ]; settings = { highlight.enable = true; indent.enable = false; }; }; }; extraPlugins = with pkgs; [ tiny-code-action cmp-lsp-rs ]; opts = { number = true; bg = "dark"; tabstop = 2; shiftwidth = 2; termguicolors = true; completeopt = "menu,menuone,noselect"; }; globals = { mapleader = " "; }; extraConfigLua = '' -- LSP client writes server stderr + errors to disk on the main loop; nixd spams info logs -> 5MB+ logs. -- warn level: captures server stderr (incl. rust-analyzer slow-request timing) without nixd's info spam. vim.lsp.set_log_level("warn") -- tree-sitter-nix uses (#is-not? local) which the new nvim-treesitter main branch no longer registers vim.treesitter.query.add_predicate("is-not?", function() return true end, { force = true }) require('tiny-code-action').setup({ backend = 'vim', picker = 'snacks', resolve_timeout = 100, notify = { enabled = true, on_empty = true, }, }) ''; keymaps = [ { action = "lua require('snacks.picker').files()"; key = "ff"; options = { silent = true; }; } { action = ":lua MiniFiles.open()"; key = "fv"; options = { silent = true; }; } { action = "LazyGit"; key = "lg"; options = { silent = true; }; } { action = "lua require('snacks.picker').buffers()"; key = "fb"; options = { silent = true; }; } { action = "lua require('snacks.picker').grep()"; key = "fg"; options = { silent = true; }; } { action = "Trouble diagnostics toggle"; key = "fd"; options = { silent = true; desc = "Toggle diagnostics (Trouble)"; }; } { action = "lua require('tiny-code-action').code_action()"; key = "ca"; mode = [ "n" "x" ]; options = { silent = true; }; } # LSP { action = "lua vim.lsp.buf.definition()"; key = "gd"; options = { silent = true; desc = "Go to definition"; }; } { action = "lua vim.lsp.buf.declaration()"; key = "gD"; options = { silent = true; desc = "Go to declaration"; }; } { action = "lua vim.lsp.buf.implementation()"; key = "gi"; options = { silent = true; desc = "Go to implementation"; }; } { action = "lua vim.lsp.buf.type_definition()"; key = "D"; options = { silent = true; desc = "Go to type definition"; }; } { action = "lua require('snacks.picker').lsp_references()"; key = "gr"; options = { silent = true; desc = "LSP references"; }; } { action = "lua vim.lsp.buf.hover()"; key = "K"; options = { silent = true; desc = "Hover docs"; }; } { action = "lua vim.lsp.buf.signature_help()"; key = ""; mode = [ "n" "i" ]; options = { silent = true; desc = "Signature help"; }; } { action = "lua vim.lsp.buf.rename()"; key = "rn"; options = { silent = true; desc = "Rename symbol"; }; } { action = "lua vim.diagnostic.goto_prev()"; key = "[d"; options = { silent = true; desc = "Previous diagnostic"; }; } { action = "lua vim.diagnostic.goto_next()"; key = "]d"; options = { silent = true; desc = "Next diagnostic"; }; } { action = "lua vim.diagnostic.open_float()"; key = "e"; options = { silent = true; desc = "Show diagnostic float"; }; } ]; }; }; }; }; }