diff --git a/common/home/neovim/base.lua b/common/home/neovim/base.lua deleted file mode 100644 index 28bb740..0000000 --- a/common/home/neovim/base.lua +++ /dev/null @@ -1,2 +0,0 @@ --- Add `:Format` command to format current buffer -vim.api.nvim_create_user_command("Format", "call CocAction('format')", {}) diff --git a/common/home/neovim/base.vim b/common/home/neovim/base.vim deleted file mode 100644 index 1afcffb..0000000 --- a/common/home/neovim/base.vim +++ /dev/null @@ -1,34 +0,0 @@ -" by default, the indent is 2 spaces. -set smartindent -set expandtab -set shiftwidth=2 -set softtabstop=2 -set tabstop=2 - -" for html/rb files, 2 spaces -autocmd Filetype html setlocal ts=2 sw=2 expandtab -autocmd Filetype ruby setlocal ts=2 sw=2 expandtab - -" for js/coffee/jade files, 4 spaces -autocmd Filetype javascript setlocal ts=4 sw=4 sts=0 expandtab -autocmd Filetype typescript setlocal ts=4 sw=4 sts=0 expandtab -autocmd Filetype java setlocal ts=4 sw=4 sts=0 expandtab -autocmd Filetype sh setlocal ts=4 sw=4 sts=0 expandtab -autocmd Filetype hyprlang setlocal ts=4 sw=4 sts=0 expandtab - -" support scss @ -autocmd FileType scss setl iskeyword+=@-@ - -set number -set relativenumber - -" TODO: make this work for nix-on-droid -set undofile -set undodir=/home/matt/.cache/nvim/ - -" remove highlight on words -nnoremap :noh - -" Always show the signcolumn, otherwise it would shift the text each time -" diagnostics appear/become resolved -set signcolumn=yes diff --git a/common/home/neovim/coc.nix b/common/home/neovim/coc.nix new file mode 100644 index 0000000..1196584 --- /dev/null +++ b/common/home/neovim/coc.nix @@ -0,0 +1,58 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (config.vars) neovimIde; + inherit (lib) fileContents; + inherit (pkgs) vimPlugins; +in + lib.mkIf neovimIde { + programs = { + neovim = { + coc = { + enable = true; + settings = { + colors.enable = true; + coc.preferences.formatOnType = true; + diagnostic.checkCurrentLine = true; + inlayHint.enable = false; + }; + }; + + extraLuaConfig = + /* + lua + */ + '' + vim.api.nvim_create_autocmd("FileType", { + pattern = 'hyprlang', + command = 'setlocal ts=4 sw=4 sts=0 expandtab', + }); + + vim.api.nvim_create_user_command("Format", "call CocAction('format')", {}); + + -- Always show the signcolumn, otherwise it would shift the text each time + -- diagnostics appear/become resolved + vim.opt.signcolumn = 'yes'; + ''; + + plugins = [ + { + plugin = vimPlugins.coc-snippets; + type = "viml"; + config = fileContents ./plugins/snippets.vim; + } + + ## Fzf + vimPlugins.coc-fzf + + vimPlugins.coc-highlight + vimPlugins.coc-json + vimPlugins.coc-yaml + vimPlugins.coc-toml + ]; + }; + }; + } diff --git a/common/home/neovim/default.nix b/common/home/neovim/default.nix index af6971b..b9a868b 100644 --- a/common/home/neovim/default.nix +++ b/common/home/neovim/default.nix @@ -2,216 +2,50 @@ config, pkgs, lib, - nvim-theme-src, - coc-stylelintplus, - nixd, - vimplugin-easytables-src, ... }: let - inherit (config.vars) hostName mainUser neovimIde; - inherit (lib) fileContents hasPrefix optionalAttrs optionals removePrefix; + inherit (config.vars) neovimIde; + inherit (lib) fileContents optionals; inherit (pkgs) vimPlugins; - - buildPlugin = pname: src: - pkgs.vimUtils.buildVimPlugin { - inherit pname src; - version = src.shortRev; - }; - - javaSdk = pkgs.temurin-bin-17; - coc-stylelintplus-flake = coc-stylelintplus.packages.${pkgs.system}.default; - nixdPkg = nixd.packages.${pkgs.system}.default; - - flakeEnv = config.programs.bash.sessionVariables.FLAKE; - flakeDir = "${removePrefix "/home/${mainUser}/" flakeEnv}"; in { - assertions = [ - { - assertion = neovimIde && hasPrefix "/home/${mainUser}/" flakeEnv || !neovimIde; - message = '' - Your $FLAKE environment variable needs to point to a directory in - the main users' home to use the neovim module. - ''; - } - ]; - imports = [ + ./coc.nix + ./langs + ./theme.nix ./treesitter.nix ]; - home = optionalAttrs neovimIde { - packages = with pkgs; [ - gradle - maven - alejandra - - # FIXME: set nixd to use alejandra - (writeShellApplication { - name = "nixpkgs-fmt"; - runtimeInputs = [alejandra]; - text = "alejandra \"$@\""; - }) - ]; - }; - - xdg.dataFile = optionalAttrs neovimIde { - ".gradle/gradle.properties".text = '' - org.gradle.java.home = ${javaSdk} - ''; - - "${flakeDir}/.nixd.json".text = builtins.toJSON { - nixpkgs = { - expr = "import (builtins.getFlake \"${flakeDir}\").inputs.nixpkgs {}"; - }; - options.nixos = { - expr = "(builtins.getFlake \"${flakeDir}\").nixosConfigurations.${hostName}.options"; - }; - }; - }; - programs = { - java = optionalAttrs neovimIde { - enable = true; - package = javaSdk; - }; - - # I love doing typos - bash.shellAliases = { - nivm = "nvim"; - nivim = "nvim"; - }; - neovim = { enable = true; - withNodeJs = true; - withPython3 = true; - withRuby = false; - defaultEditor = true; - viAlias = true; - vimAlias = true; + extraLuaConfig = + /* + lua + */ + '' + -- by default, the indent is 2 spaces. + vim.opt.smartindent = true; + vim.opt.expandtab = true; + vim.opt.shiftwidth = 2; + vim.opt.softtabstop = 2; + vim.opt.tabstop = 2; - extraPackages = - (with pkgs; [ - bat - gcc - ]) - ++ (optionals neovimIde [ - nixdPkg - ] - ++ (with pkgs; [ - clang-tools - nodejs_latest - nodePackages.npm - nodePackages.neovim - gradle - ])); + vim.opt.number = true; + vim.opt.relativenumber = true; - extraPython3Packages = ps: - optionals neovimIde [ - ps.pylint - ]; + vim.opt.undofile = true; + vim.opt.undodir = '${config.xdg.cacheHome}/nvim/'; - coc = optionalAttrs neovimIde { - enable = true; - settings = { - # General - colors.enable = true; - coc.preferences.formatOnType = true; - diagnostic.checkCurrentLine = true; - inlayHint.enable = false; - - # ESLint - eslint = { - format.enable = true; - autoFixOnSave = true; - }; - - # Stylelint - stylelintplus = { - enable = true; - cssInJs = true; - autoFixOnSave = true; - autoFixOnFormat = true; - }; - css.validate = false; - less.validate = false; - scss.validate = false; - wxss.validate = false; - - # Lua - Lua = { - misc.parameters = [ - "--metapath" - "~/.cache/sumneko_lua/meta" - "--logpath" - "~/.cache/sumneko_lua/log" - ]; - workspace.library = [ - "$\{3rd\}/luv/library" - ]; - }; - sumneko-lua = { - serverDir = "${pkgs.lua-language-server}/share/lua-language-server"; - enableNvimLuaDev = true; - }; - - languageserver = { - # Nix - nix = { - command = "nixd"; - filetypes = ["nix"]; - }; - }; - - # Java - java = { - maven.downloadSources = true; - eclipse.downloadSources = true; - - format.settings.url = "eclipse-formatter.xml"; - - jdt.ls = { - java.home = "${javaSdk}"; - statusIcons = { - "busy" = "Busy"; - "ready" = "OK"; - "warning" = "Warning"; - "error" = "Error"; - }; - }; - }; - - # Bash - bashIde.shellcheckPath = "${pkgs.shellcheck}/bin/shellcheck"; - - markdownlint.config = { - no-trailing-spaces = true; - no-multiple-blanks = false; - no-duplicate-heading = false; - line-length = { - tables = false; - }; - }; - }; - }; - - extraConfig = fileContents ./base.vim; - extraLuaConfig = fileContents ./base.lua; + -- remove highlight on words + vim.cmd[[nnoremap :noh]]; + ''; plugins = [ vimPlugins.fzfWrapper vimPlugins.fzf-vim vimPlugins.fugitive - - { - plugin = vimPlugins.dracula-nvim.overrideAttrs { - src = nvim-theme-src; - }; - type = "viml"; - config = fileContents ./plugins/dracula.vim; - } { plugin = vimPlugins.todo-comments-nvim; type = "lua"; @@ -219,18 +53,15 @@ in { /* lua */ - ''require('todo-comments').setup()''; + '' + require('todo-comments').setup(); + ''; } { plugin = vimPlugins.gitsigns-nvim; type = "lua"; config = fileContents ./plugins/gitsigns.lua; } - { - plugin = vimPlugins.indent-blankline-nvim; - type = "lua"; - config = fileContents ./plugins/indent.lua; - } { plugin = vimPlugins.mini-nvim; type = "lua"; @@ -239,72 +70,26 @@ in { { plugin = vimPlugins.codewindow-nvim; type = "lua"; - config = fileContents ./plugins/codewindow.lua; + config = + /* + lua + */ + '' + require('codewindow').setup({ + auto_enable = true, + minimap_width = 8, + relative = 'editor', + window_border = 'none', + }); + ''; } ] ++ optionals neovimIde [ - vimPlugins.markdown-preview-nvim - - # Coc configured - vimPlugins.coc-clangd - vimPlugins.coc-cmake - vimPlugins.coc-css - vimPlugins.coc-eslint - vimPlugins.coc-java - vimPlugins.coc-sh - coc-stylelintplus-flake - { - plugin = vimPlugins.coc-snippets; - type = "viml"; - config = fileContents ./plugins/snippets.vim; - } - - ## Lua - vimPlugins.coc-sumneko-lua - vimPlugins.neodev-nvim - - ## Fzf - vimPlugins.coc-fzf - - vimPlugins.coc-highlight - vimPlugins.coc-json - vimPlugins.coc-pyright - vimPlugins.coc-vimlsp - vimPlugins.coc-yaml - vimPlugins.coc-toml - vimPlugins.coc-markdownlint - vimPlugins.coc-tsserver - { plugin = vimPlugins.nvim-autopairs; type = "lua"; config = fileContents ./plugins/autopairs.lua; } - { - plugin = vimPlugins.lualine-nvim; - type = "lua"; - config = fileContents ./plugins/lualine.lua; - } - { - plugin = vimPlugins.neo-tree-nvim; - type = "viml"; - config = '' - ${fileContents ./plugins/neotree.vim} - - lua << EOF - ${fileContents ./plugins/neotree.lua} - EOF - ''; - } - { - plugin = buildPlugin "easytables-nvim" vimplugin-easytables-src; - type = "lua"; - config = - /* - lua - */ - ''require('easytables').setup();''; - } ]; }; }; diff --git a/common/home/neovim/langs/bash.nix b/common/home/neovim/langs/bash.nix new file mode 100644 index 0000000..4b547ea --- /dev/null +++ b/common/home/neovim/langs/bash.nix @@ -0,0 +1,44 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (config.vars) neovimIde; + inherit (pkgs) vimPlugins; +in + lib.mkIf neovimIde { + programs = { + # I love doing typos + bash.shellAliases = { + nivm = "nvim"; + nivim = "nvim"; + }; + + neovim = { + defaultEditor = true; + viAlias = true; + vimAlias = true; + + extraLuaConfig = + /* + lua + */ + '' + vim.api.nvim_create_autocmd("FileType", { + pattern = 'sh', + command = 'setlocal ts=4 sw=4 sts=0 expandtab', + }); + ''; + + coc.settings = { + # Bash + bashIde.shellcheckPath = "${pkgs.shellcheck}/bin/shellcheck"; + }; + + plugins = [ + vimPlugins.coc-sh + ]; + }; + }; + } diff --git a/common/home/neovim/langs/clang.nix b/common/home/neovim/langs/clang.nix new file mode 100644 index 0000000..0dd2f2a --- /dev/null +++ b/common/home/neovim/langs/clang.nix @@ -0,0 +1,24 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (config.vars) neovimIde; + inherit (pkgs) vimPlugins; +in + lib.mkIf neovimIde { + programs = { + neovim = { + extraPackages = with pkgs; [ + gcc + clang-tools + ]; + + plugins = [ + vimPlugins.coc-clangd + vimPlugins.coc-cmake + ]; + }; + }; + } diff --git a/common/home/neovim/langs/default.nix b/common/home/neovim/langs/default.nix new file mode 100644 index 0000000..3f7fc85 --- /dev/null +++ b/common/home/neovim/langs/default.nix @@ -0,0 +1,12 @@ +{...}: { + imports = [ + ./bash.nix + ./clang.nix + ./java.nix + ./lua.nix + ./markdown.nix + ./nix.nix + ./python.nix + ./web.nix + ]; +} diff --git a/common/home/neovim/langs/java.nix b/common/home/neovim/langs/java.nix new file mode 100644 index 0000000..2efbae7 --- /dev/null +++ b/common/home/neovim/langs/java.nix @@ -0,0 +1,62 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (pkgs) vimPlugins; + inherit (config.vars) neovimIde; + + javaSdk = pkgs.temurin-bin-17; + javaPkgs = with pkgs; [gradle maven]; +in + lib.mkIf neovimIde { + home.packages = javaPkgs; + + xdg.dataFile.".gradle/gradle.properties".text = '' + org.gradle.java.home = ${javaSdk} + ''; + + programs = { + java = { + enable = true; + package = javaSdk; + }; + + neovim = { + extraPackages = javaPkgs; + + extraLuaConfig = + /* + lua + */ + '' + vim.api.nvim_create_autocmd("FileType", { + pattern = 'java', + command = 'setlocal ts=4 sw=4 sts=0 expandtab', + }); + ''; + + coc.settings.java = { + maven.downloadSources = true; + eclipse.downloadSources = true; + + format.settings.url = "eclipse-formatter.xml"; + + jdt.ls = { + java.home = "${javaSdk}"; + statusIcons = { + "busy" = "Busy"; + "ready" = "OK"; + "warning" = "Warning"; + "error" = "Error"; + }; + }; + }; + + plugins = [ + vimPlugins.coc-java + ]; + }; + }; + } diff --git a/common/home/neovim/langs/lua.nix b/common/home/neovim/langs/lua.nix new file mode 100644 index 0000000..b66134f --- /dev/null +++ b/common/home/neovim/langs/lua.nix @@ -0,0 +1,39 @@ +{ + config, + pkgs, + lib, + ... +}: let + inherit (config.vars) neovimIde; + inherit (pkgs) vimPlugins; +in + lib.mkIf neovimIde { + programs = { + neovim = { + coc.settings = { + Lua = { + misc.parameters = [ + "--metapath" + "~/.cache/sumneko_lua/meta" + "--logpath" + "~/.cache/sumneko_lua/log" + ]; + workspace.library = [ + "$\{3rd\}/luv/library" + ]; + }; + sumneko-lua = { + serverDir = "${pkgs.lua-language-server}/share/lua-language-server"; + enableNvimLuaDev = true; + }; + }; + + plugins = [ + vimPlugins.coc-sumneko-lua + vimPlugins.neodev-nvim + + vimPlugins.coc-vimlsp + ]; + }; + }; + } diff --git a/common/home/neovim/langs/markdown.nix b/common/home/neovim/langs/markdown.nix new file mode 100644 index 0000000..6435065 --- /dev/null +++ b/common/home/neovim/langs/markdown.nix @@ -0,0 +1,48 @@ +{ + config, + pkgs, + lib, + vimplugin-easytables-src, + ... +}: let + inherit (config.vars) neovimIde; + inherit (pkgs) vimPlugins; + + buildPlugin = pname: src: + pkgs.vimUtils.buildVimPlugin { + inherit pname src; + version = src.shortRev; + }; +in + lib.mkIf neovimIde { + programs = { + neovim = { + coc.settings = { + markdownlint.config = { + no-trailing-spaces = true; + no-multiple-blanks = false; + no-duplicate-heading = false; + line-length = { + tables = false; + }; + }; + }; + + plugins = [ + vimPlugins.markdown-preview-nvim + vimPlugins.coc-markdownlint + { + plugin = buildPlugin "easytables-nvim" vimplugin-easytables-src; + type = "lua"; + config = + /* + lua + */ + '' + require('easytables').setup(); + ''; + } + ]; + }; + }; + } diff --git a/common/home/neovim/langs/nix.nix b/common/home/neovim/langs/nix.nix new file mode 100644 index 0000000..a78cb8a --- /dev/null +++ b/common/home/neovim/langs/nix.nix @@ -0,0 +1,61 @@ +{ + config, + pkgs, + lib, + nixd, + ... +}: let + inherit (config.vars) hostName mainUser neovimIde; + inherit (lib) hasPrefix removePrefix; + + nixdPkg = nixd.packages.${pkgs.system}.default; + + flakeEnv = config.programs.bash.sessionVariables.FLAKE; + flakeDir = "${removePrefix "/home/${mainUser}/" flakeEnv}"; +in + lib.mkIf neovimIde { + assertions = [ + { + assertion = neovimIde && hasPrefix "/home/${mainUser}/" flakeEnv || !neovimIde; + message = '' + Your $FLAKE environment variable needs to point to a directory in + the main users' home to use the neovim module. + ''; + } + ]; + + home.packages = with pkgs; [ + alejandra + + # FIXME: set nixd to use alejandra + (writeShellApplication { + name = "nixpkgs-fmt"; + runtimeInputs = [alejandra]; + text = "alejandra \"$@\""; + }) + ]; + + xdg.dataFile."${flakeDir}/.nixd.json".text = builtins.toJSON { + nixpkgs = { + expr = "import (builtins.getFlake \"${flakeDir}\").inputs.nixpkgs {}"; + }; + options.nixos = { + expr = "(builtins.getFlake \"${flakeDir}\").nixosConfigurations.${hostName}.options"; + }; + }; + + programs = { + neovim = { + extraPackages = [ + nixdPkg + ]; + + coc.settings.languageserver = { + nix = { + command = "nixd"; + filetypes = ["nix"]; + }; + }; + }; + }; + } diff --git a/common/home/neovim/langs/python.nix b/common/home/neovim/langs/python.nix new file mode 100644 index 0000000..1d563fd --- /dev/null +++ b/common/home/neovim/langs/python.nix @@ -0,0 +1,24 @@ +{ + config, + lib, + pkgs, + ... +}: let + inherit (config.vars) neovimIde; + inherit (pkgs) vimPlugins; +in + lib.mkIf neovimIde { + programs = { + neovim = { + withPython3 = true; + + extraPython3Packages = ps: [ + ps.pylint + ]; + + plugins = [ + vimPlugins.coc-pyright + ]; + }; + }; + } diff --git a/common/home/neovim/langs/web.nix b/common/home/neovim/langs/web.nix new file mode 100644 index 0000000..acc541b --- /dev/null +++ b/common/home/neovim/langs/web.nix @@ -0,0 +1,73 @@ +{ + config, + pkgs, + lib, + coc-stylelintplus, + ... +}: let + inherit (config.vars) neovimIde; + inherit (pkgs) vimPlugins; + + coc-stylelintplus-flake = coc-stylelintplus.packages.${pkgs.system}.default; +in + lib.mkIf neovimIde { + programs = { + neovim = { + withNodeJs = true; + + extraPackages = with pkgs; [ + nodejs_latest + nodePackages.npm + nodePackages.neovim + ]; + + extraLuaConfig = + /* + lua + */ + '' + vim.api.nvim_create_autocmd("FileType", { + pattern = { 'javascript' , 'typescript'}, + command = 'setlocal ts=4 sw=4 sts=0 expandtab', + }); + + vim.api.nvim_create_autocmd("FileType", { + pattern = 'html', + command = 'setlocal ts=2 sw=2 expandtab', + }); + + vim.api.nvim_create_autocmd("FileType", { + pattern = 'scss', + command = 'setl iskeyword+=@-@', + }); + ''; + + coc.settings = { + # ESLint + eslint = { + format.enable = true; + autoFixOnSave = true; + }; + + # Stylelint + stylelintplus = { + enable = true; + cssInJs = true; + autoFixOnSave = true; + autoFixOnFormat = true; + }; + css.validate = false; + less.validate = false; + scss.validate = false; + wxss.validate = false; + }; + + plugins = [ + vimPlugins.coc-css + vimPlugins.coc-eslint + coc-stylelintplus-flake + vimPlugins.coc-tsserver + ]; + }; + }; + } diff --git a/common/home/neovim/plugins/codewindow.lua b/common/home/neovim/plugins/codewindow.lua deleted file mode 100644 index d515f42..0000000 --- a/common/home/neovim/plugins/codewindow.lua +++ /dev/null @@ -1,6 +0,0 @@ -require('codewindow').setup({ - auto_enable = true, - minimap_width = 8, - relative = 'editor', - window_border = 'none', -}); diff --git a/common/home/neovim/plugins/dracula.vim b/common/home/neovim/plugins/dracula.vim deleted file mode 100644 index 255b918..0000000 --- a/common/home/neovim/plugins/dracula.vim +++ /dev/null @@ -1,10 +0,0 @@ -" set dot icon in place of trailing whitespaces -set list listchars=tab:\ \ ,nbsp:␣,trail:•,extends:⟩,precedes:⟨ - - -lua << EOF --- Add visual indicator for trailing whitespaces -vim.opt.fillchars = {eob = " "} - -vim.cmd[[colorscheme dracula]] -EOF diff --git a/common/home/neovim/plugins/lualine.lua b/common/home/neovim/plugins/lualine.lua deleted file mode 100644 index d9a4ad9..0000000 --- a/common/home/neovim/plugins/lualine.lua +++ /dev/null @@ -1,9 +0,0 @@ -require('lualine').setup({ - options = { - theme = 'dracula', - globalstatus = true, - }, - sections = { - lualine_x = {'g:coc_status', 'bo:filetype'}, - } -}) diff --git a/common/home/neovim/theme.nix b/common/home/neovim/theme.nix new file mode 100644 index 0000000..17e418b --- /dev/null +++ b/common/home/neovim/theme.nix @@ -0,0 +1,79 @@ +{ + config, + pkgs, + lib, + nvim-theme-src, + ... +}: let + inherit (config.vars) neovimIde; + inherit (lib) fileContents optionals; + inherit (pkgs) vimPlugins; +in { + programs = { + neovim = { + extraPackages = with pkgs; [ + bat + ]; + + plugins = + [ + { + plugin = vimPlugins.dracula-nvim.overrideAttrs { + src = nvim-theme-src; + }; + type = "lua"; + config = + /* + lua + */ + '' + -- set dot icon in place of trailing whitespaces + vim.cmd[[set list listchars=tab:\ \ ,nbsp:␣,trail:•,extends:⟩,precedes:⟨]] + + -- Add visual indicator for trailing whitespaces + vim.opt.fillchars = {eob = " "} + + vim.cmd[[colorscheme dracula]] + ''; + } + { + plugin = vimPlugins.indent-blankline-nvim; + type = "lua"; + config = fileContents ./plugins/indent.lua; + } + ] + ++ optionals neovimIde [ + { + plugin = vimPlugins.lualine-nvim; + type = "lua"; + config = + /* + lua + */ + '' + require('lualine').setup({ + options = { + theme = 'dracula', + globalstatus = true, + }, + sections = { + lualine_x = { 'g:coc_status', 'bo:filetype' }, + }, + }); + ''; + } + { + plugin = vimPlugins.neo-tree-nvim; + type = "viml"; + config = '' + ${fileContents ./plugins/neotree.vim} + + lua << EOF + ${fileContents ./plugins/neotree.lua} + EOF + ''; + } + ]; + }; + }; +} diff --git a/common/home/neovim/treesitter.nix b/common/home/neovim/treesitter.nix index 18a0c04..e4d29ff 100644 --- a/common/home/neovim/treesitter.nix +++ b/common/home/neovim/treesitter.nix @@ -19,7 +19,7 @@ in { }); vim.cmd( - 'hi TreesitterContextBottom gui=underline guisp=Grey' + 'hi TreesitterContextBottom gui=underline guisp=Grey' ); ''; }