From 6a125a1df6f15207af68176dc4d7a1e2556d2e20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 10 Sep 2023 13:30:29 +0200 Subject: [PATCH 1/9] refactor(nvim)!: add opts option --- modules/programs/nvim/default.nix | 142 +++++++---- .../nvim/plugins/{default.nix => coding.nix} | 221 +++++++----------- modules/programs/nvim/plugins/copilot-lua.lua | 5 - .../plugins/{ => lua}/catppuccin-nvim.lua | 0 .../nvim/plugins/{ => lua}/formatter-nvim.lua | 0 .../nvim/plugins/{ => lua}/gitsigns-nvim.lua | 0 .../nvim/plugins/{ => lua}/mini-nvim.lua | 0 .../nvim/plugins/{ => lua}/neodev-nvim.lua | 0 .../nvim/plugins/{ => lua}/noice-nvim.lua | 0 .../nvim/plugins/{ => lua}/null-ls-nvim.lua | 1 - .../nvim/plugins/{ => lua}/nvim-cmp.lua | 0 .../nvim/plugins/{ => lua}/nvim-lspconfig.lua | 0 .../nvim-treesitter-textsubjects.lua | 0 .../plugins/{ => lua}/nvim-treesitter.lua | 0 .../nvim/plugins/{ => lua}/nvim-ufo.lua | 0 .../nvim/plugins/{ => lua}/statuscol-nvim.lua | 0 .../nvim/plugins/{ => lua}/telescope.lua | 0 .../plugins/{ => lua}/vim-startuptime.lua | 0 .../nvim/plugins/{ => lua}/which-key-nvim.lua | 38 +-- .../plugins/{ => lua}/zettelkasten-nvim.lua | 0 .../programs/nvim/plugins/nvim-lastplace.lua | 5 - modules/programs/nvim/plugins/oil-nvim.lua | 4 - .../nvim/plugins/smartcolumn-nvim.lua | 4 - .../nvim/plugins/todo-comments-nvim.lua | 1 - modules/programs/nvim/plugins/treesitter.nix | 42 ++++ .../programs/nvim/plugins/trouble-nvim.lua | 1 - modules/programs/nvim/plugins/ui.nix | 47 ++++ 27 files changed, 273 insertions(+), 238 deletions(-) rename modules/programs/nvim/plugins/{default.nix => coding.nix} (51%) delete mode 100644 modules/programs/nvim/plugins/copilot-lua.lua rename modules/programs/nvim/plugins/{ => lua}/catppuccin-nvim.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/formatter-nvim.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/gitsigns-nvim.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/mini-nvim.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/neodev-nvim.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/noice-nvim.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/null-ls-nvim.lua (93%) rename modules/programs/nvim/plugins/{ => lua}/nvim-cmp.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/nvim-lspconfig.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/nvim-treesitter-textsubjects.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/nvim-treesitter.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/nvim-ufo.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/statuscol-nvim.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/telescope.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/vim-startuptime.lua (100%) rename modules/programs/nvim/plugins/{ => lua}/which-key-nvim.lua (66%) rename modules/programs/nvim/plugins/{ => lua}/zettelkasten-nvim.lua (100%) delete mode 100644 modules/programs/nvim/plugins/nvim-lastplace.lua delete mode 100644 modules/programs/nvim/plugins/oil-nvim.lua delete mode 100644 modules/programs/nvim/plugins/smartcolumn-nvim.lua delete mode 100644 modules/programs/nvim/plugins/todo-comments-nvim.lua create mode 100644 modules/programs/nvim/plugins/treesitter.nix delete mode 100644 modules/programs/nvim/plugins/trouble-nvim.lua create mode 100644 modules/programs/nvim/plugins/ui.nix diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index c4859e5..4d95a7b 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -1,57 +1,90 @@ -{ config -, lib -, pkgs -, ... -}: +{ config, lib, pkgs, ... }: with lib; let cfg = config.my.programs.nvim; - boolToString = bool: if bool then "true" else "false"; - quote = str: ''"${toString str}"''; - id = x: x; - listToString = sep: f: list: ''{ ${concatStringsSep sep (map f list)} }''; - listToStringOneLine = listToString ", "; - listToStringMultiLine' = listToString ",\n" id; + toLua = value: with builtins; + if value == null then "nil" else + if isBool value then boolToString value else + if isInt value || isFloat value then toString value else + if isString value then string value else + if isAttrs value then attrs value else + if isList value then list value else + abort "should never happen (value = ${value})"; + + string = str: ''"${toString str}"''; + attrs = set: + let + toKeyword = name: value: "${name} = ${toLua value}"; + keywords = concatStringsSep ", " (mapAttrsToList toKeyword set); + in + "{ " + keywords + " }"; + + listContent = values: concatStringsSep ", " (map toLua values); + list = values: "{ " + listContent values + " }"; + + luaList = values: "{" + (concatStringsSep ", " values) + "}"; + keybinding = { key, cmd, func, mode, desc }: let cmdString = - if cmd != null - then quote cmd - else - ( - if func != null - then func - else abort "Either cmd or function must be set" - ); - descString = optionalString (desc != null) "desc = ${quote desc},"; + if cmd != null then toLua cmd else + if func != null then func else + abort "Either cmd or function must be set"; + descString = optionalString (desc != null) "desc = ${toLua desc},"; in - ''{ ${quote key}, ${cmdString}, mode = ${listToStringOneLine quote mode}, ${descString} }''; + ''{ ${toLua key}, ${cmdString}, mode = ${toLua mode}, ${descString} }''; + lazySpecFromPlugin = - { plugin, dependencies, init, conf, lazy, event, enabled, cmd, ft, priority, keys }: - listToStringMultiLine' + { cmd + , conf + , dependencies + , enabled + , event + , ft + , init + , keys + , lazy + , opts + , plugin + , priority + }: + + luaList ([ - "dir = ${quote plugin}" - "name = ${quote (getName plugin)}" + "dir = ${string plugin}" + "name = ${toLua (getName plugin)}" ] - ++ (optional (lazy != null) "lazy = ${boolToString lazy}") - ++ (optional (!enabled) "enabled = ${boolToString enabled}") - ++ (optional (dependencies != [ ]) "dependencies = ${listToStringMultiLine' (map lazySpecFromPlugin dependencies)}") - ++ (optional (init != null) "init = function(plugin)\n${toString init}\nend") - ++ (optional (conf != null) "config = function(plugin, opts)\n${toString conf}\nend") - ++ (optional (keys != [ ]) "keys = ${listToStringMultiLine' (map keybinding keys)}") - ++ (optional (event != [ ]) "event = ${listToStringOneLine quote event}") - ++ (optional (cmd != [ ]) "cmd = ${listToStringOneLine quote cmd}") - ++ (optional (ft != [ ]) "ft = ${listToStringOneLine quote ft}") - ++ (optional (priority != null) "priority = ${toString priority}") + ++ (optional (opts != null) "opts = ${toLua opts}") + ++ (optional (lazy != null) "lazy = ${toLua lazy}") + ++ (optional (!enabled) "enabled = ${toLua enabled}") + ++ (optional (dependencies != [ ]) "dependencies = ${luaList (map lazySpecFromPlugin dependencies)}") + ++ (optional (init != null) "init = function(plugin)\n${init}\nend") + ++ (optional (conf != null) "config = function(plugin, opts)\n${conf}\nend") + ++ (optional (keys != [ ]) "keys = ${luaList (map keybinding keys)}") + ++ (optional (event != [ ]) "event = ${toLua event}") + ++ (optional (cmd != [ ]) "cmd = ${toLua cmd}") + ++ (optional (ft != [ ]) "ft = ${toLua ft}") + ++ (optional (priority != null) "priority = ${toLua priority}") ); - lazySpecs = listToStringMultiLine' (map lazySpecFromPlugin cfg.plugins); + lazySpecs = luaList (map lazySpecFromPlugin cfg.plugins); lazy = /* lua */ '' require("lazy").setup(${lazySpecs}) ''; + + initLua = + let + text = lib.concatLines [ (builtins.readFile ./options.lua) lazy ]; + in + pkgs.runCommand "init.lua" { inherit text; } '' + touch $out + echo -n "$text" > $out + ${getExe pkgs.stylua} $out + ''; + in { - imports = [ ./plugins ]; + imports = lib.my.listModulesRec ./plugins; options.my.programs.nvim = { enable = mkEnableOption "nvim"; @@ -71,6 +104,27 @@ in Lua function to be executed when the plugin is loaded. ''; }; + opts = mkOption { + type = + let + valueType = nullOr + (oneOf [ + str + bool + int + float + (listOf valueType) + (attrsOf valueType) + ]) // { + description = "Lua value"; + }; + in + nullOr (attrsOf valueType); + default = null; + description = '' + Lua table to be passed to te plugin config function. + ''; + }; dependencies = mkOption { type = listOf sub; default = [ ]; @@ -195,17 +249,9 @@ in else neovide ) ]; - xdg.configFile."nvim/init.lua" = { - source = - let - text = lib.concatLines [ (builtins.readFile ./options.lua) lazy ]; - in - pkgs.runCommand "init.lua" { inherit text; } '' - touch $out - echo -n "$text" > $out - ${getExe pkgs.stylua} $out - ''; - }; + + xdg.configFile."nvim/init.lua".source = initLua; + programs.neovim = { enable = true; package = pkgs.neovim-nightly; diff --git a/modules/programs/nvim/plugins/default.nix b/modules/programs/nvim/plugins/coding.nix similarity index 51% rename from modules/programs/nvim/plugins/default.nix rename to modules/programs/nvim/plugins/coding.nix index f4a6780..801f9f0 100644 --- a/modules/programs/nvim/plugins/default.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -1,30 +1,24 @@ -{ lib, pkgs, ... }: +{ pkgs, ... }: with builtins; { config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ - { - plugin = which-key-nvim; - lazy = false; - conf = readFile ./which-key-nvim.lua; - } - { - plugin = catppuccin-nvim; - conf = readFile ./catppuccin-nvim.lua; - lazy = false; - priority = 99; - } { plugin = formatter-nvim; + cmd = [ "Format" "Fmt" ]; keys = [ - { key = "="; cmd = "Format"; desc = "format (formatter)"; } + { + key = "="; + cmd = "Format"; + desc = "format (formatter)"; + } ]; - conf = readFile ./formatter-nvim.lua; + conf = readFile ./lua/formatter-nvim.lua; } { plugin = oil-nvim; lazy = false; - conf = readFile ./oil-nvim.lua; + opts = { }; dependencies = [ { plugin = which-key-nvim; } { plugin = nvim-web-devicons; } @@ -33,7 +27,7 @@ with builtins; { plugin = mini-nvim; lazy = false; - conf = readFile ./mini-nvim.lua; + conf = readFile ./lua/mini-nvim.lua; } { plugin = trouble-nvim; @@ -44,31 +38,35 @@ with builtins; { key = "xq"; cmd = "TroubleToggle quickfix"; desc = "Quickfix List (Trouble)"; } { key = "xt"; cmd = "TodoTrouble"; desc = "Todo (Trouble)"; } { key = "xT"; cmd = "TodoTrouble keywords=TODO,FIX,FIXME"; desc = "Todo/Fix/Fixme (Trouble)"; } - { key = "st"; cmd = "TodoTelescope"; desc = "Todo"; } + { key = "ft"; cmd = "TodoTelescope"; desc = "Todo"; } { key = "[q"; - func = /* lua */ ''function() - if require("trouble").is_open() then - require("trouble").previous({ skip_groups = true, jump = true }) - else - vim.cmd.cprev() - end - end''; + func = /* lua */ '' + function() + if require("trouble").is_open() then + require("trouble").previous({ skip_groups = true, jump = true }) + else + vim.cmd.cprev() + end + end + ''; desc = "Previous trouble/quickfix item"; } { key = "]q"; - func = /* lua */ ''function() - if require("trouble").is_open() then - require("trouble").next({ skip_groups = true, jump = true }) - else - vim.cmd.cnext() - end - end''; + func = /* lua */ '' + function() + if require("trouble").is_open() then + require("trouble").next({ skip_groups = true, jump = true }) + else + vim.cmd.cnext() + end + end + ''; desc = "Next trouble/quickfix item"; } ]; - conf = readFile ./trouble-nvim.lua; + opts = { }; dependencies = [ { plugin = which-key-nvim; } { plugin = nvim-web-devicons; } @@ -76,14 +74,12 @@ with builtins; } { plugin = nvim-cmp; - conf = readFile ./nvim-cmp.lua; + conf = readFile ./lua/nvim-cmp.lua; event = [ "InsertEnter" ]; dependencies = [ { plugin = nvim-autopairs; - conf = /* lua */ '' - require("nvim-autopairs").setup({}) - ''; + opts = { }; } { plugin = cmp-async-path; } { plugin = cmp-buffer; } @@ -92,55 +88,26 @@ with builtins; { plugin = cmp_luasnip; } { plugin = codeium-nvim; - conf = /* lua */ '' - require("codeium").setup({}) - ''; + opts = { }; } { plugin = friendly-snippets; } { plugin = lspkind-nvim; } { plugin = luasnip; } ]; } - { - plugin = todo-comments-nvim; - event = [ "BufReadPost" "BufNewFile" ]; - conf = readFile ./todo-comments-nvim.lua; - dependencies = [{ plugin = plenary-nvim; }]; - } { plugin = direnv-vim; lazy = false; } - { - plugin = nvim-treesitter; - event = [ "BufReadPost" "BufNewFile" ]; - conf = - let - parserDir = pkgs.symlinkJoin { - name = "tresitter-grammars-all"; - paths = lib.attrValues (lib.filterAttrs (_: builtins.isAttrs) nvim-treesitter-parsers); - }; - in - readFile ./nvim-treesitter.lua + '' - vim.opt.runtimepath:append("${parserDir}") - - require'nvim-treesitter.configs'.setup { - parser_install_dir = "${parserDir}", - } - ''; - dependencies = [ - { plugin = nvim-ts-context-commentstring; } - ]; - } { plugin = nvim-lspconfig; event = [ "BufRead" "BufNewFile" ]; - conf = readFile ./nvim-lspconfig.lua; + conf = readFile ./lua/nvim-lspconfig.lua; dependencies = [ { plugin = lsp_signature-nvim; } { plugin = null-ls-nvim; - conf = readFile ./null-ls-nvim.lua; + conf = readFile ./lua/null-ls-nvim.lua; dependencies = [ { plugin = which-key-nvim; } { plugin = plenary-nvim; } @@ -150,36 +117,27 @@ with builtins; { plugin = lsp_lines-nvim; } { plugin = nvim-ufo; - conf = readFile ./nvim-ufo.lua; + conf = readFile ./lua/nvim-ufo.lua; dependencies = [ { plugin = promise-async; } ]; } { plugin = neodev-nvim; - conf = readFile ./neodev-nvim.lua; + conf = readFile ./lua/neodev-nvim.lua; } { plugin = inc-rename-nvim; - conf = /* lua */ '' - require("inc_rename").setup { - input_buffer_type = "dressing", - } - ''; + opts = { + input_buffer_type = "dressing"; + }; dependencies = [ - { - plugin = dressing-nvim; - } + { plugin = dressing-nvim; } ]; } { plugin = actions-preview-nvim; } ]; } - { - plugin = statuscol-nvim; - event = [ "VeryLazy" ]; - conf = readFile ./statuscol-nvim.lua; - } { plugin = vim-fugitive; cmd = [ @@ -212,44 +170,25 @@ with builtins; plugin = vim-tmux-navigator; event = [ "VeryLazy" ]; } - { - plugin = gitsigns-nvim; - event = [ "BufReadPost" "BufNewFile" ]; - conf = readFile ./gitsigns-nvim.lua; - dependencies = [{ plugin = which-key-nvim; }]; - } { plugin = nvim-lastplace; event = [ "BufReadPost" "BufNewFile" ]; - conf = readFile ./nvim-lastplace.lua; - } - { - plugin = nvim-treesitter-textsubjects; - event = [ "BufReadPost" "BufNewFile" ]; - conf = readFile ./nvim-treesitter-textsubjects.lua; - } - { - plugin = smartcolumn-nvim; - event = [ "BufReadPost" "BufNewFile" ]; - conf = readFile ./smartcolumn-nvim.lua; + opts = { + lastplace_ignore_buftype = [ "quickfix" "nofile" "help" ]; + lastplace_ignore_filetype = [ "gitcommit" "gitrebase" "svn" "hgcommit" ]; + lastplace_open_folds = true; + }; } { plugin = telescope-nvim; cmd = [ "Telescope" ]; - conf = builtins.readFile ./telescope.lua; + conf = builtins.readFile ./lua/telescope.lua; keys = [ { key = "ff"; cmd = "Telescope find_files"; desc = "Find files"; } { key = "fb"; cmd = "Telescope buffers"; desc = "Find buffers"; } - { key = "fr"; cmd = "Telescope oldfiles"; desc = "Find recent files"; } - { key = "sl"; cmd = "Telescope current_buffer_fuzzy_find"; desc = "Search lines"; } - { key = "sg"; cmd = "Telescope live_grep"; desc = "Live grep"; } - { key = "sc"; cmd = "Telescope command_history"; desc = "Command history"; } - { key = "sC"; cmd = "Telescope commands"; desc = "Commands"; } - { key = "sd"; cmd = "Telescope diagnostics"; desc = "Diagnostics"; } - { key = "sh"; cmd = "Telescope help_tags"; desc = "Help tags"; } - { key = "sk"; cmd = "Telescope keymaps"; desc = "Keymaps"; } - { key = "ss"; cmd = "Telescope lsp_document_symbols"; desc = "Symbols (Document)"; } - { key = "sS"; cmd = "Telescope lsp_workspace_symbols"; desc = "Symbols (Workspace)"; } + { key = "fl"; cmd = "Telescope current_buffer_fuzzy_find"; desc = "Search lines"; } + { key = "fg"; cmd = "Telescope live_grep"; desc = "Live grep"; } + { key = "fh"; cmd = "Telescope help_tags"; desc = "Help tags"; } ]; dependencies = [ { plugin = plenary-nvim; } @@ -260,7 +199,7 @@ with builtins; { plugin = vim-startuptime; cmd = [ "StartupTime" ]; - conf = readFile ./vim-startuptime.lua; + conf = readFile ./lua/vim-startuptime.lua; } { plugin = typst-vim; @@ -269,47 +208,28 @@ with builtins; { plugin = comment-nvim; event = [ "BufReadPost" "BufNewFile" ]; - conf = /* lua */ '' - require("Comment").setup() - ''; + opts = { }; } { plugin = telekasten-nvim; dependencies = [ { plugin = telescope-nvim; } { plugin = which-key-nvim; } + { + plugin = markdown-preview-nvim; + ft = [ "md" ]; + } ]; cmd = [ "Telekasten" ]; keys = [ { key = "z"; cmd = "Telekasten"; desc = "zettelkasten"; } ]; - conf = builtins.readFile ./zettelkasten-nvim.lua; - } - { - plugin = markdown-preview-nvim; - ft = [ "md" ]; + conf = builtins.readFile ./lua/zettelkasten-nvim.lua; } { plugin = nvim-surround; event = [ "BufReadPost" "BufNewFile" ]; - conf = /* lua */ '' - require("nvim-surround").setup({}) - ''; - } - { - plugin = nvim-treesitter-context; - event = [ "BufReadPost" "BufNewFile" ]; - conf = /* lua */ '' - require("treesitter-context").setup({}) - ''; - } - { - plugin = dressing-nvim; - event = [ "VeryLazy" ]; - } - { - plugin = hmts-nvim; - ft = [ "nix" ]; + opts = { }; } { plugin = zen-mode-nvim; @@ -320,5 +240,30 @@ with builtins; { plugin = twilight-nvim; } ]; } + { + plugin = refactoring-nvim; + keys = [ + { key = "re"; cmd = ": Refactor eextract "; desc = "Extract"; mode = [ "x" ]; } + { key = "rf"; cmd = ": Refactor extract_to_file "; desc = "Extract to file"; mode = [ "x" ]; } + { key = "rv"; cmd = ": Refactor extract_var "; desc = "Extract variable"; mode = [ "x" ]; } + { key = "ri"; cmd = ": Refactor inline_var"; desc = "Inline variable"; mode = [ "n" "x" ]; } + { key = "rI"; cmd = ": Refactor inline_func"; desc = "Inline function"; mode = [ "n" "x" ]; } + { key = "rb"; cmd = ": Refactor extract_block"; desc = "Extract block"; mode = [ "n" ]; } + { key = "rbf"; cmd = ": Refactor extract_block_to_file"; desc = "Extract block to file"; mode = [ "n" ]; } + ]; + dependencies = [ + { plugin = which-key-nvim; } + { plugin = plenary-nvim; } + { plugin = nvim-lspconfig; } + ]; + init = /* lua */ '' + require("which-key").register({ + ["r"] = { + name = "refactoring", + }, + }) + ''; + opts = { }; + } ]; } diff --git a/modules/programs/nvim/plugins/copilot-lua.lua b/modules/programs/nvim/plugins/copilot-lua.lua deleted file mode 100644 index f9799dc..0000000 --- a/modules/programs/nvim/plugins/copilot-lua.lua +++ /dev/null @@ -1,5 +0,0 @@ -require("copilot").setup({ - suggestion = { enabled = false }, - panel = { enabled = false }, -}) -vim.cmd("Copilot disable") diff --git a/modules/programs/nvim/plugins/catppuccin-nvim.lua b/modules/programs/nvim/plugins/lua/catppuccin-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/catppuccin-nvim.lua rename to modules/programs/nvim/plugins/lua/catppuccin-nvim.lua diff --git a/modules/programs/nvim/plugins/formatter-nvim.lua b/modules/programs/nvim/plugins/lua/formatter-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/formatter-nvim.lua rename to modules/programs/nvim/plugins/lua/formatter-nvim.lua diff --git a/modules/programs/nvim/plugins/gitsigns-nvim.lua b/modules/programs/nvim/plugins/lua/gitsigns-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/gitsigns-nvim.lua rename to modules/programs/nvim/plugins/lua/gitsigns-nvim.lua diff --git a/modules/programs/nvim/plugins/mini-nvim.lua b/modules/programs/nvim/plugins/lua/mini-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/mini-nvim.lua rename to modules/programs/nvim/plugins/lua/mini-nvim.lua diff --git a/modules/programs/nvim/plugins/neodev-nvim.lua b/modules/programs/nvim/plugins/lua/neodev-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/neodev-nvim.lua rename to modules/programs/nvim/plugins/lua/neodev-nvim.lua diff --git a/modules/programs/nvim/plugins/noice-nvim.lua b/modules/programs/nvim/plugins/lua/noice-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/noice-nvim.lua rename to modules/programs/nvim/plugins/lua/noice-nvim.lua diff --git a/modules/programs/nvim/plugins/null-ls-nvim.lua b/modules/programs/nvim/plugins/lua/null-ls-nvim.lua similarity index 93% rename from modules/programs/nvim/plugins/null-ls-nvim.lua rename to modules/programs/nvim/plugins/lua/null-ls-nvim.lua index c689fad..6701630 100644 --- a/modules/programs/nvim/plugins/null-ls-nvim.lua +++ b/modules/programs/nvim/plugins/lua/null-ls-nvim.lua @@ -3,7 +3,6 @@ local null_ls = require("null-ls") null_ls.setup({ sources = { -- Code actions - null_ls.builtins.code_actions.gitsigns, null_ls.builtins.code_actions.shellcheck, null_ls.builtins.code_actions.statix, -- Completion diff --git a/modules/programs/nvim/plugins/nvim-cmp.lua b/modules/programs/nvim/plugins/lua/nvim-cmp.lua similarity index 100% rename from modules/programs/nvim/plugins/nvim-cmp.lua rename to modules/programs/nvim/plugins/lua/nvim-cmp.lua diff --git a/modules/programs/nvim/plugins/nvim-lspconfig.lua b/modules/programs/nvim/plugins/lua/nvim-lspconfig.lua similarity index 100% rename from modules/programs/nvim/plugins/nvim-lspconfig.lua rename to modules/programs/nvim/plugins/lua/nvim-lspconfig.lua diff --git a/modules/programs/nvim/plugins/nvim-treesitter-textsubjects.lua b/modules/programs/nvim/plugins/lua/nvim-treesitter-textsubjects.lua similarity index 100% rename from modules/programs/nvim/plugins/nvim-treesitter-textsubjects.lua rename to modules/programs/nvim/plugins/lua/nvim-treesitter-textsubjects.lua diff --git a/modules/programs/nvim/plugins/nvim-treesitter.lua b/modules/programs/nvim/plugins/lua/nvim-treesitter.lua similarity index 100% rename from modules/programs/nvim/plugins/nvim-treesitter.lua rename to modules/programs/nvim/plugins/lua/nvim-treesitter.lua diff --git a/modules/programs/nvim/plugins/nvim-ufo.lua b/modules/programs/nvim/plugins/lua/nvim-ufo.lua similarity index 100% rename from modules/programs/nvim/plugins/nvim-ufo.lua rename to modules/programs/nvim/plugins/lua/nvim-ufo.lua diff --git a/modules/programs/nvim/plugins/statuscol-nvim.lua b/modules/programs/nvim/plugins/lua/statuscol-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/statuscol-nvim.lua rename to modules/programs/nvim/plugins/lua/statuscol-nvim.lua diff --git a/modules/programs/nvim/plugins/telescope.lua b/modules/programs/nvim/plugins/lua/telescope.lua similarity index 100% rename from modules/programs/nvim/plugins/telescope.lua rename to modules/programs/nvim/plugins/lua/telescope.lua diff --git a/modules/programs/nvim/plugins/vim-startuptime.lua b/modules/programs/nvim/plugins/lua/vim-startuptime.lua similarity index 100% rename from modules/programs/nvim/plugins/vim-startuptime.lua rename to modules/programs/nvim/plugins/lua/vim-startuptime.lua diff --git a/modules/programs/nvim/plugins/which-key-nvim.lua b/modules/programs/nvim/plugins/lua/which-key-nvim.lua similarity index 66% rename from modules/programs/nvim/plugins/which-key-nvim.lua rename to modules/programs/nvim/plugins/lua/which-key-nvim.lua index 09f227f..aa3c8a9 100644 --- a/modules/programs/nvim/plugins/which-key-nvim.lua +++ b/modules/programs/nvim/plugins/lua/which-key-nvim.lua @@ -1,14 +1,16 @@ vim.o.timeout = true vim.o.timeoutlen = 500 --- buffer +-- Delete require("which-key").register({ - b = { - name = "buffer", - b = { "Telescope buffers", "List buffers" }, - d = { "bd", "Delete buffer" }, + d = { + name = "delete", + b = { "bd", "Delete buffer" }, + w = { "c", "Delete window" }, }, }, { prefix = "" }) + +-- buffer require("which-key").register({ ["["] = { b = { "bprevious", "Previous buffer" }, @@ -25,32 +27,6 @@ require("which-key").register({ ["|"] = { "v", "Split window horizontally" }, ["-"] = { "s", "Split window vertically" }, w = { "w", "Switch window" }, - d = { "c", "Delete window" }, - }, -}, { prefix = "" }) - --- tab -require("which-key").register({ - [""] = { - name = "tab", - [""] = { "tabnew", "New tab" }, - d = { "tabclose", "Close tab" }, - }, -}, { prefix = "" }) -require("which-key").register({ - ["["] = { - t = { "tabprevious", "Previous tab" }, - }, - ["]"] = { - t = { "tabnext", "Next tab" }, - }, -}) - --- file -require("which-key").register({ - f = { - name = "file/find", - n = { "enew", "New file" }, }, }, { prefix = "" }) diff --git a/modules/programs/nvim/plugins/zettelkasten-nvim.lua b/modules/programs/nvim/plugins/lua/zettelkasten-nvim.lua similarity index 100% rename from modules/programs/nvim/plugins/zettelkasten-nvim.lua rename to modules/programs/nvim/plugins/lua/zettelkasten-nvim.lua diff --git a/modules/programs/nvim/plugins/nvim-lastplace.lua b/modules/programs/nvim/plugins/nvim-lastplace.lua deleted file mode 100644 index d97700f..0000000 --- a/modules/programs/nvim/plugins/nvim-lastplace.lua +++ /dev/null @@ -1,5 +0,0 @@ -require("nvim-lastplace").setup({ - lastplace_ignore_buftype = { "quickfix", "nofile", "help" }, - lastplace_ignore_filetype = { "gitcommit", "gitrebase", "svn", "hgcommit" }, - lastplace_open_folds = true, -}) diff --git a/modules/programs/nvim/plugins/oil-nvim.lua b/modules/programs/nvim/plugins/oil-nvim.lua deleted file mode 100644 index 6c9c81e..0000000 --- a/modules/programs/nvim/plugins/oil-nvim.lua +++ /dev/null @@ -1,4 +0,0 @@ -require("oil").setup() -require("which-key").register({ - d = { require("oil").toggle_float, "Directory (oil)" }, -}, { prefix = "t" }) diff --git a/modules/programs/nvim/plugins/smartcolumn-nvim.lua b/modules/programs/nvim/plugins/smartcolumn-nvim.lua deleted file mode 100644 index c095401..0000000 --- a/modules/programs/nvim/plugins/smartcolumn-nvim.lua +++ /dev/null @@ -1,4 +0,0 @@ -require("smartcolumn").setup({ - colorcolumn = "120", - disabled_filetypes = { "help", "text", "markdown", "dashboard" }, -}) diff --git a/modules/programs/nvim/plugins/todo-comments-nvim.lua b/modules/programs/nvim/plugins/todo-comments-nvim.lua deleted file mode 100644 index 57fce71..0000000 --- a/modules/programs/nvim/plugins/todo-comments-nvim.lua +++ /dev/null @@ -1 +0,0 @@ -require("todo-comments").setup() diff --git a/modules/programs/nvim/plugins/treesitter.nix b/modules/programs/nvim/plugins/treesitter.nix new file mode 100644 index 0000000..d4c3cf0 --- /dev/null +++ b/modules/programs/nvim/plugins/treesitter.nix @@ -0,0 +1,42 @@ +{ lib, pkgs, ... }: + +with builtins; +{ + config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ + { + plugin = nvim-treesitter; + event = [ "BufReadPost" "BufNewFile" ]; + conf = + let + parserDir = pkgs.symlinkJoin { + name = "tresitter-grammars-all"; + paths = lib.attrValues (lib.filterAttrs (_: builtins.isAttrs) nvim-treesitter-parsers); + }; + in + readFile ./lua/nvim-treesitter.lua + '' + vim.opt.runtimepath:append("${parserDir}") + + require'nvim-treesitter.configs'.setup { + parser_install_dir = "${parserDir}", + } + ''; + dependencies = [ + { plugin = nvim-ts-context-commentstring; } + ]; + } + { + plugin = nvim-treesitter-textsubjects; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./lua/nvim-treesitter-textsubjects.lua; + } + { + plugin = nvim-treesitter-context; + event = [ "BufReadPost" "BufNewFile" ]; + opts = { }; + } + { + plugin = hmts-nvim; + ft = [ "nix" ]; + } + ]; +} diff --git a/modules/programs/nvim/plugins/trouble-nvim.lua b/modules/programs/nvim/plugins/trouble-nvim.lua deleted file mode 100644 index 38ef1e9..0000000 --- a/modules/programs/nvim/plugins/trouble-nvim.lua +++ /dev/null @@ -1 +0,0 @@ -require("trouble").setup() diff --git a/modules/programs/nvim/plugins/ui.nix b/modules/programs/nvim/plugins/ui.nix new file mode 100644 index 0000000..0e535c4 --- /dev/null +++ b/modules/programs/nvim/plugins/ui.nix @@ -0,0 +1,47 @@ +{ pkgs, ... }: + +with builtins; +{ + config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ + { + plugin = which-key-nvim; + lazy = false; + conf = readFile ./lua/which-key-nvim.lua; + } + { + plugin = catppuccin-nvim; + conf = readFile ./lua/catppuccin-nvim.lua; + lazy = false; + priority = 99; + } + { + plugin = todo-comments-nvim; + event = [ "BufReadPost" "BufNewFile" ]; + dependencies = [{ plugin = plenary-nvim; }]; + opts = { }; + } + { + plugin = statuscol-nvim; + event = [ "VeryLazy" ]; + conf = readFile ./lua/statuscol-nvim.lua; + } + { + plugin = smartcolumn-nvim; + event = [ "BufReadPost" "BufNewFile" ]; + opts = { + colorcolumn = "120"; + disabled_filetypes = [ "help" "text" "markdown" "dashboard" ]; + }; + } + { + plugin = dressing-nvim; + event = [ "VeryLazy" ]; + } + { + plugin = gitsigns-nvim; + event = [ "BufReadPost" "BufNewFile" ]; + conf = readFile ./lua/gitsigns-nvim.lua; + dependencies = [{ plugin = which-key-nvim; }]; + } + ]; +} From cc72c96512ba6decb4bf0202c005ce02173fbbd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 10 Sep 2023 13:35:01 +0200 Subject: [PATCH 2/9] feat(base): add nixos-test command --- modules/profiles/base.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index 830069d..459a65d 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -149,6 +149,7 @@ in # nix (nom-system-command "nixos-boot" "sudo nixos-rebuild boot --flake ~/.dotfiles") (nom-system-command "nixos-switch" "sudo nixos-rebuild switch --flake ~/.dotfiles") + (nom-system-command "nixos-test" "sudo nixos-rebuild test --flake ~/.dotfiles") manix nix-index nix-output-monitor From d6ad8105680fe53708e1705d61a412c4a40b6b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 10 Sep 2023 13:35:13 +0200 Subject: [PATCH 3/9] feat(nvim): add harpoon --- modules/programs/nvim/plugins/coding.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index 0242af5..79a94bc 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -289,5 +289,17 @@ with builtins; ''; opts = { }; } + { + plugin = harpoon; + keys = [ + { key = "ha"; cmd = "lua require('harpoon.mark').add_file()"; desc = "Add file"; } + { key = "hh"; cmd = "lua require('harpoon.ui').toggle_quick_menu()"; desc = "Harpoon"; } + { key = "h1"; cmd = "lua require('harpoon.ui').nav_file(1)"; desc = "Harpoon file 1"; } + { key = "h2"; cmd = "lua require('harpoon.ui').nav_file(2)"; desc = "Harpoon file 2"; } + { key = "h3"; cmd = "lua require('harpoon.ui').nav_file(3)"; desc = "Harpoon file 3"; } + { key = "h4"; cmd = "lua require('harpoon.ui').nav_file(4)"; desc = "Harpoon file 4"; } + ]; + opts = { }; + } ]; } From 749e2cf67d5c5515cf304a26ac51f7c597712066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 10 Sep 2023 15:05:56 +0200 Subject: [PATCH 4/9] refactor: remove hyrpland overlay --- flake.nix | 1 - modules/programs/hyprland/default.nix | 3 ++- overlays/packages.nix | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 91ccddd..4ba9684 100644 --- a/flake.nix +++ b/flake.nix @@ -86,7 +86,6 @@ overlays = [ inputs.hypr-contrib.overlays.default - inputs.hyprland.overlays.default inputs.neovim-nightly-overlay.overlay overlay ]; diff --git a/modules/programs/hyprland/default.nix b/modules/programs/hyprland/default.nix index e208565..7c1cefa 100644 --- a/modules/programs/hyprland/default.nix +++ b/modules/programs/hyprland/default.nix @@ -9,7 +9,8 @@ with lib; let cfg = config.my.programs.hyprland; - hyprland = pkgs.hyprland.override { enableNvidiaPatches = cfg.nvidiaSupport; }; + hyprland-nvidia = pkgs.hyprland.override { enableNvidiaPatches = true; }; + hyprland = if cfg.nvidiaSupport then hyprland-nvidia else pkgs.hyprland; in { options.my.programs.hyprland = { diff --git a/overlays/packages.nix b/overlays/packages.nix index 66b2624..973523e 100644 --- a/overlays/packages.nix +++ b/overlays/packages.nix @@ -11,6 +11,7 @@ final: prev: version = lib.my.mkVersionInput inputs.rofi-wayland; }); timers = inputs.timers.packages.${prev.system}.default; + hyprland = inputs.hyprland.packages.${prev.system}.default; fzf1 = final.writeShellApplication { name = "fzf1"; From 372ee5985abdb43b4e2caff4ecc241a833766c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 10 Sep 2023 15:07:55 +0200 Subject: [PATCH 5/9] refactor: small changes --- modules/profiles/base.nix | 66 +++++++++++++++++++------------- modules/programs/fish.nix | 9 +++-- modules/services/openconnect.nix | 2 +- overlays/builders.nix | 63 +++++++++++++++++++----------- 4 files changed, 86 insertions(+), 54 deletions(-) diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index aefaac4..b22c622 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -34,42 +34,54 @@ let which-nix = pkgs.writeFishApplication { name = "which-nix"; - runtimeInputs = with pkgs; [ which coreutils-full ]; + runtimeInputs = with pkgs; [ which coreutils-full procps ]; text = /* fish */ '' - readlink -f (which $argv) + function recurse -a path; + if not test -f "$path" + return + end + + echo $path + if test -L $path + recurse (readlink $path) + end + end + + for arg in $argv + recurse (which $arg) + end ''; completions = /* fish */ '' complete -c which-nix -fa '(__fish_complete_command)' ''; }; - gi = pkgs.writeFishApplication - { - name = "gi"; - runtimeInputs = with pkgs; [ fzf gum curl ]; - text = /* fish */ '' - set url https://www.gitignore.io/api + gi = pkgs.writeFishApplication { + name = "gi"; + runtimeInputs = with pkgs; [ fzf gum curl ]; + text = /* fish */ '' + set url https://www.gitignore.io/api - if test (count $argv) -eq 0 - set choice ( curl -sL $url/list \ - | string split "," \ - | fzf -m \ - | string join "," ) - else - set choice (string join "," $argv[1..]) - end + if test (count $argv) -eq 0 + set choice ( curl -sL $url/list \ + | string split "," \ + | fzf -m \ + | string join "," ) + else + set choice (string join "," $argv[1..]) + end - if gum confirm "Overwrite current .gitignore?" - curl -sL $url/$choice > .gitignore - else - curl -sL $url/$choice >> .gitignore - end - ''; - completions = /* fish */ '' - set args (curl -sL https://www.gitignore.io/api/list | string split ",") - complete -c gi -fa "$args" - ''; - }; + if gum confirm "Overwrite current .gitignore?" + curl -sL $url/$choice > .gitignore + else + curl -sL $url/$choice >> .gitignore + end + ''; + completions = /* fish */ '' + set args (curl -sL https://www.gitignore.io/api/list | string split ",") + complete -c gi -fa "$args" + ''; + }; in { users.users.moritz = { diff --git a/modules/programs/fish.nix b/modules/programs/fish.nix index de683ab..f6e8c92 100644 --- a/modules/programs/fish.nix +++ b/modules/programs/fish.nix @@ -8,9 +8,12 @@ with lib; let cfg = config.my.programs.fish; shellConfig = config.my.shell; - exportVariables = - lib.mapAttrsToList (n: v: ''set -x ${n} "${v}"'') shellConfig.variables; - exportedVariables = lib.concatStringsSep "\n" exportVariables; + exportedVariables = + let + exportVariables = + lib.mapAttrsToList (n: v: ''set -x ${n} "${v}"'') shellConfig.variables; + in + lib.concatStringsSep "\n" exportVariables; in { options.my.programs.fish.enable = mkEnableOption "fish"; diff --git a/modules/services/openconnect.nix b/modules/services/openconnect.nix index 87c37a1..6eddd64 100644 --- a/modules/services/openconnect.nix +++ b/modules/services/openconnect.nix @@ -17,7 +17,7 @@ in gateway = "vpn.uni-leipzig.de"; protocol = "anyconnect"; user = "mb18cele@uni-leipzig.de"; - # NOTE file content as follows: + # NOTE: file content as follows: # # "1-Standard-Uni" or "2-Spezial-Alles" # Explanation: diff --git a/overlays/builders.nix b/overlays/builders.nix index 813b7d3..359a4af 100644 --- a/overlays/builders.nix +++ b/overlays/builders.nix @@ -2,7 +2,33 @@ _: final: _: with final.lib; -{ +rec { + fishFile = + { name + , destination + , content + , checkPhase ? null + }: + final.writeTextFile { + inherit name destination; + executable = true; + allowSubstitutes = true; + preferLocalBuild = false; + text = '' + #!${getExe final.fish} + + ${content} + ''; + + checkPhase = + if checkPhase == null then '' + runHook preCheck + ${getExe final.fish} -n "$target" + runHook postCheck + '' + else checkPhase; + }; + writeFishApplication = { name , text @@ -11,30 +37,21 @@ with final.lib; , checkPhase ? null }: let - fishFile = destination: content: final.writeTextFile { - inherit name destination; - executable = true; - allowSubstitutes = true; - preferLocalBuild = false; - text = '' - #!${getExe final.fish} + runtimeHeader = optionalString (runtimeInputs != [ ]) + ''export PATH="${makeBinPath runtimeInputs}:$PATH"''; - ${optionalString (runtimeInputs != [ ]) ''export PATH="${makeBinPath runtimeInputs}:$PATH"''} - - ${content} - ''; - - checkPhase = - if checkPhase == null then '' - runHook preCheck - ${getExe final.fish} -n "$target" - runHook postCheck - '' - else checkPhase; + script = fishFile { + inherit checkPhase; + name = "${name}_script"; + destination = "/bin/${name}"; + content = concatLines [ runtimeHeader text ]; + }; + completions_file = fishFile { + inherit checkPhase; + name = "${name}_completions"; + destination = "/share/fish/vendor_completions.d/${name}.fish"; + content = concatLines [ runtimeHeader completions ]; }; - - script = fishFile "/bin/${name}" text; - completions_file = fishFile "/share/fish/vendor_completions.d/${name}.fish" completions; in final.symlinkJoin { inherit name; From b0f07137811d1df70e1963a1f0a4e6452271a626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 17 Sep 2023 09:25:50 +0200 Subject: [PATCH 6/9] feat(nvim)!: remove deprecated codeium extension --- flake.lock | 47 ++----------------- flake.nix | 2 - modules/programs/nvim/plugins/coding.nix | 4 -- .../programs/nvim/plugins/lua/nvim-cmp.lua | 5 +- overlays/vimPlugins.nix | 2 - 5 files changed, 6 insertions(+), 54 deletions(-) diff --git a/flake.lock b/flake.lock index dafb7f2..a66d563 100644 --- a/flake.lock +++ b/flake.lock @@ -71,27 +71,6 @@ "type": "github" } }, - "codeium-nvim": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1693966170, - "narHash": "sha256-maRkkUCzjSXK04ts+Io0WFBV1MxR7dCw8I6TV03Dpbs=", - "owner": "jcdickinson", - "repo": "codeium.nvim", - "rev": "6a8cbce54c41e0c305b5f77721f61b2ddd4b6c6d", - "type": "github" - }, - "original": { - "owner": "jcdickinson", - "repo": "codeium.nvim", - "type": "github" - } - }, "darwin": { "inputs": { "nixpkgs": [ @@ -224,21 +203,6 @@ } }, "flake-utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { "inputs": { "systems": "systems" }, @@ -256,7 +220,7 @@ "type": "github" } }, - "flake-utils_3": { + "flake-utils_2": { "inputs": { "systems": "systems_3" }, @@ -274,7 +238,7 @@ "type": "github" } }, - "flake-utils_4": { + "flake-utils_3": { "inputs": { "systems": "systems_4" }, @@ -566,7 +530,7 @@ }, "neovim-flake": { "inputs": { - "flake-utils": "flake-utils_3", + "flake-utils": "flake-utils_2", "nixpkgs": [ "neovim-nightly-overlay", "nixpkgs" @@ -855,7 +819,7 @@ "pre-commit-hooks": { "inputs": { "flake-compat": "flake-compat_3", - "flake-utils": "flake-utils_4", + "flake-utils": "flake-utils_3", "gitignore": "gitignore", "nixpkgs": "nixpkgs_7", "nixpkgs-stable": "nixpkgs-stable" @@ -897,8 +861,7 @@ "agenix": "agenix", "arkenfox-userjs": "arkenfox-userjs", "asus-touchpad-numpad-driver": "asus-touchpad-numpad-driver", - "codeium-nvim": "codeium-nvim", - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils", "hmts-nvim": "hmts-nvim", "home-manager": "home-manager_2", "hypr-contrib": "hypr-contrib", diff --git a/flake.nix b/flake.nix index f3bc896..5c91c13 100644 --- a/flake.nix +++ b/flake.nix @@ -53,8 +53,6 @@ actions-preview-nvim.flake = false; actions-preview-nvim.url = "github:aznhe21/actions-preview.nvim"; - codeium-nvim.url = "github:jcdickinson/codeium.nvim"; - codeium-nvim.inputs.nixpkgs.follows = "nixpkgs"; # Hyprland hypr-contrib.url = "github:hyprwm/contrib"; diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index 79a94bc..e44d7ab 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -86,10 +86,6 @@ with builtins; { plugin = cmp-cmdline; } { plugin = cmp-nvim-lsp; } { plugin = cmp_luasnip; } - { - plugin = codeium-nvim; - opts = { }; - } { plugin = friendly-snippets; } { plugin = lspkind-nvim; } { plugin = luasnip; } diff --git a/modules/programs/nvim/plugins/lua/nvim-cmp.lua b/modules/programs/nvim/plugins/lua/nvim-cmp.lua index 1a8a070..437c4e9 100644 --- a/modules/programs/nvim/plugins/lua/nvim-cmp.lua +++ b/modules/programs/nvim/plugins/lua/nvim-cmp.lua @@ -8,9 +8,7 @@ cmp.setup({ mode = "symbol", -- show only symbol annotations maxwidth = 50, -- prevent the popup from showing more than provided characters ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead - symbol_map = { - Codeium = "", - }, + symbol_map = {}, }), }, snippet = { @@ -48,7 +46,6 @@ cmp.setup({ { name = "async_path", priority = 1 }, { name = "buffer", priority = 1 }, { name = "luasnip", priority = 2 }, - { name = "codeium", priority = 3 }, { name = "nvim_lsp", priority = 4 }, }, }) diff --git a/overlays/vimPlugins.nix b/overlays/vimPlugins.nix index 39f81d4..7cafdf5 100644 --- a/overlays/vimPlugins.nix +++ b/overlays/vimPlugins.nix @@ -4,8 +4,6 @@ _: prev: with lib.my; { vimPlugins = prev.vimPlugins // { - inherit (inputs.codeium-nvim.packages.${prev.system}.vimPlugins) codeium-nvim; - smartcolumn-nvim = prev.vimUtils.buildVimPluginFrom2Nix { pname = "smartcolumn-nvim"; version = mkVersionInput inputs.smartcolumn-nvim; From bfbc3ad24f9fd799ee7146cca356f7c283b753b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 17 Sep 2023 09:35:10 +0200 Subject: [PATCH 7/9] feat(nvim): add NixLazy.nvim --- flake.nix | 2 + modules/programs/nvim/default.nix | 248 +------------------ modules/programs/nvim/plugins/coding.nix | 4 +- modules/programs/nvim/plugins/treesitter.nix | 2 +- modules/programs/nvim/plugins/ui.nix | 2 +- 5 files changed, 9 insertions(+), 249 deletions(-) diff --git a/flake.nix b/flake.nix index 5c91c13..af999bc 100644 --- a/flake.nix +++ b/flake.nix @@ -53,6 +53,7 @@ actions-preview-nvim.flake = false; actions-preview-nvim.url = "github:aznhe21/actions-preview.nvim"; + nix-lazy-nvim.url = "git+https://git.moritzboeh.me/moritz/NixLazy.nvim"; # Hyprland hypr-contrib.url = "github:hyprwm/contrib"; @@ -126,6 +127,7 @@ useGlobalPkgs = true; useUserPackages = true; extraSpecialArgs = { inherit inputs self; }; + sharedModules = [ inputs.nix-lazy-nvim.homeManagerModules.default ]; }; } inputs.agenix.nixosModules.age diff --git a/modules/programs/nvim/default.nix b/modules/programs/nvim/default.nix index 4d95a7b..bd14433 100644 --- a/modules/programs/nvim/default.nix +++ b/modules/programs/nvim/default.nix @@ -3,242 +3,11 @@ with lib; let cfg = config.my.programs.nvim; - toLua = value: with builtins; - if value == null then "nil" else - if isBool value then boolToString value else - if isInt value || isFloat value then toString value else - if isString value then string value else - if isAttrs value then attrs value else - if isList value then list value else - abort "should never happen (value = ${value})"; - - string = str: ''"${toString str}"''; - attrs = set: - let - toKeyword = name: value: "${name} = ${toLua value}"; - keywords = concatStringsSep ", " (mapAttrsToList toKeyword set); - in - "{ " + keywords + " }"; - - listContent = values: concatStringsSep ", " (map toLua values); - list = values: "{ " + listContent values + " }"; - - luaList = values: "{" + (concatStringsSep ", " values) + "}"; - - keybinding = { key, cmd, func, mode, desc }: - let - cmdString = - if cmd != null then toLua cmd else - if func != null then func else - abort "Either cmd or function must be set"; - descString = optionalString (desc != null) "desc = ${toLua desc},"; - in - ''{ ${toLua key}, ${cmdString}, mode = ${toLua mode}, ${descString} }''; - - lazySpecFromPlugin = - { cmd - , conf - , dependencies - , enabled - , event - , ft - , init - , keys - , lazy - , opts - , plugin - , priority - }: - - luaList - ([ - "dir = ${string plugin}" - "name = ${toLua (getName plugin)}" - ] - ++ (optional (opts != null) "opts = ${toLua opts}") - ++ (optional (lazy != null) "lazy = ${toLua lazy}") - ++ (optional (!enabled) "enabled = ${toLua enabled}") - ++ (optional (dependencies != [ ]) "dependencies = ${luaList (map lazySpecFromPlugin dependencies)}") - ++ (optional (init != null) "init = function(plugin)\n${init}\nend") - ++ (optional (conf != null) "config = function(plugin, opts)\n${conf}\nend") - ++ (optional (keys != [ ]) "keys = ${luaList (map keybinding keys)}") - ++ (optional (event != [ ]) "event = ${toLua event}") - ++ (optional (cmd != [ ]) "cmd = ${toLua cmd}") - ++ (optional (ft != [ ]) "ft = ${toLua ft}") - ++ (optional (priority != null) "priority = ${toLua priority}") - ); - lazySpecs = luaList (map lazySpecFromPlugin cfg.plugins); - lazy = /* lua */ '' - require("lazy").setup(${lazySpecs}) - ''; - - initLua = - let - text = lib.concatLines [ (builtins.readFile ./options.lua) lazy ]; - in - pkgs.runCommand "init.lua" { inherit text; } '' - touch $out - echo -n "$text" > $out - ${getExe pkgs.stylua} $out - ''; - in { imports = lib.my.listModulesRec ./plugins; - options.my.programs.nvim = { - enable = mkEnableOption "nvim"; - plugins = mkOption { - default = [ ]; - description = '' - List of plugins with config. - ''; - type = with types; listOf ( - let - sub = submodule { - options = { - conf = mkOption { - type = nullOr str; - default = null; - description = '' - Lua function to be executed when the plugin is loaded. - ''; - }; - opts = mkOption { - type = - let - valueType = nullOr - (oneOf [ - str - bool - int - float - (listOf valueType) - (attrsOf valueType) - ]) // { - description = "Lua value"; - }; - in - nullOr (attrsOf valueType); - default = null; - description = '' - Lua table to be passed to te plugin config function. - ''; - }; - dependencies = mkOption { - type = listOf sub; - default = [ ]; - description = '' - List of plugins this plugin depends on. - ''; - }; - init = mkOption { - type = nullOr str; - default = null; - description = '' - Lua code to be executed when the plugin is initialized. - ''; - }; - event = mkOption { - type = listOf str; - default = [ ]; - description = '' - Event to load the plugin on. - ''; - }; - lazy = mkOption { - type = nullOr bool; - default = null; - description = '' - Whether to load the plugin lazily. - ''; - }; - plugin = mkOption { - type = package; - description = '' - The plugin package. - ''; - }; - enabled = mkOption { - type = bool; - default = true; - description = '' - Whether to enable the plugin. - ''; - }; - cmd = mkOption { - type = listOf str; - default = [ ]; - description = '' - Command to load the plugin. - ''; - }; - ft = mkOption { - type = listOf str; - default = [ ]; - description = '' - Filetype to load the plugin on. - ''; - }; - priority = mkOption { - type = nullOr int; - default = null; - description = '' - Priority to load the plugin. - ''; - }; - keys = mkOption { - default = [ ]; - description = '' - List of keybindings. - ''; - type = listOf (submodule { - options = { - key = mkOption { - type = str; - description = '' - Key to bind. - ''; - }; - cmd = mkOption { - type = nullOr str; - default = null; - description = '' - Command to execute. - ''; - }; - func = mkOption { - type = nullOr str; - default = null; - description = '' - Function to execute. - ''; - }; - mode = mkOption { - type = listOf str; - default = [ "n" ]; - description = '' - Mode to bind the key in. - ''; - }; - desc = mkOption { - type = nullOr str; - default = null; - description = '' - Description of the keybinding. - ''; - }; - }; - }); - }; - }; - }; - in - sub - ); - }; - }; - + options.my.programs.nvim.enable = mkEnableOption "nvim"; config = mkIf cfg.enable { home-manager.users.moritz = { @@ -250,8 +19,6 @@ in ) ]; - xdg.configFile."nvim/init.lua".source = initLua; - programs.neovim = { enable = true; package = pkgs.neovim-nightly; @@ -259,14 +26,6 @@ in vimdiffAlias = true; withNodeJs = true; withPython3 = true; - extraPython3Packages = ps: - let - plugins = map (getAttr "plugin") cfg.plugins; - depAttrName = "python3Dependencies"; - filtered = filter (hasAttr depAttrName) plugins; - funcs = map (getAttr depAttrName) filtered; - in - foldl (list: f: list ++ (f ps)) [ ] funcs; extraPackages = with pkgs; [ alejandra @@ -288,9 +47,8 @@ in typst-lsp yamlfmt ]; - plugins = [ - pkgs.vimPlugins.lazy-nvim - ]; + extraLuaConfig = readFile ./options.lua; + lazy.enable = true; }; }; }; diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index e44d7ab..a9e460f 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -1,8 +1,8 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: with builtins; { - config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ + config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [ { plugin = formatter-nvim; cmd = [ "Format" "Fmt" ]; diff --git a/modules/programs/nvim/plugins/treesitter.nix b/modules/programs/nvim/plugins/treesitter.nix index d4c3cf0..b76bcbc 100644 --- a/modules/programs/nvim/plugins/treesitter.nix +++ b/modules/programs/nvim/plugins/treesitter.nix @@ -2,7 +2,7 @@ with builtins; { - config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ + config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [ { plugin = nvim-treesitter; event = [ "BufReadPost" "BufNewFile" ]; diff --git a/modules/programs/nvim/plugins/ui.nix b/modules/programs/nvim/plugins/ui.nix index 0e535c4..92e5fd5 100644 --- a/modules/programs/nvim/plugins/ui.nix +++ b/modules/programs/nvim/plugins/ui.nix @@ -2,7 +2,7 @@ with builtins; { - config.my.programs.nvim.plugins = with pkgs.vimPlugins; [ + config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [ { plugin = which-key-nvim; lazy = false; From 7078b97ee9f4ee86197a3023ae1974dbfdf12896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 17 Sep 2023 09:36:22 +0200 Subject: [PATCH 8/9] feat(nvim): add copilot-cmp --- modules/programs/nvim/plugins/coding.nix | 17 +++++++++++++++++ modules/programs/nvim/plugins/lua/nvim-cmp.lua | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index a9e460f..8219567 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -89,6 +89,23 @@ with builtins; { plugin = friendly-snippets; } { plugin = lspkind-nvim; } { plugin = luasnip; } + { + plugin = copilot-cmp; + opts = { }; + dependencies = [ + { + plugin = copilot-lua; + opts = { + suggestion = { enabled = false; }; + panel = { enabled = false; }; + }; + conf = /* lua */ '' + require("copilot").setup(opts) + vim.cmd("Copilot disable") + ''; + } + ]; + } ]; } { diff --git a/modules/programs/nvim/plugins/lua/nvim-cmp.lua b/modules/programs/nvim/plugins/lua/nvim-cmp.lua index 437c4e9..c48297b 100644 --- a/modules/programs/nvim/plugins/lua/nvim-cmp.lua +++ b/modules/programs/nvim/plugins/lua/nvim-cmp.lua @@ -2,13 +2,23 @@ local cmp = require("cmp") local luasnip = require("luasnip") require("luasnip.loaders.from_vscode").lazy_load() +local has_words_before = function() + if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then + return false + end + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil +end + cmp.setup({ formatting = { format = require("lspkind").cmp_format({ mode = "symbol", -- show only symbol annotations maxwidth = 50, -- prevent the popup from showing more than provided characters ellipsis_char = "...", -- when popup menu exceed maxwidth, the truncated part would show ellipsis_char instead - symbol_map = {}, + symbol_map = { + Copilot = "", + }, }), }, snippet = { @@ -24,8 +34,8 @@ cmp.setup({ [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() + if cmp.visible() and has_words_before() then + cmp.select_next_item({ behavior = cmp.SelectBehavior.Select }) elseif luasnip.expand_or_jumpable() then luasnip.expand_or_jump() else @@ -46,6 +56,7 @@ cmp.setup({ { name = "async_path", priority = 1 }, { name = "buffer", priority = 1 }, { name = "luasnip", priority = 2 }, + { name = "copilot", group_index = 3 }, { name = "nvim_lsp", priority = 4 }, }, }) From 3ee3593b0cff4275c4b27789edb44002a1e07293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sun, 17 Sep 2023 09:37:02 +0200 Subject: [PATCH 9/9] refactor(nvim): remove unnused dependency --- flake.lock | 16 ++++++++++++++++ modules/programs/nvim/plugins/coding.nix | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/flake.lock b/flake.lock index a66d563..7ff13b1 100644 --- a/flake.lock +++ b/flake.lock @@ -598,6 +598,21 @@ "type": "github" } }, + "nix-lazy-nvim": { + "locked": { + "lastModified": 1694868321, + "narHash": "sha256-LHPQkD+7ltdo77gpFQOnr8QAgYPdtFf9pm/Alwrs570=", + "ref": "refs/heads/main", + "rev": "1dc6361600111b1c46f6e85221334c8c47f88200", + "revCount": 4, + "type": "git", + "url": "https://git.moritzboeh.me/moritz/NixLazy.nvim" + }, + "original": { + "type": "git", + "url": "https://git.moritzboeh.me/moritz/NixLazy.nvim" + } + }, "nix-super": { "inputs": { "flake-compat": "flake-compat_2", @@ -870,6 +885,7 @@ "master": "master", "neovim-nightly-overlay": "neovim-nightly-overlay", "nil": "nil", + "nix-lazy-nvim": "nix-lazy-nvim", "nix-super": "nix-super", "nixpkgs": "nixpkgs_6", "nvim-treesitter": "nvim-treesitter", diff --git a/modules/programs/nvim/plugins/coding.nix b/modules/programs/nvim/plugins/coding.nix index 8219567..ae3d393 100644 --- a/modules/programs/nvim/plugins/coding.nix +++ b/modules/programs/nvim/plugins/coding.nix @@ -205,7 +205,6 @@ with builtins; ]; dependencies = [ { plugin = plenary-nvim; } - { plugin = which-key-nvim; } { plugin = telescope-fzf-native-nvim; } ]; }