From 6174f3650cf42aaf008012e828d5a1f8e2ce037f Mon Sep 17 00:00:00 2001 From: Leander Scherer Date: Thu, 8 Jan 2026 02:48:11 +0100 Subject: refactor(modules): separate nixos/home-manager modules, use standard option conventions --- modules/users/editors/neovim/default.nix | 109 ++++++++++++++++++ modules/users/editors/neovim/init.lua | 190 +++++++++++++++++++++++++++++++ 2 files changed, 299 insertions(+) create mode 100644 modules/users/editors/neovim/default.nix create mode 100644 modules/users/editors/neovim/init.lua (limited to 'modules/users/editors/neovim') diff --git a/modules/users/editors/neovim/default.nix b/modules/users/editors/neovim/default.nix new file mode 100644 index 0000000..975fae8 --- /dev/null +++ b/modules/users/editors/neovim/default.nix @@ -0,0 +1,109 @@ +{ + config, + username, + lib, + pkgs, + ... +}: + +let + inherit (lib) + mkOption + types + mkIf + optionals + ; + cfg = config.nx.editors.neovim; +in +{ + options.nx.editors.neovim = { + enable = mkOption { + description = "Neovim editor"; + type = types.bool; + default = true; + }; + + langs = { + python = mkOption { + description = "enable the python integration"; + type = types.bool; + default = false; + }; + go = mkOption { + description = "enable go integration"; + type = types.bool; + default = false; + }; + ts = mkOption { + description = "enable the js/ts integration"; + type = types.bool; + default = false; + }; + java = mkOption { + description = "enable the java integration"; + type = types.bool; + default = false; + }; + nix = mkOption { + description = "enable the nix integration"; + type = types.bool; + default = true; + }; + latex = mkOption { + description = "enable latex integration"; + type = types.bool; + default = false; + }; + }; + }; + + config = mkIf cfg.enable { + programs.neovim = { + defaultEditor = true; + enable = true; + package = pkgs.neovim-unwrapped; + extraPackages = + with pkgs; + [ + tree-sitter + git + ripgrep + fd + gcc + ] + ++ (optionals cfg.langs.ts [ pkgs.nodePackages.typescript-language-server ]) + ++ (optionals cfg.langs.python [ ]) + ++ (optionals cfg.langs.go [ pkgs.gopls ]) + ++ (optionals cfg.langs.java [ pkgs.jdt-language-server ]) + ++ (optionals cfg.langs.nix [ + pkgs.nil + pkgs.nixfmt-rfc-style + ]) + ++ (optionals cfg.langs.latex [ pkgs.texlab ]); + + plugins = with pkgs.vimPlugins; [ + gruvbox-nvim + mini-starter + gitsigns-nvim + nvim-autopairs + telescope-nvim + fidget-nvim + plenary-nvim + nvim-treesitter.withAllGrammars + nvim-lspconfig + nvim-cmp + cmp-nvim-lsp + cmp-buffer + cmp-path + cmp-cmdline + luasnip + cmp_luasnip + lspkind-nvim + ]; + + extraConfig = '' + luafile ${./init.lua} + ''; + }; + }; +} diff --git a/modules/users/editors/neovim/init.lua b/modules/users/editors/neovim/init.lua new file mode 100644 index 0000000..1d2bdbb --- /dev/null +++ b/modules/users/editors/neovim/init.lua @@ -0,0 +1,190 @@ +-- General settings +vim.g.mapleader = " " +vim.o.number = true +vim.o.relativenumber = true +vim.o.signcolumn = "yes" +vim.o.termguicolors = true +vim.o.wrap = false +vim.o.tabstop = 2 +vim.o.shiftwidth = 2 +vim.o.updatetime = 250 +vim.o.timeoutlen = 300 +vim.o.swapfile = false +vim.o.ignorecase = true +vim.o.smartcase = true +vim.o.winborder = "rounded" +vim.o.clipboard = "unnamedplus" + +local map = vim.keymap.set +map('n', 'o', 'updatesource %', { desc = 'Save & reload init.lua' }) +map('n', 'w', 'write') +map('n', 'q', 'quit') + + +require("mini.starter").setup({ + header = table.concat({ + " /l、 ", + "(゚、 。 7 ", + " l ~ ヽ ", + " じしf_,)ノ ", + }, "\n"), + footer = "", + content_hooks = { + require("mini.starter").gen_hook.adding_bullet("» "), + require("mini.starter").gen_hook.aligning("center", "center"), + }, +}) + +require("gitsigns").setup() +require("nvim-autopairs").setup() +require("fidget").setup() + +vim.cmd("colorscheme gruvbox") + +local hl = vim.api.nvim_set_hl +hl(0, 'Normal', { bg = 'none' }) +hl(0, 'NormalFloat', { bg = 'none' }) +hl(0, 'NormalNC', { bg = 'none' }) +hl(0, 'StatusLine', { bg = 'none' }) +hl(0, 'SignColumn', { bg = 'none' }) +hl(0, "DiagnosticError", { bg = "none" }) +hl(0, "DiagnosticSignError", { bg = "none" }) +hl(0, "DiagnosticSignHint", { bg = "none" }) +hl(0, "DiagnosticSignInfo", { bg = "none" }) +hl(0, "DiagnosticSignWarn", { bg = "none" }) + +hl(0, "Pmenu", { bg = "none" }) +hl(0, "PmenuSel", { bg = "none" }) +hl(0, "FloatBorder", { bg = "none" }) + +local status_ok, configs = pcall(require, "nvim-treesitter.configs") +if status_ok then + configs.setup({ + highlight = { enable = true }, + indent = { enable = true }, + }) +end + +local builtin = require('telescope.builtin') +local map = vim.keymap.set +map('n', 'ff', builtin.find_files, { desc = 'Telescope find files' }) +map('n', 'fg', builtin.live_grep, { desc = 'Telescope live grep' }) +map('n', 'fb', builtin.buffers, { desc = 'Telescope buffers' }) +map('n', 'fh', builtin.help_tags, { desc = 'Telescope help tags' }) + + +local cmp = require("cmp") +cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.abort(), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, { 'i', 's' }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, { 'i', 's' }), + }), + sources = cmp.config.sources({ + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, { + { name = 'buffer' }, + }) +}) + +-- Add parentheses after selecting function or method +local cmp_autopairs = require('nvim-autopairs.completion.cmp') +cmp.event:on( + 'confirm_done', + cmp_autopairs.on_confirm_done() +) + +local capabilities = require('cmp_nvim_lsp').default_capabilities() + +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('UserLspConfig', {}), + callback = function(ev) + local opts = { buffer = ev.buf, noremap = true, silent = true } + vim.keymap.set('n', 'lf', function() vim.lsp.buf.format { async = true } end, opts) + end, +}) + +local servers = { + nixd = { + settings = { + nixd = { + formatting = { + command = { "nixfmt" }, + }, + }, + }, + }, + lua_ls = { + settings = { + lua_ls = { + formatting = { + command = { "luaformatter" }, + }, + }, + Lua = { + runtime = { + version = 'LuaJIT', + }, + diagnostics = { + globals = { 'vim', 'require' }, + }, + workspace = { + library = vim.api.nvim_get_runtime_file("", true), + }, + telemetry = { + enable = false, + }, + }, + }, + }, + pyright = {}, + tailwindcss = {}, + gopls = { + settings = { + gopls = { + analyses = { + unusedparams = true, + unusedwrite = true, + }, + staticcheck = true, + }, + }, + }, + rust_analyzer = {}, + ts_ls = {}, +} + + +local lspconfig = require('lspconfig') +for server, config in pairs(servers) do + config.capabilities = capabilities + lspconfig[server].setup(config) +end + +vim.diagnostic.config({ + virtual_text = { source = "if_many" }, + underline = true, + severity_sort = true, +}) -- cgit v1.3.1