From 0f627107cee4262aba2765e5dd08593d2662d055 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 21 Dec 2024 23:34:10 -0500 Subject: [PATCH] refactor(nvim): add _file and config attrs to all submodules --- configurations/binto/default.nix | 1 - configurations/cluster/default.nix | 1 - configurations/homie/default.nix | 1 - configurations/live-image/default.nix | 1 - configurations/nos/default.nix | 1 - configurations/servivi/default.nix | 1 - configurations/wim/default.nix | 1 - homeManagerModules/neovim/default.nix | 154 +++++++++--------- .../neovim/langs/bash/default.nix | 80 ++++----- .../neovim/langs/c-lang/default.nix | 6 +- .../neovim/langs/csharp/default.nix | 4 +- homeManagerModules/neovim/langs/default.nix | 9 +- .../neovim/langs/hyprlang/default.nix | 10 +- .../neovim/langs/java/default.nix | 10 +- .../neovim/langs/json/default.nix | 11 +- .../neovim/langs/lua/default.nix | 14 +- .../neovim/langs/markdown/default.nix | 6 +- .../neovim/langs/nix-lang/default.nix | 9 +- .../neovim/langs/python/default.nix | 24 +-- .../neovim/langs/rust/default.nix | 10 +- .../neovim/langs/web/default.nix | 4 +- homeManagerModules/neovim/theme/default.nix | 20 +-- .../neovim/theme/treesitter.nix | 74 +++++---- 23 files changed, 243 insertions(+), 209 deletions(-) diff --git a/configurations/binto/default.nix b/configurations/binto/default.nix index fcde4bb8..a7f90ae0 100644 --- a/configurations/binto/default.nix +++ b/configurations/binto/default.nix @@ -87,7 +87,6 @@ neovim = { enable = true; - enableIde = true; user = mainUser; }; }; diff --git a/configurations/cluster/default.nix b/configurations/cluster/default.nix index df99d166..ba3e52c4 100644 --- a/configurations/cluster/default.nix +++ b/configurations/cluster/default.nix @@ -84,7 +84,6 @@ in { neovim = { enable = true; - enableIde = true; user = mainUser; }; }; diff --git a/configurations/homie/default.nix b/configurations/homie/default.nix index 48e249f5..bb028706 100644 --- a/configurations/homie/default.nix +++ b/configurations/homie/default.nix @@ -70,7 +70,6 @@ neovim = { enable = true; - enableIde = true; user = mainUser; }; }; diff --git a/configurations/live-image/default.nix b/configurations/live-image/default.nix index d7231949..e4ab4308 100644 --- a/configurations/live-image/default.nix +++ b/configurations/live-image/default.nix @@ -43,7 +43,6 @@ neovim = { enable = true; - enableIde = true; user = mainUser; }; }; diff --git a/configurations/nos/default.nix b/configurations/nos/default.nix index 1c842c44..836271a5 100644 --- a/configurations/nos/default.nix +++ b/configurations/nos/default.nix @@ -70,7 +70,6 @@ neovim = { enable = true; - enableIde = true; user = mainUser; }; }; diff --git a/configurations/servivi/default.nix b/configurations/servivi/default.nix index ffa90b24..469d3aff 100644 --- a/configurations/servivi/default.nix +++ b/configurations/servivi/default.nix @@ -84,7 +84,6 @@ neovim = { enable = true; - enableIde = true; user = mainUser; }; }; diff --git a/configurations/wim/default.nix b/configurations/wim/default.nix index ba14efdf..e6d8a88c 100644 --- a/configurations/wim/default.nix +++ b/configurations/wim/default.nix @@ -106,7 +106,6 @@ neovim = { enable = true; - enableIde = true; user = mainUser; }; }; diff --git a/homeManagerModules/neovim/default.nix b/homeManagerModules/neovim/default.nix index d68baea1..f0054bc2 100644 --- a/homeManagerModules/neovim/default.nix +++ b/homeManagerModules/neovim/default.nix @@ -4,7 +4,9 @@ self: { pkgs, ... }: let - inherit (lib) mkOption types; + inherit (lib) mkIf mkOption types; + + cfg = config.programs.neovim; in { imports = [ ./git @@ -17,94 +19,92 @@ in { user = mkOption { type = types.str; }; - enableIde = mkOption { - type = types.bool; - default = false; - }; }; - config.programs.neovim = { - 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; + config = mkIf cfg.enable { + programs.neovim = { + 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; - vim.opt.number = true; - vim.opt.relativenumber = true; + vim.opt.number = true; + vim.opt.relativenumber = true; - vim.opt.undofile = true; - vim.opt.undodir = '${config.xdg.cacheHome}/nvim/'; + vim.opt.undofile = true; + vim.opt.undodir = '${config.xdg.cacheHome}/nvim/'; - -- Always show the signcolumn, otherwise it would shift - -- the text each time diagnostics appear/become resolved - vim.opt.signcolumn = 'yes'; + -- Always show the signcolumn, otherwise it would shift + -- the text each time diagnostics appear/become resolved + vim.opt.signcolumn = 'yes'; - -- remove highlight on words - vim.keymap.set('n', '', ':noh', { - noremap = true, - silent = true, - }); + -- remove highlight on words + vim.keymap.set('n', '', ':noh', { + noremap = true, + silent = true, + }); - -- https://github.com/seblj/roslyn.nvim/issues/121#issuecomment-2544076963 - vim.opt.cmdheight = 2; - ''; + -- https://github.com/seblj/roslyn.nvim/issues/121#issuecomment-2544076963 + vim.opt.cmdheight = 2; + ''; - plugins = [ - pkgs.vimPlugins.fzfWrapper - pkgs.vimPlugins.fzf-vim + plugins = [ + pkgs.vimPlugins.fzfWrapper + pkgs.vimPlugins.fzf-vim - { - plugin = pkgs.vimPlugins.todo-comments-nvim; - type = "lua"; - config = - # lua - '' - require('todo-comments').setup(); - ''; - } - { - plugin = pkgs.vimPlugins.mini-nvim; - type = "lua"; - config = - # lua - '' - -- TODO: see how this works - local ts_input = require('mini.surround').gen_spec.input.treesitter; + { + plugin = pkgs.vimPlugins.todo-comments-nvim; + type = "lua"; + config = + # lua + '' + require('todo-comments').setup(); + ''; + } + { + plugin = pkgs.vimPlugins.mini-nvim; + type = "lua"; + config = + # lua + '' + -- TODO: see how this works + local ts_input = require('mini.surround').gen_spec.input.treesitter; - require('mini.surround').setup({ - custom_surroundings = { - -- Use tree-sitter to search for function call - f = { - input = ts_input({ - outer = '@call.outer', - inner = '@call.inner', - }); - }, - }, - }); - ''; - } + require('mini.surround').setup({ + custom_surroundings = { + -- Use tree-sitter to search for function call + f = { + input = ts_input({ + outer = '@call.outer', + inner = '@call.inner', + }); + }, + }, + }); + ''; + } - { - plugin = pkgs.vimPlugins.nvim-config-local; - type = "lua"; - config = - # lua - '' - require('config-local').setup({ - config_files = { '.nvim.lua', '.nvimrc', '.exrc' }, + { + plugin = pkgs.vimPlugins.nvim-config-local; + type = "lua"; + config = + # lua + '' + require('config-local').setup({ + config_files = { '.nvim.lua', '.nvimrc', '.exrc' }, - -- Where the plugin keeps files data - hashfile = '${config.xdg.cacheHome}/nvim/config-local', - }); - ''; - } - ]; + -- Where the plugin keeps files data + hashfile = '${config.xdg.cacheHome}/nvim/config-local', + }); + ''; + } + ]; + }; }; # For accurate stack trace diff --git a/homeManagerModules/neovim/langs/bash/default.nix b/homeManagerModules/neovim/langs/bash/default.nix index d4215ba8..3e4167f2 100644 --- a/homeManagerModules/neovim/langs/bash/default.nix +++ b/homeManagerModules/neovim/langs/bash/default.nix @@ -8,51 +8,55 @@ cfg = config.programs.neovim; in { - programs = mkIf cfg.enable { - # I love doing typos - bash.shellAliases = { - nivm = "nvim"; - nivim = "nvim"; - }; + config = mkIf cfg.enable { + programs = { + # I love doing typos + bash.shellAliases = { + nivm = "nvim"; + nivim = "nvim"; + }; - neovim = { - defaultEditor = true; - viAlias = true; - vimAlias = true; + neovim = { + defaultEditor = true; + viAlias = true; + vimAlias = true; - extraPackages = mkIf cfg.enableIde (attrValues { - inherit - (pkgs.nodePackages) - bash-language-server - ; + extraPackages = attrValues { + inherit + (pkgs.nodePackages) + bash-language-server + ; - inherit - (pkgs) - shellcheck - ; - }); + inherit + (pkgs) + shellcheck + ; + }; - extraLuaConfig = - mkIf cfg.enableIde - # lua - '' - vim.api.nvim_create_autocmd('FileType', { - pattern = 'sh', - command = 'setlocal ts=4 sw=4 sts=0 expandtab', - }); + extraLuaConfig = + # lua + '' + vim.api.nvim_create_autocmd('FileType', { + pattern = 'sh', + command = 'setlocal ts=4 sw=4 sts=0 expandtab', + }); - local default_capabilities = require('cmp_nvim_lsp').default_capabilities(); + local default_capabilities = require('cmp_nvim_lsp').default_capabilities(); - require('lspconfig').bashls.setup({ - capabilities = default_capabilities, + require('lspconfig').bashls.setup({ + capabilities = default_capabilities, - settings = { - bashIde = { - shellcheckPath = '${getExe pkgs.shellcheck}', - }, - }, - }); - ''; + settings = { + bashIde = { + shellcheckPath = '${getExe pkgs.shellcheck}', + }, + }, + }); + ''; + }; }; }; + + # For accurate stack trace + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/langs/c-lang/default.nix b/homeManagerModules/neovim/langs/c-lang/default.nix index ae4ca2dc..a0557f48 100644 --- a/homeManagerModules/neovim/langs/c-lang/default.nix +++ b/homeManagerModules/neovim/langs/c-lang/default.nix @@ -9,7 +9,7 @@ cfg = config.programs.neovim; in { - config = mkIf cfg.enableIde { + config = mkIf cfg.enable { xdg.configFile."clangd/config.yaml".source = writeYAML "config.yaml" { CompileFlags.Add = ["-D__cpp_concepts=202002L"]; }; @@ -21,6 +21,7 @@ in { '' vim.api.nvim_create_autocmd('FileType', { pattern = { 'cpp', 'c' }, + -- FIXME: load direnv here https://github.com/actionshrimp/direnv.nvim?tab=readme-ov-file#using-nvim-lspconfig command = 'setlocal ts=4 sw=4 sts=0 expandtab', }); ''; @@ -57,4 +58,7 @@ in { }; }; }; + + # For accurate stack trace + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/langs/csharp/default.nix b/homeManagerModules/neovim/langs/csharp/default.nix index a83256dc..f38c05f4 100644 --- a/homeManagerModules/neovim/langs/csharp/default.nix +++ b/homeManagerModules/neovim/langs/csharp/default.nix @@ -10,7 +10,7 @@ self: { cfg = config.programs.neovim; in { - config = mkIf cfg.enableIde { + config = mkIf cfg.enable { programs = { neovim = { extraPackages = attrValues { @@ -73,5 +73,5 @@ in { }; # For accurate stack trace - _file = ./csharp.nix; + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/langs/default.nix b/homeManagerModules/neovim/langs/default.nix index 76b17290..539c428b 100644 --- a/homeManagerModules/neovim/langs/default.nix +++ b/homeManagerModules/neovim/langs/default.nix @@ -1,9 +1,12 @@ self: { + config, lib, pkgs, ... }: let - inherit (lib) fileContents mkBefore; + inherit (lib) fileContents mkBefore mkIf; + + cfg = config.programs.neovim; in { imports = [ ./bash @@ -21,8 +24,8 @@ in { (import ./web self) ]; - config.programs = { - neovim = { + config = mkIf cfg.enable { + programs.neovim = { extraLuaConfig = mkBefore # lua diff --git a/homeManagerModules/neovim/langs/hyprlang/default.nix b/homeManagerModules/neovim/langs/hyprlang/default.nix index a12c6013..95b68a07 100644 --- a/homeManagerModules/neovim/langs/hyprlang/default.nix +++ b/homeManagerModules/neovim/langs/hyprlang/default.nix @@ -6,8 +6,8 @@ inherit (lib) mkIf; cfg = config.programs.neovim; -in - mkIf cfg.enableIde { +in { + config = mkIf cfg.enable { programs = { neovim = { extraLuaConfig = @@ -24,4 +24,8 @@ in ''; }; }; - } + }; + + # For accurate stack trace + _file = ./default.nix; +} diff --git a/homeManagerModules/neovim/langs/java/default.nix b/homeManagerModules/neovim/langs/java/default.nix index ff9c8291..b0a7d24d 100644 --- a/homeManagerModules/neovim/langs/java/default.nix +++ b/homeManagerModules/neovim/langs/java/default.nix @@ -10,8 +10,8 @@ javaSdk = pkgs.temurin-bin-17; javaPkgs = attrValues {inherit (pkgs) gradle maven;}; -in - mkIf cfg.enableIde { +in { + config = mkIf cfg.enable { home.packages = javaPkgs; xdg.dataFile.".gradle/gradle.properties".text = '' @@ -81,4 +81,8 @@ in ]; }; }; - } + }; + + # For accurate stack trace + _file = ./default.nix; +} diff --git a/homeManagerModules/neovim/langs/json/default.nix b/homeManagerModules/neovim/langs/json/default.nix index 39ea78e3..93d45405 100644 --- a/homeManagerModules/neovim/langs/json/default.nix +++ b/homeManagerModules/neovim/langs/json/default.nix @@ -7,8 +7,8 @@ inherit (lib) attrValues mkIf; cfg = config.programs.neovim; -in - mkIf cfg.enableIde { +in { + config = mkIf cfg.enable { programs = { neovim = { extraPackages = attrValues { @@ -26,6 +26,7 @@ in pattern = 'yaml', command = 'setlocal ts=4 sw=4 sts=0 expandtab', }); + vim.api.nvim_create_autocmd('FileType', { pattern = 'json', command = 'setlocal ts=4 sw=4 sts=0 expandtab', @@ -54,4 +55,8 @@ in ''; }; }; - } + }; + + # For accurate stack trace + _file = ./default.nix; +} diff --git a/homeManagerModules/neovim/langs/lua/default.nix b/homeManagerModules/neovim/langs/lua/default.nix index ff6371b6..fe43a8df 100644 --- a/homeManagerModules/neovim/langs/lua/default.nix +++ b/homeManagerModules/neovim/langs/lua/default.nix @@ -9,8 +9,8 @@ cfg = config.programs.neovim; flakeEnv = config.programs.bash.sessionVariables.FLAKE; -in - mkIf cfg.enableIde { +in { + config = mkIf cfg.enable { programs = { neovim = { extraPackages = attrValues { @@ -38,8 +38,8 @@ in require("neodev").setup({ override = function(root_dir, library) if root_dir:find('${flakeEnv}', 1, true) == 1 then - library.enabled = true - library.plugins = true + library.enabled = true; + library.plugins = true; end end, }); @@ -52,4 +52,8 @@ in ]; }; }; - } + }; + + # For accurate stack trace + _file = ./default.nix; +} diff --git a/homeManagerModules/neovim/langs/markdown/default.nix b/homeManagerModules/neovim/langs/markdown/default.nix index 2c0eccee..da1544ea 100644 --- a/homeManagerModules/neovim/langs/markdown/default.nix +++ b/homeManagerModules/neovim/langs/markdown/default.nix @@ -19,9 +19,7 @@ self: { hash = "sha256-deQvQOOyK6iP7kjVrgEdFTyOP80RWXMrETs6gi7DTmo="; }; in { - # live-server --quiet --browser=firefox --open=%outputfile% --watch=%outputfile% --wait=800 - - config = mkIf cfg.enableIde { + config = mkIf cfg.enable { programs = { neovim = { extraPackages = attrValues { @@ -165,5 +163,5 @@ in { }; # For accurate stack trace - _file = ./markdown.nix; + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/langs/nix-lang/default.nix b/homeManagerModules/neovim/langs/nix-lang/default.nix index bdf2f508..bc3f251a 100644 --- a/homeManagerModules/neovim/langs/nix-lang/default.nix +++ b/homeManagerModules/neovim/langs/nix-lang/default.nix @@ -18,13 +18,10 @@ self: { flakeEnv = config.programs.bash.sessionVariables.FLAKE; flakeDir = "${removePrefix "/home/${cfg.user}/" flakeEnv}"; in { - config = mkIf cfg.enableIde { + config = mkIf cfg.enable { assertions = [ { - assertion = - cfg.enableIde - && hasPrefix "/home/${cfg.user}/" flakeEnv - || !cfg.enableIde; + assertion = hasPrefix "/home/${cfg.user}/" flakeEnv; message = '' Your $FLAKE environment variable needs to point to a directory in the main users' home to use the neovim module. @@ -79,5 +76,5 @@ in { }; # For accurate stack trace - _file = ./nix.nix; + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/langs/python/default.nix b/homeManagerModules/neovim/langs/python/default.nix index 42b04114..d727afdd 100644 --- a/homeManagerModules/neovim/langs/python/default.nix +++ b/homeManagerModules/neovim/langs/python/default.nix @@ -7,23 +7,20 @@ inherit (lib) attrValues mkIf; cfg = config.programs.neovim; + + pythonPkgs = py: + (attrValues { + inherit (py) python-lsp-server; + }) + ++ py.python-lsp-server.optional-dependencies.all; in { - config = mkIf cfg.enableIde { + config = mkIf cfg.enable { programs = { neovim = { withPython3 = true; - extraPython3Packages = py: - (attrValues { - inherit (py) python-lsp-server; - }) - ++ py.python-lsp-server.optional-dependencies.all; - - extraPackages = - (attrValues { - inherit (pkgs.python3Packages) python-lsp-server; - }) - ++ pkgs.python3Packages.python-lsp-server.optional-dependencies.all; + extraPython3Packages = pythonPkgs; + extraPackages = pythonPkgs pkgs.python3Packages; extraLuaConfig = # lua @@ -45,4 +42,7 @@ in { }; }; }; + + # For accurate stack trace + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/langs/rust/default.nix b/homeManagerModules/neovim/langs/rust/default.nix index 77afcbbc..06c520e1 100644 --- a/homeManagerModules/neovim/langs/rust/default.nix +++ b/homeManagerModules/neovim/langs/rust/default.nix @@ -7,8 +7,8 @@ inherit (lib) attrValues mkIf; cfg = config.programs.neovim; -in - mkIf cfg.enableIde { +in { + config = mkIf cfg.enable { programs = { neovim = { extraPackages = attrValues { @@ -35,4 +35,8 @@ in ''; }; }; - } + }; + + # For accurate stack trace + _file = ./default.nix; +} diff --git a/homeManagerModules/neovim/langs/web/default.nix b/homeManagerModules/neovim/langs/web/default.nix index fc033030..414b725a 100644 --- a/homeManagerModules/neovim/langs/web/default.nix +++ b/homeManagerModules/neovim/langs/web/default.nix @@ -11,7 +11,7 @@ self: { cfg = config.programs.neovim; in { - config = mkIf cfg.enableIde { + config = mkIf cfg.enable { programs = { neovim = { withNodeJs = true; @@ -200,5 +200,5 @@ in { }; # For accurate stack trace - _file = ./web.nix; + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/theme/default.nix b/homeManagerModules/neovim/theme/default.nix index 47bc18df..b8327446 100644 --- a/homeManagerModules/neovim/theme/default.nix +++ b/homeManagerModules/neovim/theme/default.nix @@ -5,19 +5,19 @@ self: { ... }: let inherit (self.inputs) nvim-theme-src; - inherit (lib) attrValues fileContents optionals; + inherit (lib) attrValues fileContents mkIf; cfg = config.programs.neovim; in { imports = [./treesitter.nix]; - config.programs.neovim = { - extraPackages = attrValues { - inherit (pkgs) bat; - }; + config = mkIf cfg.enable { + programs.neovim = { + extraPackages = attrValues { + inherit (pkgs) bat; + }; - plugins = - [ + plugins = [ { plugin = pkgs.vimPlugins.dracula-nvim.overrideAttrs { src = nvim-theme-src; @@ -100,8 +100,7 @@ in { type = "lua"; config = fileContents ./config/heirline.lua; } - ] - ++ optionals cfg.enableIde [ + { plugin = pkgs.vimPlugins.neo-tree-nvim; type = "lua"; @@ -176,8 +175,9 @@ in { ''; } ]; + }; }; # For accurate stack trace - _file = ./theme.nix; + _file = ./default.nix; } diff --git a/homeManagerModules/neovim/theme/treesitter.nix b/homeManagerModules/neovim/theme/treesitter.nix index c9326be6..a8a374cb 100644 --- a/homeManagerModules/neovim/theme/treesitter.nix +++ b/homeManagerModules/neovim/theme/treesitter.nix @@ -1,34 +1,48 @@ -{pkgs, ...}: { - programs.neovim.plugins = [ - { - plugin = pkgs.vimPlugins.nvim-treesitter-context; - type = "lua"; - config = - # lua - '' - require('treesitter-context').setup({ - enable = true, - max_lines = 3, - min_window_height = 20, - }); +{ + config, + lib, + pkgs, + ... +}: let + inherit (lib) mkIf; - vim.cmd.hi('TreesitterContextBottom', 'gui=underline guisp=Grey'); - ''; - } + cfg = config.programs.neovim; +in { + config = mkIf cfg.enable { + programs.neovim.plugins = [ + { + plugin = pkgs.vimPlugins.nvim-treesitter-context; + type = "lua"; + config = + # lua + '' + require('treesitter-context').setup({ + enable = true, + max_lines = 3, + min_window_height = 20, + }); - pkgs.vimPlugins.nvim-treesitter-textobjects + vim.cmd.hi('TreesitterContextBottom', 'gui=underline guisp=Grey'); + ''; + } - { - plugin = pkgs.vimPlugins.nvim-treesitter.withAllGrammars; - type = "lua"; - config = - # lua - '' - require('nvim-treesitter.configs').setup({ - highlight = { enable = true }, - indent = { enable = true }, - }); - ''; - } - ]; + pkgs.vimPlugins.nvim-treesitter-textobjects + + { + plugin = pkgs.vimPlugins.nvim-treesitter.withAllGrammars; + type = "lua"; + config = + # lua + '' + require('nvim-treesitter.configs').setup({ + highlight = { enable = true }, + indent = { enable = true }, + }); + ''; + } + ]; + }; + + # For accurate stack trace + _file = ./treesitter.nix; }