/
neovim.nix
249 lines (224 loc) · 7.79 KB
/
neovim.nix
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
244
245
246
247
248
249
{ config, pkgs, lib, ... }:
# Let-In ----------------------------------------------------------------------------------------{{{
let
inherit (lib) concatStringsSep optional;
inherit (config.lib.file) mkOutOfStoreSymlink;
inherit (config.home.user-info) nixConfigDirectory;
mkLuaTableFromList = x: "{" + lib.concatMapStringsSep "," (y: "'${y}'") x + "}";
mkNeovimAutocmd = { event, pattern, callback ? "" }: ''
vim.api.nvim_create_autocmd(${mkLuaTableFromList event}, {
pattern = ${mkLuaTableFromList pattern},
callback = ${callback},
})'';
requireConf = p: "require 'malo.${builtins.replaceStrings [ "." ] [ "-" ] p.pname}'";
# Function to create `programs.neovim.plugins` entries inspired by `packer.nvim`.
packer =
{ use
# Plugins that this plugin depends on.
, deps ? [ ]
# Used to manually specify that the plugin shouldn't be loaded at start up.
, opt ? false
# Whether to load the plugin when using VS Code with `vscode-neovim`.
, vscode ? false
# Code to run before the plugin is loaded.
, setup ? ""
# Code to run after the plugin is loaded.
, config ? ""
# The following all imply lazy-loading and imply `opt = true`.
# `FileType`s which load the plugin.
, ft ? [ ]
# Autocommand events which load the plugin.
, event ? [ ]
}:
let
loadFunctionName = "load_${builtins.replaceStrings [ "." "-" ] [ "_" "_" ] use.pname}";
autoload = !opt && vscode && ft == [ ] && event == [ ];
configFinal =
concatStringsSep "\n" (
optional (!autoload && !opt) "vim.cmd 'packadd ${use.pname}'"
++ optional (config != "") config
);
in
{
plugin = use.overrideAttrs (old: {
dependencies = lib.unique (old.dependencies or [ ] ++ deps);
});
optional = !autoload;
type = "lua";
config = if (setup == "" && configFinal == "") then null else
(
concatStringsSep "\n"
(
[ "\n-- ${use.pname or use.name}" ]
++ optional (setup != "") setup
# If the plugin isn't always loaded at startup
++ optional (!autoload) (concatStringsSep "\n" (
[ "local ${loadFunctionName} = function()" ]
++ optional (!vscode) "if vim.g.vscode == nil then"
++ [ configFinal ]
++ optional (!vscode) "end"
++ [ "end" ]
++ optional (ft == [ ] && event == [ ]) "${loadFunctionName}()"
++ optional (ft != [ ]) (mkNeovimAutocmd {
event = [ "FileType" ];
pattern = ft;
callback = loadFunctionName;
})
++ optional (event != [ ]) (mkNeovimAutocmd {
inherit event;
pattern = [ "*" ];
callback = loadFunctionName;
})
))
# If the plugin is always loaded at startup
++ optional (autoload && configFinal != "") configFinal
)
);
};
in
# }}}
{
# Neovim
# https://rycee.gitlab.io/home-manager/options.html#opt-programs.neovim.enable
programs.neovim.enable = true;
# Config and plugins ------------------------------------------------------------------------- {{{
# Put neovim configuration located in this repository into place in a way that edits to the
# configuration don't require rebuilding the `home-manager` environment to take effect.
xdg.configFile."nvim/lua".source = mkOutOfStoreSymlink "${nixConfigDirectory}/configs/nvim/lua";
xdg.configFile."nvim/colors".source =
mkOutOfStoreSymlink "${nixConfigDirectory}/configs/nvim/colors";
# Load the `init` module from the above configs
programs.neovim.extraConfig = "lua require('init')";
# Add `penlight` Lua module package since I used in the above configs
programs.neovim.extraLuaPackages = ps: [ ps.penlight ];
# Add plugins using my `packer` function.
programs.neovim.plugins = with pkgs.vimPlugins; map packer [
# Apperance, interface, UI, etc.
{
use = bufferline-nvim;
deps = [ nvim-web-devicons scope-nvim ];
config = requireConf bufferline-nvim;
}
{ use = galaxyline-nvim; deps = [ nvim-web-devicons ]; config = requireConf galaxyline-nvim; }
{ use = gitsigns-nvim; config = requireConf gitsigns-nvim; }
{ use = goyo-vim; }
{ use = indent-blankline-nvim; config = requireConf indent-blankline-nvim; }
{ use = lush-nvim; vscode = true; }
{ use = no-neck-pain-nvim; config = requireConf no-neck-pain-nvim; }
{
use = noice-nvim;
deps = [ nui-nvim nvim-notify ];
config = requireConf noice-nvim;
}
{
use = telescope-nvim;
config = requireConf telescope-nvim;
deps = [
nvim-web-devicons
telescope-file-browser-nvim
telescope-fzf-native-nvim
telescope_hoogle
telescope-symbols-nvim
telescope-zoxide
];
}
{ use = toggleterm-nvim; config = requireConf toggleterm-nvim; }
{ use = zoomwintab-vim; opt = true; }
# Completions
{
use = copilot-lua;
config = ''
require'copilot'.setup {
suggestion = { enabled = false },
panel = { enabled = false },
}
'';
}
{
use = nvim-cmp;
deps = [
cmp-async-path
cmp-buffer
cmp-nvim-lsp
cmp-nvim-lsp-signature-help
copilot-cmp
lspkind-nvim
luasnip
cmp_luasnip
];
config = requireConf nvim-cmp;
}
# Language servers, linters, etc.
{
use = lsp_lines-nvim;
config = ''
require'lsp_lines'.setup()
vim.diagnostic.config({ virtual_lines = { only_current_line = true } })'';
}
{ use = haskell-tools-nvim; }
{
use = nvim-lspconfig;
deps = [ neodev-nvim telescope-nvim ];
config = requireConf nvim-lspconfig;
}
# Language support/utilities
{
use = cornelis;
setup = ''
vim.g.cornelis_use_global_binary = 1
vim.g.cornelis_agda_prefix = '\\'
'';
}
{
use = nvim-treesitter.withAllGrammars;
config = requireConf nvim-treesitter;
}
{ use = vim-haskell-module-name; vscode = true; }
{ use = vim-polyglot; config = requireConf vim-polyglot; }
# Editor behavior
{ use = comment-nvim; config = "require'comment'.setup()"; }
{ use = editorconfig-vim; setup = "vim.g.EditorConfig_exclude_patterns = { 'fugitive://.*' }"; }
{ use = tabular; vscode = true; }
{ use = vim-surround; vscode = true; }
{ use = nvim-lastplace; config = "require'nvim-lastplace'.setup()"; }
{
use = vim-pencil;
setup = "vim.g['pencil#wrapModeDefault'] = 'soft'";
config = "vim.fn['pencil#init'](); vim.wo.spell = true";
ft = [ "markdown" "text" ];
}
# Misc
{ use = direnv-vim; }
{ use = vim-eunuch; vscode = true; }
{ use = vim-fugitive; }
{ use = which-key-nvim; opt = true; }
];
# From personal addon module `../modules/home/programs/neovim/extras.nix`
programs.neovim.extras.termBufferAutoChangeDir = true;
programs.neovim.extras.nvrAliases.enable = true;
programs.neovim.extras.defaultEditor = true;
# }}}
# Required packages -------------------------------------------------------------------------- {{{
programs.neovim.extraPackages = with pkgs; [
neovim-remote
# Language servers, linters, etc.
# See `../configs/nvim/lua/malo/nvim-lspconfig.lua` and
# Bash
nodePackages.bash-language-server
# Javascript/Typescript
nodePackages.typescript-language-server
# Nix
nil
nixpkgs-fmt
# Vim
nodePackages.vim-language-server
#Other
(agda.withPackages (p: [ p.standard-library ]))
cornelis
nodePackages.yaml-language-server
sumneko-lua-language-server
vscode-langservers-extracted
];
# }}}
}
# vim: foldmethod=marker