diff --git a/default.nix b/default.nix index ae5e54f..0eab4b2 100644 --- a/default.nix +++ b/default.nix @@ -1,39 +1,22 @@ -{ wrapNeovim, neovim-unwrapped, vimPlugins, ... }: +{ callPackage, wrapNeovim, neovim-unwrapped, vimPlugins, ... }: +let + lib = import ./lib.nix; + + plugins = [ + (callPackage ./syntax { }) + ]; + +in wrapNeovim neovim-unwrapped { withPython3 = false; withNodeJs = false; withRuby = false; configure = { - customRC = '' - lua << EOF - require("nvim-treesitter.configs").setup({ - -- A list of parser names, or "all" - ensure_installed = {}, - - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, - - highlight = { - enable = true, - }, - - indent = { - enable = true, - }, - }) - EOF - ''; + customRC = lib.mkLuaRc (lib.extractAttrs "luaConfig" plugins); packages.myVimPackages = - { - start = with vimPlugins; [ - (nvim-treesitter.withPlugins - (ts: [ - ts.tree-sitter-nix - ])) - ]; - }; + { start = lib.extractAttrs "plugins" plugins; }; }; } diff --git a/lib.nix b/lib.nix new file mode 100644 index 0000000..037adb0 --- /dev/null +++ b/lib.nix @@ -0,0 +1,39 @@ +rec { + ############################################################################# + # Helpers + + # Source: https://github.com/NixOS/nixpkgs/blob/d61bc96d16ca288c69b798b8e31eca64050098e3/lib/lists.nix + foldr = op: nul: list: + let + len = builtins.length list; + fold' = n: + if n == len + then nul + else op (builtins.elemAt list n) (fold' (n + 1)); + in + fold' 0; + + extractAttrs = attr: list: + let + getAttr' = builtins.getAttr attr; + hasAttr' = builtins.hasAttr attr; + filteredList = builtins.filter hasAttr' list; + in + builtins.map getAttr' filteredList; + + ############################################################################# + # Lua + + mkLuaHeredoc = content: '' + lua << EOF + ${content} + EOF + ''; + + mkLuaRc = contents: + let + concat = (a: b: a + b); + luaHeredors = builtins.map mkLuaHeredoc contents; + in + foldr concat "" luaHeredors; +} diff --git a/syntax/default.nix b/syntax/default.nix new file mode 100644 index 0000000..65fb716 --- /dev/null +++ b/syntax/default.nix @@ -0,0 +1,12 @@ +{ vimPlugins, ... }: + +{ + luaConfig = builtins.readFile ./treesitter.lua; + + plugins = [ + (vimPlugins.nvim-treesitter.withPlugins + (ts: [ + ts.tree-sitter-nix + ])) + ]; +} diff --git a/syntax/treesitter.lua b/syntax/treesitter.lua new file mode 100644 index 0000000..a22df49 --- /dev/null +++ b/syntax/treesitter.lua @@ -0,0 +1,12 @@ +require("nvim-treesitter.configs").setup({ + ensure_installed = {}, + sync_install = false, + + highlight = { + enable = true, + }, + + indent = { + enable = true, + }, +})