From 65cc61773f5409c92d5494b10296c80109b30743 Mon Sep 17 00:00:00 2001 From: Martin Pander Date: Tue, 10 Feb 2026 22:00:42 +0100 Subject: [PATCH] Refactore nvim config --- nix/hosts/work/common.nix | 1 + nix/modules/home/nvim.nix | 171 +++++++++++++++++++----------------- nvim/init.lua | 7 ++ nvim/{ => lua}/base.lua | 0 nvim/{ => lua}/filetype.lua | 0 nvim/{ => lua}/keymaps.lua | 0 nvim/{ => lua}/plugins.lua | 8 +- 7 files changed, 100 insertions(+), 87 deletions(-) create mode 100644 nvim/init.lua rename nvim/{ => lua}/base.lua (100%) rename nvim/{ => lua}/filetype.lua (100%) rename nvim/{ => lua}/keymaps.lua (100%) rename nvim/{ => lua}/plugins.lua (98%) diff --git a/nix/hosts/work/common.nix b/nix/hosts/work/common.nix index 9031385..d4655ed 100644 --- a/nix/hosts/work/common.nix +++ b/nix/hosts/work/common.nix @@ -22,4 +22,5 @@ }; dot.tmux.workMode = true; + dot.nvim.workMode = true; } diff --git a/nix/modules/home/nvim.nix b/nix/modules/home/nvim.nix index 14438a0..05b0098 100644 --- a/nix/modules/home/nvim.nix +++ b/nix/modules/home/nvim.nix @@ -1,87 +1,96 @@ { config, pkgs, lib, ... }: +let + cfg = config.dot.nvim; +in { - programs.neovim = { - enable = true; - - defaultEditor = true; - vimAlias = true; - - plugins = with pkgs.vimPlugins; [ - vim-repeat - vim-surround - ts-comments-nvim - vim-fugitive - gitsigns-nvim - nvim-tree-lua - targets-vim - mini-pairs - mini-align - mini-bracketed - mini-splitjoin - mini-move - mini-ai - mini-icons - flash-nvim - trouble-nvim - conform-nvim - nvim-lint - promise-async - nvim-ufo - vim-windowswap - plenary-nvim - telescope-nvim - telescope-fzf-native-nvim - telescope-ui-select-nvim - yanky-nvim - lualine-nvim - undotree - luasnip - nvim-cmp - cmp_luasnip - cmp-buffer - cmp-path - cmp-cmdline - cmp-nvim-lsp - cmp-nvim-lsp-signature-help - cmp_yanky - cmp-git - nvim-lspconfig - lspkind-nvim - copilot-lua - copilot-cmp - CopilotChat-nvim - bullets-vim - nvim-dap - nvim-nio - nvim-dap-ui - nvim-dap-virtual-text - nvim-dap-go - nvim-dap-python - nvim-dap-lldb - todo-comments-nvim - vim-markdown - zen-mode-nvim - plantuml-syntax - obsidian-nvim - render-markdown-nvim - image-nvim - img-clip-nvim - vim-nix - (nvim-treesitter.withPlugins (p: [ p.awk p.bash p.c p.c_sharp p.cpp p.css p.diff p.dockerfile p.doxygen p.git_config p.gitcommit p.go p.gomod p.gosum p.gotmpl p.helm p.haskell p.html p.http p.java p.javascript p.json p.latex p.lua p.markdown p.markdown_inline p.matlab p.nix p.printf p.python p.regex p.rust p.sql p.strace p.supercollider p.svelte p.swift p.terraform p.tmux p.toml p.typescript p.vim p.xml p.yaml p.zig ])) - ]; - - # Use extraLuaConfig for home-manager 25.11 compatibility - # (initLua was renamed from extraLuaConfig in later versions) - extraLuaConfig = builtins.concatStringsSep "\n" [ - (lib.strings.fileContents ../../../nvim/base.lua) - (lib.strings.fileContents ../../../nvim/keymaps.lua) - (lib.strings.fileContents ../../../nvim/plugins.lua) - (lib.strings.fileContents ../../../nvim/filetype.lua) - ]; + options.dot.nvim = { + workMode = lib.mkEnableOption "work-specific neovim configuration"; }; - home.packages = with pkgs; [ - nodejs-slim - ]; + config = { + programs.neovim = { + enable = true; + + defaultEditor = true; + vimAlias = true; + + plugins = with pkgs.vimPlugins; [ + vim-repeat + vim-surround + ts-comments-nvim + vim-fugitive + gitsigns-nvim + nvim-tree-lua + targets-vim + mini-pairs + mini-align + mini-bracketed + mini-splitjoin + mini-move + mini-ai + mini-icons + flash-nvim + trouble-nvim + conform-nvim + nvim-lint + promise-async + nvim-ufo + vim-windowswap + plenary-nvim + telescope-nvim + telescope-fzf-native-nvim + telescope-ui-select-nvim + yanky-nvim + lualine-nvim + undotree + luasnip + nvim-cmp + cmp_luasnip + cmp-buffer + cmp-path + cmp-cmdline + cmp-nvim-lsp + cmp-nvim-lsp-signature-help + cmp_yanky + cmp-git + nvim-lspconfig + lspkind-nvim + copilot-lua + copilot-cmp + CopilotChat-nvim + bullets-vim + nvim-dap + nvim-nio + nvim-dap-ui + nvim-dap-virtual-text + nvim-dap-go + nvim-dap-python + nvim-dap-lldb + todo-comments-nvim + vim-markdown + zen-mode-nvim + plantuml-syntax + obsidian-nvim + render-markdown-nvim + image-nvim + img-clip-nvim + vim-nix + (nvim-treesitter.withPlugins (p: [ p.awk p.bash p.c p.c_sharp p.cpp p.css p.diff p.dockerfile p.doxygen p.git_config p.gitcommit p.go p.gomod p.gosum p.gotmpl p.helm p.haskell p.html p.http p.java p.javascript p.json p.latex p.lua p.markdown p.markdown_inline p.matlab p.nix p.printf p.python p.regex p.rust p.sql p.strace p.supercollider p.svelte p.swift p.terraform p.tmux p.toml p.typescript p.vim p.xml p.yaml p.zig ])) + ]; + + extraLuaConfig = '' + _G.is_work = ${if cfg.workMode then "true" else "false"} + _G.is_mac = ${if pkgs.stdenv.isDarwin then "true" else "false"} + ''; + }; + + # Symlink the nvim directory to ~/.config/nvim + # This allows for editing the config without a nix rebuild + xdg.configFile."nvim".source = config.lib.file.mkOutOfStoreSymlink "${config.home.homeDirectory}/dev/dot/nvim"; + + home.packages = with pkgs; [ + nodejs-slim + ]; + }; } diff --git a/nvim/init.lua b/nvim/init.lua new file mode 100644 index 0000000..44fae22 --- /dev/null +++ b/nvim/init.lua @@ -0,0 +1,7 @@ +-- init.lua +-- This file is managed by Nix, but requires standard Lua modules from the lua/ directory + +require('base') +require('keymaps') +require('plugins') +require('filetype') diff --git a/nvim/base.lua b/nvim/lua/base.lua similarity index 100% rename from nvim/base.lua rename to nvim/lua/base.lua diff --git a/nvim/filetype.lua b/nvim/lua/filetype.lua similarity index 100% rename from nvim/filetype.lua rename to nvim/lua/filetype.lua diff --git a/nvim/keymaps.lua b/nvim/lua/keymaps.lua similarity index 100% rename from nvim/keymaps.lua rename to nvim/lua/keymaps.lua diff --git a/nvim/plugins.lua b/nvim/lua/plugins.lua similarity index 98% rename from nvim/plugins.lua rename to nvim/lua/plugins.lua index 1d73bd4..1f394f4 100644 --- a/nvim/plugins.lua +++ b/nvim/lua/plugins.lua @@ -10,10 +10,6 @@ require('mini.move').setup() require('flash').setup() require('ts-comments').setup() -local function is_wsl_env() - return os.getenv("WSL_DISTRO_NAME") ~= nil or os.getenv("WSL_INTEROP") ~= nil -end - vim.g.tagbar_left=1 vim.g.tagbar_autoclose=1 vim.g.tagbar_autofocus=1 @@ -381,7 +377,7 @@ dap.configurations.zig = { }, } -if vim.fn.has("mac") then +if _G.is_mac then workspaces = { { name = "privat", @@ -400,7 +396,7 @@ if vim.fn.has("mac") then } end -if is_wsl_env() then +if _G.is_work then workspaces = { { name = "work",