aboutsummaryrefslogtreecommitdiff
path: root/modules/neovim/default.nix
blob: 7939f0d3f7e2b792e050a09fdc090811ea62ac21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.modules.neovim;
  scheme = config.modules.scheme;
  tsparsers = pkgs.symlinkJoin {
    # if we don't symlink, startuptime grows by an order of magnitude because of long runtimepath
    name = "tsparsers";
    # paths = (pkgs.vimPlugins.nvim-treesitter.withAllGrammars).dependencies;
    paths =
      (pkgs.vimPlugins.nvim-treesitter.withPlugins (
        p: with p; [
          tree-sitter-nix
          tree-sitter-nu
          tree-sitter-go
          tree-sitter-rst
          tree-sitter-lua
          tree-sitter-css
          tree-sitter-yaml
          tree-sitter-toml
          tree-sitter-scss
          tree-sitter-json
          tree-sitter-html
          tree-sitter-fish
          tree-sitter-bash
          tree-sitter-query
          tree-sitter-ocaml
          tree-sitter-ocaml-interface
          tree-sitter-latex
          tree-sitter-python
          tree-sitter-bibtex
          tree-sitter-comment
          tree-sitter-dockerfile
          tree-sitter-make
          tree-sitter-cmake
          tree-sitter-scheme
          tree-sitter-llvm
          tree-sitter-html
          tree-sitter-glsl
          tree-sitter-devicetree
          tree-sitter-cuda
          tree-sitter-c
          tree-sitter-cpp
          tree-sitter-lua
          tree-sitter-zig
          tree-sitter-rust
          tree-sitter-haskell
          tree-sitter-toml
          tree-sitter-markdown
          tree-sitter-markdown-inline
          tree-sitter-tablegen
          tree-sitter-latex
        ]
      )).dependencies;
  };
in
{
  options.modules.neovim = {
    enable = lib.mkEnableOption "neovim";
  };

  config = lib.mkIf cfg.enable {
    home.packages = with pkgs; [
      basedpyright
      clang-tools
      ruff
      nixfmt-rfc-style
      stylua
      black
      isort
      nixd
      lua-language-server
      cmake-language-server
      kdePackages.qtdeclarative
    ];
    xdg.configFile."nvim/lua" = {
      source = ./nvim/lua;
      recursive = true;
    };

    xdg.configFile."nvim/after" = {
      source = ./nvim/after;
      recursive = true;
    };

    # home.sessionVariables.MANPAGER = "nvim +Man!";

    programs.neovim = {
      enable = true;
      defaultEditor = true;
      viAlias = false;
      vimAlias = false;
      vimdiffAlias = true;
      plugins = with pkgs.vimPlugins; [
        # lazy loading
        lz-n

        nvim-treesitter
        tsparsers
        # broken or missing ts parsers
        nvim-treesitter-parsers.qmljs
        nvim-treesitter-parsers.systemverilog
        nvim-treesitter-parsers.prolog

        nvim-lspconfig

        {
          plugin = lazydev-nvim;
          type = "lua";
          config = # lua
          ''
          require("lazydev").setup{}
          '';
        }

        # colorschemes. TODO: delete
        base16-nvim

        {
          plugin = nvim-highlight-colors;
          type = "lua";
          config =
            # lua
            ''
              require("nvim-highlight-colors").setup {
                render = 'virtual',
                virtual_symbol_position = 'eow',
                virtual_symbol_prefix = " ",
                virtual_symbol_suffix = "",
              }
            '';
        }

        {
          plugin = lean-nvim;
          optional = true;
          type = "lua";
          config =
            # lua
            ''
              require("lz.n").load({
                "lean",
                ft = "lean",
                after = function()
                  require('lean').setup({ mappings = true })
                end,
              })
            '';
        }

        tmux-nvim
        nvim-lspconfig

        {
          plugin = telescope-nvim;
          optional = true;
          type = "lua";
          config =
            # lua
            ''
              require("lz.n").load({
                "telescope.nvim",
                cmd = "Telescope",
                after = function()
                  require('telescope').setup({})
                  require('telescope').load_extension('fzf')
                end,
              })
            '';
        }
        telescope-fzf-native-nvim

        conform-nvim

        # textobjects
        mini-ai
        {
          plugin = mini-pairs;
          type = "lua";
          config =
            # lua
            ''
              require("mini.pairs").setup()
            '';
        }
        {
          plugin = mini-surround;
          type = "lua";
          config =
            # lua
            ''
              require("mini.surround").setup({ silent = true })
            '';
        }
        {
          plugin = mini-trailspace;
          type = "lua";
          config =
            # lua
            ''
              require("mini.trailspace").setup()
            '';
        }
        {
          plugin = mini-splitjoin;
          type = "lua";
          config =
            # lua
            ''
              require("mini.splitjoin").setup({
                mappings = { toggle = "", split = "", join = "" },
              })
            '';
        }
        {
          plugin = treesj;
          type = "lua";
          config =
            # lua
            ''
              require("treesj").setup({ use_default_keymaps = false, notify = false})
              --require("lz.n").load({
              --     "treesj",
              --     cmd = {'TSJSplit', 'TSJToggle', 'TSJJoin'},
              --     after = function()
              --       require("treesj").setup(use_default_keymaps = false)
              --     end,
              -- })
            '';
        }
      ];
      extraLuaConfig = ''
        ${builtins.readFile ./nvim/init.lua}
        vim.cmd[[colorscheme ${scheme.name}]]
        vim.opt.runtimepath:prepend('${tsparsers}')
      '';
    };
  };
}