From 11adcacd6f1d225ee36ebdf35a9f34b7e5c04729 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Fri, 22 Nov 2024 02:48:41 -0500 Subject: [PATCH] refactor(nvim): move to homeManagerModules --- common/home/default.nix | 1 - common/home/neovim/default.nix | 116 ----------- common/home/neovim/git.nix | 31 --- common/home/neovim/theme.nix | 179 ----------------- common/nix-on-droid.nix | 2 + common/vars/default.nix | 5 - devices/android/default.nix | 5 +- devices/binto/default.nix | 19 +- devices/cluster/default.nix | 16 ++ devices/homie/default.nix | 16 ++ devices/nos/default.nix | 16 ++ devices/servivi/default.nix | 16 ++ devices/wim/default.nix | 19 +- homeManagerModules/default.nix | 1 + .../neovim/.editorconfig | 0 homeManagerModules/neovim/default.nix | 128 +++++++++++++ homeManagerModules/neovim/git.nix | 27 +++ .../neovim/langs/bash.nix | 11 +- .../neovim/langs/clang.nix | 7 +- .../neovim/langs/csharp.nix | 7 +- .../neovim/langs/default.nix | 26 +-- .../neovim/langs/hyprlang.nix | 5 +- .../neovim/langs/java.nix | 5 +- .../neovim/langs/json.nix | 5 +- .../neovim/langs/lua.nix | 7 +- .../neovim/langs/markdown.nix | 21 +- .../neovim/langs/nix.nix | 29 +-- .../neovim/langs/python.nix | 5 +- .../neovim/langs/rust.nix | 11 +- .../neovim/langs/web.nix | 22 ++- .../neovim/plugins/cmp.lua | 0 .../neovim/plugins/heirline.lua | 0 .../neovim/plugins/neotree.lua | 0 homeManagerModules/neovim/theme.nix | 181 ++++++++++++++++++ .../neovim/treesitter.nix | 0 35 files changed, 524 insertions(+), 415 deletions(-) delete mode 100644 common/home/neovim/default.nix delete mode 100644 common/home/neovim/git.nix delete mode 100644 common/home/neovim/theme.nix rename {common/home => homeManagerModules}/neovim/.editorconfig (100%) create mode 100644 homeManagerModules/neovim/default.nix create mode 100644 homeManagerModules/neovim/git.nix rename {common/home => homeManagerModules}/neovim/langs/bash.nix (86%) rename {common/home => homeManagerModules}/neovim/langs/clang.nix (95%) rename {common/home => homeManagerModules}/neovim/langs/csharp.nix (97%) rename {common/home => homeManagerModules}/neovim/langs/default.nix (82%) rename {common/home => homeManagerModules}/neovim/langs/hyprlang.nix (89%) rename {common/home => homeManagerModules}/neovim/langs/java.nix (97%) rename {common/home => homeManagerModules}/neovim/langs/json.nix (95%) rename {common/home => homeManagerModules}/neovim/langs/lua.nix (95%) rename {common/home => homeManagerModules}/neovim/langs/markdown.nix (95%) rename {common/home => homeManagerModules}/neovim/langs/nix.nix (82%) rename {common/home => homeManagerModules}/neovim/langs/python.nix (88%) rename {common/home => homeManagerModules}/neovim/langs/rust.nix (83%) rename {common/home => homeManagerModules}/neovim/langs/web.nix (96%) rename {common/home => homeManagerModules}/neovim/plugins/cmp.lua (100%) rename {common/home => homeManagerModules}/neovim/plugins/heirline.lua (100%) rename {common/home => homeManagerModules}/neovim/plugins/neotree.lua (100%) create mode 100644 homeManagerModules/neovim/theme.nix rename {common/home => homeManagerModules}/neovim/treesitter.nix (100%) diff --git a/common/home/default.nix b/common/home/default.nix index 3c274ddf..614d3fb0 100644 --- a/common/home/default.nix +++ b/common/home/default.nix @@ -3,7 +3,6 @@ ./bash ./direnv ./git - ./neovim ./nix-index ./tmux ]; diff --git a/common/home/neovim/default.nix b/common/home/neovim/default.nix deleted file mode 100644 index 7de00769..00000000 --- a/common/home/neovim/default.nix +++ /dev/null @@ -1,116 +0,0 @@ -{ - config, - pkgs, - ... -}: { - imports = [ - ./git.nix - ./langs - ./theme.nix - ./treesitter.nix - ]; - - programs = { - neovim = { - enable = 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; - - vim.opt.number = true; - vim.opt.relativenumber = true; - - 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'; - - -- remove highlight on words - vim.keymap.set('n', '', ':noh', { - noremap = true, - silent = true, - }); - - -- Get rid of deprecated messages - vim.tbl_add_reverse_lookup = function(tbl) - for k, v in pairs(tbl) do - tbl[v] = k; - end - end; - vim.tbl_islist = function(tbl) - return vim.islist(tbl); - end; - vim.diagnostic.is_disabled = function() - return not vim.diagnostic.is_enabled(); - end; - vim.lsp.buf_get_clients = function() - return vim.lsp.get_clients(); - end; - vim.lsp.get_active_clients = function() - return vim.lsp.get_clients(); - end; - ''; - - 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; - - 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' }, - - -- Where the plugin keeps files data - hashfile = '${config.xdg.cacheHome}/nvim/config-local', - }); - ''; - } - ]; - }; - }; -} diff --git a/common/home/neovim/git.nix b/common/home/neovim/git.nix deleted file mode 100644 index 60e3b80f..00000000 --- a/common/home/neovim/git.nix +++ /dev/null @@ -1,31 +0,0 @@ -{pkgs, ...}: { - programs = { - neovim = { - plugins = [ - pkgs.vimPlugins.fugitive - - { - plugin = pkgs.vimPlugins.gitsigns-nvim; - type = "lua"; - config = - # lua - '' - local gitsigns = require("gitsigns"); - - local function visual_stage() - local first_line = vim.fn.line('v'); - local last_line = vim.fn.getpos('.')[2]; - gitsigns.stage_hunk({ first_line, last_line }); - end - - vim.keymap.set("v", "gs", function() - visual_stage() - end); - - gitsigns.setup(); - ''; - } - ]; - }; - }; -} diff --git a/common/home/neovim/theme.nix b/common/home/neovim/theme.nix deleted file mode 100644 index b119190a..00000000 --- a/common/home/neovim/theme.nix +++ /dev/null @@ -1,179 +0,0 @@ -{ - config, - pkgs, - lib, - nvim-theme-src, - ... -}: let - inherit (lib) fileContents optionals; - inherit (config.vars) neovimIde; -in { - programs = { - neovim = { - extraPackages = builtins.attrValues { - inherit (pkgs) bat; - }; - - plugins = - [ - { - plugin = pkgs.vimPlugins.dracula-nvim.overrideAttrs { - src = nvim-theme-src; - }; - type = "lua"; - config = - # lua - '' - -- set dot icon in place of trailing whitespaces - vim.opt.listchars = { - tab = '→ ', - trail = '•', - extends = '⟩', - precedes = '⟨', - nbsp = '␣', - }; - vim.opt.list = true; - - -- Add visual indicator for trailing whitespaces - vim.opt.fillchars = { eob = " " }; - vim.fn.matchadd('errorMsg', [[\s\+$]]); - - vim.cmd.colorscheme('dracula'); - ''; - } - { - plugin = pkgs.vimPlugins.indent-blankline-nvim; - type = "lua"; - config = - # lua - '' - -- - local highlight = { - "RainbowRed", - "RainbowYellow", - "RainbowBlue", - "RainbowOrange", - "RainbowGreen", - "RainbowViolet", - "RainbowCyan", - }; - - local hooks = require('ibl.hooks'); - hooks.register(hooks.type.HIGHLIGHT_SETUP, function() - vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }); - vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }); - vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }); - vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }); - vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }); - vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }); - vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }); - end); - - require('ibl').setup({ - indent = { - highlight = highlight, - char = "▏", - }, - }); - ''; - } - - { - plugin = pkgs.vimPlugins.nvim-highlight-colors; - type = "lua"; - config = - # lua - '' - -- Ensure termguicolors is enabled if not already - vim.opt.termguicolors = true; - - require('nvim-highlight-colors').setup({}); - ''; - } - - # Deps of heirline config - pkgs.vimPlugins.nvim-web-devicons - { - plugin = pkgs.vimPlugins.heirline-nvim; - type = "lua"; - config = fileContents ./plugins/heirline.lua; - } - ] - ++ optionals neovimIde [ - { - plugin = pkgs.vimPlugins.neo-tree-nvim; - type = "lua"; - config = fileContents ./plugins/neotree.lua; - } - { - plugin = pkgs.vimPlugins.codewindow-nvim; - type = "lua"; - config = - # lua - '' - -- - local codewindow = require('codewindow'); - - codewindow.setup({ - auto_enable = false, - minimap_width = 8, - relative = 'editor', - window_border = 'none', - exclude_filetypes = { 'help' }, - }); - - vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResized' }, { - pattern = '*', - callback = function() - if vim.api.nvim_win_get_width(0) < 88 then - codewindow.close_minimap(); - else - codewindow.open_minimap(); - end - end, - }); - ''; - } - { - plugin = pkgs.vimPlugins.transparent-nvim; - type = "lua"; - config = - # lua - '' - require('transparent').setup({ - groups = { - 'Normal', - 'NormalNC', - 'Comment', - 'Constant', - 'Special', - 'Identifier', - 'Statement', - 'PreProc', - 'Type', - 'Underlined', - 'Todo', - 'String', - 'Function', - 'Conditional', - 'Repeat', - 'Operator', - 'Structure', - 'LineNr', - 'NonText', - 'SignColumn', - 'CursorLine', - 'CursorLineNr', - 'StatusLine', - 'StatusLineNC', - 'EndOfBuffer', - }, - extra_groups = {}, - exclude_groups = {}, - }); - ''; - } - ]; - }; - }; -} diff --git a/common/nix-on-droid.nix b/common/nix-on-droid.nix index 95c8764a..ef73b871 100644 --- a/common/nix-on-droid.nix +++ b/common/nix-on-droid.nix @@ -1,6 +1,7 @@ { config, lib, + self, ... }: { imports = [ @@ -41,6 +42,7 @@ } ./home + self.homeManagerModules.neovim { programs.bash.sessionVariables = { diff --git a/common/vars/default.nix b/common/vars/default.nix index ae10cd1e..df0099b5 100644 --- a/common/vars/default.nix +++ b/common/vars/default.nix @@ -39,11 +39,6 @@ in { }; }; }; - - neovimIde = mkOption { - type = types.bool; - default = true; - }; }; config = { diff --git a/devices/android/default.nix b/devices/android/default.nix index 37523cf9..cd1181a5 100644 --- a/devices/android/default.nix +++ b/devices/android/default.nix @@ -4,10 +4,7 @@ pkgs, ... }: { - vars = { - mainUser = "nix-on-droid"; - neovimIde = false; - }; + vars.mainUser = "nix-on-droid"; environment.variables.FLAKE = "/data/data/com.termux.nix/files/home/.nix"; diff --git a/devices/binto/default.nix b/devices/binto/default.nix index 8c1dc68f..94f3f682 100644 --- a/devices/binto/default.nix +++ b/devices/binto/default.nix @@ -19,9 +19,22 @@ in { self.nixosModules.server ]; - home-manager.users.${mainUser}.imports = [ - self.homeManagerModules.firefox - ]; + home-manager.users = rec { + root = { + imports = [ + self.homeManagerModules.firefox + self.homeManagerModules.neovim + ]; + + programs.neovim = { + enable = true; + enableIde = true; + user = mainUser; + }; + }; + + ${mainUser} = root; + }; # State Version: DO NOT CHANGE system.stateVersion = "23.11"; diff --git a/devices/cluster/default.nix b/devices/cluster/default.nix index a4d16e82..f7f82b8f 100644 --- a/devices/cluster/default.nix +++ b/devices/cluster/default.nix @@ -19,6 +19,22 @@ in { self.nixosModules.server ]; + home-manager.users = rec { + root = { + imports = [ + self.homeManagerModules.neovim + ]; + + programs.neovim = { + enable = true; + enableIde = true; + user = mainUser; + }; + }; + + ${mainUser} = root; + }; + # State Version: DO NOT CHANGE system.stateVersion = "24.05"; diff --git a/devices/homie/default.nix b/devices/homie/default.nix index 1441d066..41aa8503 100644 --- a/devices/homie/default.nix +++ b/devices/homie/default.nix @@ -18,6 +18,22 @@ in { self.nixosModules.server ]; + home-manager.users = rec { + root = { + imports = [ + self.homeManagerModules.neovim + ]; + + programs.neovim = { + enable = true; + enableIde = true; + user = mainUser; + }; + }; + + ${mainUser} = root; + }; + # State Version: DO NOT CHANGE system.stateVersion = "24.11"; diff --git a/devices/nos/default.nix b/devices/nos/default.nix index 79386d79..60cfadb1 100644 --- a/devices/nos/default.nix +++ b/devices/nos/default.nix @@ -18,6 +18,22 @@ in { self.nixosModules.server ]; + home-manager.users = rec { + root = { + imports = [ + self.homeManagerModules.neovim + ]; + + programs.neovim = { + enable = true; + enableIde = true; + user = mainUser; + }; + }; + + ${mainUser} = root; + }; + # State Version: DO NOT CHANGE system.stateVersion = "24.05"; diff --git a/devices/servivi/default.nix b/devices/servivi/default.nix index 0050da18..2c6aa777 100644 --- a/devices/servivi/default.nix +++ b/devices/servivi/default.nix @@ -18,6 +18,22 @@ in { self.nixosModules.server ]; + home-manager.users = rec { + root = { + imports = [ + self.homeManagerModules.neovim + ]; + + programs.neovim = { + enable = true; + enableIde = true; + user = mainUser; + }; + }; + + ${mainUser} = root; + }; + # State Version: DO NOT CHANGE system.stateVersion = "24.05"; diff --git a/devices/wim/default.nix b/devices/wim/default.nix index 46e1ab63..90730437 100644 --- a/devices/wim/default.nix +++ b/devices/wim/default.nix @@ -22,9 +22,22 @@ in { self.nixosModules.server ]; - home-manager.users.${mainUser}.imports = [ - self.homeManagerModules.firefox - ]; + home-manager.users = rec { + root = { + imports = [ + self.homeManagerModules.firefox + self.homeManagerModules.neovim + ]; + + programs.neovim = { + enable = true; + enableIde = true; + user = mainUser; + }; + }; + + ${mainUser} = root; + }; # State Version: DO NOT CHANGE system.stateVersion = "23.05"; diff --git a/homeManagerModules/default.nix b/homeManagerModules/default.nix index 74c0734b..50df3492 100644 --- a/homeManagerModules/default.nix +++ b/homeManagerModules/default.nix @@ -1,3 +1,4 @@ self: { firefox = import ./firefox self; + neovim = import ./neovim self; } diff --git a/common/home/neovim/.editorconfig b/homeManagerModules/neovim/.editorconfig similarity index 100% rename from common/home/neovim/.editorconfig rename to homeManagerModules/neovim/.editorconfig diff --git a/homeManagerModules/neovim/default.nix b/homeManagerModules/neovim/default.nix new file mode 100644 index 00000000..3645cafe --- /dev/null +++ b/homeManagerModules/neovim/default.nix @@ -0,0 +1,128 @@ +self: { + config, + lib, + pkgs, + ... +}: let + inherit (lib) mkOption types; +in { + imports = [ + ./git.nix + ./treesitter.nix + (import ./langs self) + (import ./theme.nix self) + ]; + + options.programs.neovim = { + 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; + + vim.opt.number = true; + vim.opt.relativenumber = true; + + 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'; + + -- remove highlight on words + vim.keymap.set('n', '', ':noh', { + noremap = true, + silent = true, + }); + + -- Get rid of deprecated messages + vim.tbl_add_reverse_lookup = function(tbl) + for k, v in pairs(tbl) do + tbl[v] = k; + end + end; + vim.tbl_islist = function(tbl) + return vim.islist(tbl); + end; + vim.diagnostic.is_disabled = function() + return not vim.diagnostic.is_enabled(); + end; + vim.lsp.buf_get_clients = function() + return vim.lsp.get_clients(); + end; + vim.lsp.get_active_clients = function() + return vim.lsp.get_clients(); + end; + ''; + + 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; + + 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' }, + + -- Where the plugin keeps files data + hashfile = '${config.xdg.cacheHome}/nvim/config-local', + }); + ''; + } + ]; + }; + + # For accurate stack trace + _file = ./default.nix; +} diff --git a/homeManagerModules/neovim/git.nix b/homeManagerModules/neovim/git.nix new file mode 100644 index 00000000..b39a62a6 --- /dev/null +++ b/homeManagerModules/neovim/git.nix @@ -0,0 +1,27 @@ +{pkgs, ...}: { + programs.neovim.plugins = [ + pkgs.vimPlugins.fugitive + + { + plugin = pkgs.vimPlugins.gitsigns-nvim; + type = "lua"; + config = + # lua + '' + local gitsigns = require("gitsigns"); + + local function visual_stage() + local first_line = vim.fn.line('v'); + local last_line = vim.fn.getpos('.')[2]; + gitsigns.stage_hunk({ first_line, last_line }); + end + + vim.keymap.set("v", "gs", function() + visual_stage() + end); + + gitsigns.setup(); + ''; + } + ]; +} diff --git a/common/home/neovim/langs/bash.nix b/homeManagerModules/neovim/langs/bash.nix similarity index 86% rename from common/home/neovim/langs/bash.nix rename to homeManagerModules/neovim/langs/bash.nix index 10b66a2b..77201e98 100644 --- a/common/home/neovim/langs/bash.nix +++ b/homeManagerModules/neovim/langs/bash.nix @@ -1,13 +1,14 @@ { config, - pkgs, lib, + pkgs, ... }: let inherit (lib) getExe mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; in { - programs = { + programs = mkIf cfg.enable { # I love doing typos bash.shellAliases = { nivm = "nvim"; @@ -19,13 +20,13 @@ in { viAlias = true; vimAlias = true; - extraPackages = mkIf neovimIde [ + extraPackages = mkIf cfg.enableIde [ pkgs.nodePackages.bash-language-server pkgs.shellcheck ]; extraLuaConfig = - mkIf neovimIde + mkIf cfg.enableIde # lua '' vim.api.nvim_create_autocmd('FileType', { diff --git a/common/home/neovim/langs/clang.nix b/homeManagerModules/neovim/langs/clang.nix similarity index 95% rename from common/home/neovim/langs/clang.nix rename to homeManagerModules/neovim/langs/clang.nix index bd1fbf9c..aea9c6e3 100644 --- a/common/home/neovim/langs/clang.nix +++ b/homeManagerModules/neovim/langs/clang.nix @@ -1,13 +1,14 @@ { config, - pkgs, lib, + pkgs, ... }: let inherit (lib) mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; in - mkIf neovimIde { + mkIf cfg.enableIde { programs = { neovim = { extraPackages = builtins.attrValues { diff --git a/common/home/neovim/langs/csharp.nix b/homeManagerModules/neovim/langs/csharp.nix similarity index 97% rename from common/home/neovim/langs/csharp.nix rename to homeManagerModules/neovim/langs/csharp.nix index d1669d10..240167d5 100644 --- a/common/home/neovim/langs/csharp.nix +++ b/homeManagerModules/neovim/langs/csharp.nix @@ -1,13 +1,14 @@ { config, - pkgs, lib, + pkgs, ... }: let inherit (lib) mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; in - mkIf neovimIde { + mkIf cfg.enableIde { programs = { neovim = { extraPackages = builtins.attrValues { diff --git a/common/home/neovim/langs/default.nix b/homeManagerModules/neovim/langs/default.nix similarity index 82% rename from common/home/neovim/langs/default.nix rename to homeManagerModules/neovim/langs/default.nix index 2947522e..43f58ebf 100644 --- a/common/home/neovim/langs/default.nix +++ b/homeManagerModules/neovim/langs/default.nix @@ -1,11 +1,12 @@ -{ +self: { config, lib, pkgs, ... }: let inherit (lib) fileContents mkBefore mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; in { imports = [ ./bash.nix @@ -15,29 +16,19 @@ in { ./java.nix ./json.nix ./lua.nix - ./markdown.nix - ./nix.nix ./python.nix ./rust.nix - ./web.nix + (import ./markdown.nix self) + (import ./nix.nix self) + (import ./web.nix self) ]; - programs = mkIf neovimIde { + config.programs = mkIf cfg.enableIde { neovim = { extraLuaConfig = mkBefore # lua '' - -- Start completion / snippet stuff - vim.g.coq_settings = { - auto_start = 'shut-up', - keymap = { - recommended = false, - }, - -- https://github.com/NixOS/nixpkgs/issues/168928#issuecomment-1109581739 - xdg = true, - }; - -- Add formatting cmd vim.api.nvim_create_user_command( 'Format', @@ -101,4 +92,7 @@ in { ]; }; }; + + # For accurate stack trace + _file = ./default.nix; } diff --git a/common/home/neovim/langs/hyprlang.nix b/homeManagerModules/neovim/langs/hyprlang.nix similarity index 89% rename from common/home/neovim/langs/hyprlang.nix rename to homeManagerModules/neovim/langs/hyprlang.nix index 575ae8d7..582ce17a 100644 --- a/common/home/neovim/langs/hyprlang.nix +++ b/homeManagerModules/neovim/langs/hyprlang.nix @@ -4,9 +4,10 @@ ... }: let inherit (lib) mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; in - mkIf neovimIde { + mkIf cfg.enableIde { programs = { neovim = { extraLuaConfig = diff --git a/common/home/neovim/langs/java.nix b/homeManagerModules/neovim/langs/java.nix similarity index 97% rename from common/home/neovim/langs/java.nix rename to homeManagerModules/neovim/langs/java.nix index 03ce807e..a65656dd 100644 --- a/common/home/neovim/langs/java.nix +++ b/homeManagerModules/neovim/langs/java.nix @@ -5,12 +5,13 @@ ... }: let inherit (lib) getExe mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; javaSdk = pkgs.temurin-bin-17; javaPkgs = builtins.attrValues {inherit (pkgs) gradle maven;}; in - mkIf neovimIde { + mkIf cfg.enableIde { home.packages = javaPkgs; xdg.dataFile.".gradle/gradle.properties".text = '' diff --git a/common/home/neovim/langs/json.nix b/homeManagerModules/neovim/langs/json.nix similarity index 95% rename from common/home/neovim/langs/json.nix rename to homeManagerModules/neovim/langs/json.nix index a9511709..93fe1545 100644 --- a/common/home/neovim/langs/json.nix +++ b/homeManagerModules/neovim/langs/json.nix @@ -5,9 +5,10 @@ ... }: let inherit (lib) mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; in - mkIf neovimIde { + mkIf cfg.enableIde { programs = { neovim = { extraPackages = builtins.attrValues { diff --git a/common/home/neovim/langs/lua.nix b/homeManagerModules/neovim/langs/lua.nix similarity index 95% rename from common/home/neovim/langs/lua.nix rename to homeManagerModules/neovim/langs/lua.nix index 276702ef..943364e8 100644 --- a/common/home/neovim/langs/lua.nix +++ b/homeManagerModules/neovim/langs/lua.nix @@ -1,15 +1,16 @@ { config, - pkgs, lib, + pkgs, ... }: let inherit (lib) mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; flakeEnv = config.programs.bash.sessionVariables.FLAKE; in - mkIf neovimIde { + mkIf cfg.enableIde { programs = { neovim = { extraPackages = builtins.attrValues { diff --git a/common/home/neovim/langs/markdown.nix b/homeManagerModules/neovim/langs/markdown.nix similarity index 95% rename from common/home/neovim/langs/markdown.nix rename to homeManagerModules/neovim/langs/markdown.nix index b451c59f..e3f83177 100644 --- a/common/home/neovim/langs/markdown.nix +++ b/homeManagerModules/neovim/langs/markdown.nix @@ -1,17 +1,18 @@ -{ +self: { config, lib, pkgs, self, - vimplugin-easytables-src, ... }: let - inherit (lib) mkIf; - inherit (config.vars) neovimIde; - + inherit (self.inputs) vimplugin-easytables-src; inherit (self.lib.${pkgs.system}) buildPlugin; -in - mkIf neovimIde { + + inherit (lib) mkIf; + + cfg = config.programs.neovim; +in { + config = mkIf cfg.enableIde { programs = { neovim = { extraPackages = builtins.attrValues { @@ -125,4 +126,8 @@ in ]; }; }; - } + }; + + # For accurate stack trace + _file = ./markdown.nix; +} diff --git a/common/home/neovim/langs/nix.nix b/homeManagerModules/neovim/langs/nix.nix similarity index 82% rename from common/home/neovim/langs/nix.nix rename to homeManagerModules/neovim/langs/nix.nix index 1d4b2f7b..19a07da4 100644 --- a/common/home/neovim/langs/nix.nix +++ b/homeManagerModules/neovim/langs/nix.nix @@ -1,30 +1,29 @@ -{ +self: { config, + lib, osConfig, pkgs, - lib, - nixd, - self, ... }: let inherit (lib) getExe hasPrefix mkIf removePrefix; - inherit (config.vars) mainUser neovimIde; inherit (osConfig.networking) hostName; + cfg = config.programs.neovim; + defaultFormatter = self.formatter.${pkgs.system}; - nixdPkg = nixd.packages.${pkgs.system}.default; + nixdPkg = self.inputs.nixd.packages.${pkgs.system}.default; flakeEnv = config.programs.bash.sessionVariables.FLAKE; - flakeDir = "${removePrefix "/home/${mainUser}/" flakeEnv}"; -in - mkIf neovimIde { + flakeDir = "${removePrefix "/home/${cfg.user}/" flakeEnv}"; +in { + config = mkIf cfg.enableIde { assertions = [ { assertion = - neovimIde - && hasPrefix "/home/${mainUser}/" flakeEnv - || !neovimIde; + cfg.enableIde + && hasPrefix "/home/${cfg.user}/" flakeEnv + || !cfg.enableIde; message = '' Your $FLAKE environment variable needs to point to a directory in the main users' home to use the neovim module. @@ -74,4 +73,8 @@ in ''; }; }; - } + }; + + # For accurate stack trace + _file = ./nix.nix; +} diff --git a/common/home/neovim/langs/python.nix b/homeManagerModules/neovim/langs/python.nix similarity index 88% rename from common/home/neovim/langs/python.nix rename to homeManagerModules/neovim/langs/python.nix index e5d28ab8..fd493a8f 100644 --- a/common/home/neovim/langs/python.nix +++ b/homeManagerModules/neovim/langs/python.nix @@ -5,9 +5,10 @@ ... }: let inherit (lib) mkIf; - inherit (config.vars) neovimIde; + + cfg = config.programs.neovim; in - mkIf neovimIde { + mkIf cfg.enableIde { programs = { neovim = { withPython3 = true; diff --git a/common/home/neovim/langs/rust.nix b/homeManagerModules/neovim/langs/rust.nix similarity index 83% rename from common/home/neovim/langs/rust.nix rename to homeManagerModules/neovim/langs/rust.nix index 5487c4f6..77afcbbc 100644 --- a/common/home/neovim/langs/rust.nix +++ b/homeManagerModules/neovim/langs/rust.nix @@ -1,16 +1,17 @@ { config, - pkgs, lib, + pkgs, ... }: let - inherit (lib) mkIf; - inherit (config.vars) neovimIde; + inherit (lib) attrValues mkIf; + + cfg = config.programs.neovim; in - mkIf neovimIde { + mkIf cfg.enableIde { programs = { neovim = { - extraPackages = builtins.attrValues { + extraPackages = attrValues { inherit (pkgs) cargo diff --git a/common/home/neovim/langs/web.nix b/homeManagerModules/neovim/langs/web.nix similarity index 96% rename from common/home/neovim/langs/web.nix rename to homeManagerModules/neovim/langs/web.nix index aee5fc71..973dcdc8 100644 --- a/common/home/neovim/langs/web.nix +++ b/homeManagerModules/neovim/langs/web.nix @@ -1,17 +1,17 @@ -{ +self: { config, lib, pkgs, - self, - vimplugin-ts-error-translator-src, ... }: let - inherit (lib) mkIf; - inherit (config.vars) neovimIde; - + inherit (self.inputs) vimplugin-ts-error-translator-src; inherit (self.lib.${pkgs.system}) buildPlugin; -in - mkIf neovimIde { + + inherit (lib) mkIf; + + cfg = config.programs.neovim; +in { + config = mkIf cfg.enableIde { programs = { neovim = { withNodeJs = true; @@ -197,4 +197,8 @@ in ]; }; }; - } + }; + + # For accurate stack trace + _file = ./web.nix; +} diff --git a/common/home/neovim/plugins/cmp.lua b/homeManagerModules/neovim/plugins/cmp.lua similarity index 100% rename from common/home/neovim/plugins/cmp.lua rename to homeManagerModules/neovim/plugins/cmp.lua diff --git a/common/home/neovim/plugins/heirline.lua b/homeManagerModules/neovim/plugins/heirline.lua similarity index 100% rename from common/home/neovim/plugins/heirline.lua rename to homeManagerModules/neovim/plugins/heirline.lua diff --git a/common/home/neovim/plugins/neotree.lua b/homeManagerModules/neovim/plugins/neotree.lua similarity index 100% rename from common/home/neovim/plugins/neotree.lua rename to homeManagerModules/neovim/plugins/neotree.lua diff --git a/homeManagerModules/neovim/theme.nix b/homeManagerModules/neovim/theme.nix new file mode 100644 index 00000000..10123437 --- /dev/null +++ b/homeManagerModules/neovim/theme.nix @@ -0,0 +1,181 @@ +self: { + config, + pkgs, + lib, + ... +}: let + inherit (self.inputs) nvim-theme-src; + inherit (lib) attrValues fileContents optionals; + + cfg = config.programs.neovim; +in { + config.programs.neovim = { + extraPackages = attrValues { + inherit (pkgs) bat; + }; + + plugins = + [ + { + plugin = pkgs.vimPlugins.dracula-nvim.overrideAttrs { + src = nvim-theme-src; + }; + type = "lua"; + config = + # lua + '' + -- set dot icon in place of trailing whitespaces + vim.opt.listchars = { + tab = '→ ', + trail = '•', + extends = '⟩', + precedes = '⟨', + nbsp = '␣', + }; + vim.opt.list = true; + + -- Add visual indicator for trailing whitespaces + vim.opt.fillchars = { eob = " " }; + vim.fn.matchadd('errorMsg', [[\s\+$]]); + + vim.cmd.colorscheme('dracula'); + ''; + } + { + plugin = pkgs.vimPlugins.indent-blankline-nvim; + type = "lua"; + config = + # lua + '' + -- + local highlight = { + "RainbowRed", + "RainbowYellow", + "RainbowBlue", + "RainbowOrange", + "RainbowGreen", + "RainbowViolet", + "RainbowCyan", + }; + + local hooks = require('ibl.hooks'); + hooks.register(hooks.type.HIGHLIGHT_SETUP, function() + vim.api.nvim_set_hl(0, "RainbowRed", { fg = "#E06C75" }); + vim.api.nvim_set_hl(0, "RainbowYellow", { fg = "#E5C07B" }); + vim.api.nvim_set_hl(0, "RainbowBlue", { fg = "#61AFEF" }); + vim.api.nvim_set_hl(0, "RainbowOrange", { fg = "#D19A66" }); + vim.api.nvim_set_hl(0, "RainbowGreen", { fg = "#98C379" }); + vim.api.nvim_set_hl(0, "RainbowViolet", { fg = "#C678DD" }); + vim.api.nvim_set_hl(0, "RainbowCyan", { fg = "#56B6C2" }); + end); + + require('ibl').setup({ + indent = { + highlight = highlight, + char = "▏", + }, + }); + ''; + } + + { + plugin = pkgs.vimPlugins.nvim-highlight-colors; + type = "lua"; + config = + # lua + '' + -- Ensure termguicolors is enabled if not already + vim.opt.termguicolors = true; + + require('nvim-highlight-colors').setup({}); + ''; + } + + # Deps of heirline config + pkgs.vimPlugins.nvim-web-devicons + { + plugin = pkgs.vimPlugins.heirline-nvim; + type = "lua"; + config = fileContents ./plugins/heirline.lua; + } + ] + ++ optionals cfg.enableIde [ + { + plugin = pkgs.vimPlugins.neo-tree-nvim; + type = "lua"; + config = fileContents ./plugins/neotree.lua; + } + { + plugin = pkgs.vimPlugins.codewindow-nvim; + type = "lua"; + config = + # lua + '' + -- + local codewindow = require('codewindow'); + + codewindow.setup({ + auto_enable = false, + minimap_width = 8, + relative = 'editor', + window_border = 'none', + exclude_filetypes = { 'help' }, + }); + + vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResized' }, { + pattern = '*', + callback = function() + if vim.api.nvim_win_get_width(0) < 88 then + codewindow.close_minimap(); + else + codewindow.open_minimap(); + end + end, + }); + ''; + } + { + plugin = pkgs.vimPlugins.transparent-nvim; + type = "lua"; + config = + # lua + '' + require('transparent').setup({ + groups = { + 'Normal', + 'NormalNC', + 'Comment', + 'Constant', + 'Special', + 'Identifier', + 'Statement', + 'PreProc', + 'Type', + 'Underlined', + 'Todo', + 'String', + 'Function', + 'Conditional', + 'Repeat', + 'Operator', + 'Structure', + 'LineNr', + 'NonText', + 'SignColumn', + 'CursorLine', + 'CursorLineNr', + 'StatusLine', + 'StatusLineNC', + 'EndOfBuffer', + }, + extra_groups = {}, + exclude_groups = {}, + }); + ''; + } + ]; + }; + + # For accurate stack trace + _file = ./theme.nix; +} diff --git a/common/home/neovim/treesitter.nix b/homeManagerModules/neovim/treesitter.nix similarity index 100% rename from common/home/neovim/treesitter.nix rename to homeManagerModules/neovim/treesitter.nix