diff --git a/flake.nix b/flake.nix index 20d1c2d..81ecc14 100644 --- a/flake.nix +++ b/flake.nix @@ -255,6 +255,7 @@ { mode = "n"; bind = "nf"; command = "NvimTreeFindFile"; } ]; }; + nvim-treesitter = { }; }; plugins = with prev.nix2lua.lib; { diff --git a/modules/catppuccin.nix b/modules/catppuccin.nix index 96c87c8..ca92b2a 100644 --- a/modules/catppuccin.nix +++ b/modules/catppuccin.nix @@ -1,4 +1,4 @@ -{ nix2lua }: +{ nix2lua, ... }: { flavour ? "frappe" }: diff --git a/modules/nvim-tree-lua.nix b/modules/nvim-tree-lua.nix index 96ddbde..a72956b 100644 --- a/modules/nvim-tree-lua.nix +++ b/modules/nvim-tree-lua.nix @@ -1,4 +1,4 @@ -{ nix2lua }: +{ nix2lua, ... }: { configs ? { } , keymaps ? [ diff --git a/modules/nvim-treesitter.nix b/modules/nvim-treesitter.nix new file mode 100644 index 0000000..3eabc8c --- /dev/null +++ b/modules/nvim-treesitter.nix @@ -0,0 +1,208 @@ +{ nix2lua, pkgs }: + +let + defaultGrammars = g: [ + # g.agda + # g.arduino + # g.astro + g.awk + g.bash + # g.beancount + # g.bibtex + # g.blueprint + # g.c + # g.c_sharp + # g.clojure + g.cmake + g.comment + # g.commonlisp + # g.cooklang + # g.cpp + # g.css + # g.cuda + # g.d + # g.d2 + # g.dart + # g.devicetree + g.diff + # g.dockerfile + # g.dot + # g.eex + # g.elixir + # g.elm + # g.elvish + g.embedded_template + # g.erlang + # g.fennel + # g.fish + # g.foam + # g.fortran + # g.fusion + # g.gdscript + g.git_rebase + g.gitattributes + g.gitignore + # g.gleam + # g.glimmer + # g.glsl + # g.go + # g.godot_resource + # g.gomod + # g.gowork + # g.graphql + # g.hack + # g.haskell + # g.hcl + # g.heex + # g.hjson + # g.hlsl + # g.hocon + # g.html + g.http + # g.java + # g.javascript + g.jq + g.jsdoc + g.json + # g.json5 + # g.jsonc + # g.jsonnet + # g.julia + # g.kotlin + # g.lalrpop + # g.latex + # g.ledger + # g.llvm + # g.lua + # g.m68k + g.make + g.markdown + g.markdown_inline + # g.menhir + # g.meson + # g.nickel + # g.ninja + g.nix + # g.norg + # g.ocaml + # g.ocaml_interface + # g.ocamllex + # g.org + # g.pascal + # g.perl + # g.php + # g.phpdoc + # g.pioasm + # g.prisma + # g.proto + # g.pug + # g.python + # g.ql + # g.qmljs + g.query + # g.r + # g.racket + # g.rasi + g.regex + # g.rego + # g.rnoweb + # g.rst + # g.ruby + # g.rust + # g.scala + g.scheme + # g.scss + # g.slint + # g.solidity + # g.sparql + # g.sql + # g.supercollider + # g.surface + # g.svelte + # g.swift + # g.sxhkdrc + # g.teal + # g.tiger + # g.tlaplus + g.todotxt + # g.toml + # g.tsx + # g.turtle + # g.twig + # g.typescript + # g.v + # g.vala + # g.verilog + # g.vhs + # g.vim + # g.vue + # g.wgsl + g.yaml + # g.yang + # g.zig + ]; +in + +{ allGrammars ? false +, withGrammars ? defaultGrammars +}: + +with nix2lua.lib; + + +let + extraGrammars = { + tree-sitter-d2 = { + language = "d2"; + version = "2023-06-21"; + src = pkgs.fetchFromGitea { + domain = "git.pleshevski.ru"; + owner = "pleshevskiy"; + repo = "tree-sitter-d2"; + rev = "8a9d50043d58eedf1e375b0e2059e43efd856902"; + sha256 = "sha256-ZhVjxo7Xi7DaHN3qabUcykflY74bUqPcOA410fA3zRk="; + }; + }; + }; + + tree-sitter = pkgs.tree-sitter.override { inherit extraGrammars; }; + customGrammars = tree-sitter.withPlugins (g: [ g.tree-sitter-d2 ]); + + nvimTreesitterWithGrammars = + if allGrammars then pkgs.vimPlugins.nvim-treesitter.withAllGrammars + else pkgs.vimPlugins.nvim-treesitter.withPlugins withGrammars; + + finalNvimTreesitter = nvimTreesitterWithGrammars.overrideAttrs (oldAttrs: { + passthru.dependencies = oldAttrs.passthru.dependencies ++ [ + (pkgs.runCommand "nvim-treesitter-d2-grammar" { } '' + mkdir -p $out/parser + ln -s ${customGrammars}/d2.so $out/parser/d2.so + '') + ]; + postPatch = '' + ln -s ${extraGrammars.tree-sitter-d2.src}/queries queries/d2 + ''; + }); +in +{ + override' = { + nvim-treesitter = finalNvimTreesitter; + }; + + nvim-treesitter = [ + (local (set "parser_config" + (pipe [ (require "nvim-treesitter.parsers") (call "get_parser_configs" [ ]) ]) + )) + (set "parser_config.d2" { }) + + (pipe [ + (require "nvim-treesitter.configs") + (call "setup" [{ + ensure_installed = { }; + sync_install = false; + highlight.enable = true; + indent.enable = true; + }]) + ]) + ]; +} diff --git a/neovim.nix b/neovim.nix index 04d59d2..97b6ec7 100644 --- a/neovim.nix +++ b/neovim.nix @@ -4,8 +4,8 @@ , extraLuaConfig ? "" , wrapNeovim , neovim-unwrapped -, tree-sitter , neovimPlugins +, pkgs , lib , nix2lua , plugins ? { } @@ -16,6 +16,7 @@ let plugins' = plugins; + modules' = modules; mergeAttrs = v: if builtins.isList v then @@ -28,18 +29,23 @@ let in let plugins = mergeAttrs plugins'; + modules = mergeAttrs modules'; - importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua; }; - + importModule = moduleName: import (./modules + "/${moduleName}.nix") { inherit nix2lua pkgs; }; allModules = mergeAttrs (lib.mapAttrsToList importModule modules); - pluginsWithModules = mergeAttrs [ allModules plugins ]; + # Type: excludeOverride :: AttrSet -> AttrSet + excludeOverride = lib.filterAttrs (n: v: n != "override'"); + # Type: pluginsWithModules :: AttrSet + pluginsWithModules = mergeAttrs [ (excludeOverride allModules) plugins ]; + overridedNeovimPlugins = + if allModules ? override' then neovimPlugins // allModules.override' + else neovimPlugins; - /* - Type: getPluginByName :: string -> derivation - */ - getPluginByName = lib.flip lib.getAttr neovimPlugins; + # Type: getPluginByName :: string -> derivation + getPluginByName = lib.flip lib.getAttr overridedNeovimPlugins; + # Type: allPlugins :: AttrSet -> [derivation] allPlugins = map getPluginByName (lib.attrNames pluginsWithModules); /*