This repository has no description
9.4 kB
318 lines
1{ inputs, ... }:
2{
3 perSystem =
4 { system, pkgs, ... }:
5 {
6 packages.nvim = inputs.nixvim.legacyPackages.${system}.makeNixvim {
7 vimAlias = true;
8 colorschemes.ayu = {
9 enable = true;
10 settings.overrides = {
11 EoLSpace = {
12 bg = "#883333";
13 };
14 };
15 };
16 globals.mapleader = " ";
17 opts = {
18 mouse = "a";
19 number = true;
20 shiftwidth = 2;
21 clipboard = "unnamedplus";
22 # undo stuff
23 undofile = true;
24 undolevels = 10000;
25 undoreload = 10000;
26 listchars = "tab:⇥ ,extends:❯,precedes:❮,nbsp:␣,trail:·,eol:↲";
27 };
28 extraConfigVim = ''
29 set et
30
31 " show special characters
32 set list
33
34 " match trailing whitespace
35 match EoLSpace /\s\+$/
36
37 " need to use lua to expand $HOME
38 lua vim.o.undodir = vim.fs.normalize('$HOME/.vim/undodir')
39 '';
40 extraConfigLua = ''
41 local function watch_theme_file()
42 local path = '/var/theme/current_theme'
43 local uv = vim.loop
44
45 local watcher = uv.new_fs_event()
46 watcher:start(path, {}, function(err, filename, events)
47 if err then
48 print('Error watching file:', err)
49 return
50 end
51
52 -- Use Lua's io.open to read the file content
53 local file = io.open(path, 'r')
54 if not file then
55 print('Failed to open file:', path)
56 return
57 end
58
59 local content = file:read('*a') -- Read the entire file
60 file:close()
61
62 content = content:gsub('%s+$', "")
63 content = content:gsub('"', '\\"')
64
65 -- Execute a Neovim command based on the content
66 vim.schedule(function()
67 cmd = 'set background=' .. content
68 vim.cmd(cmd)
69 end)
70 end)
71 end
72 watch_theme_file()
73
74 '';
75 extraPlugins = [
76 pkgs.vimPlugins.vim-fetch
77 ];
78 # not ready yet, we are waiting for none-ls to get updated
79 # extraConfigLua = ''
80 # local null_ls = require("null-ls")
81 # null_ls.register(null_ls.builtins.formatting.nix_flake_fmt)
82 # '';
83 keymaps = [
84 {
85 mode = "i";
86 key = "<C-p>";
87 action = "<Nop>";
88 }
89 {
90 mode = "i";
91 key = "<C-n>";
92 action = "<Nop>";
93 }
94 {
95 mode = "n";
96 key = "<C-c>";
97 action = ":q<cr>";
98 }
99 {
100 mode = "n";
101 key = "<Space>";
102 action = "<Nop>";
103 }
104 {
105 mode = "n";
106 key = "<leader>sd";
107 action = ":colorscheme ayu-dark<cr>";
108 }
109 {
110 mode = "n";
111 key = "<leader>sw";
112 action = ":colorscheme ayu-light<cr>";
113 }
114 {
115 mode = [
116 "n"
117 "v"
118 ];
119 key = "<leader>cc";
120 action = ":CopilotChatOpen<cr>";
121 }
122 {
123 mode = [
124 "n"
125 "v"
126 ];
127 key = "<leader>ce";
128 action = ":CopilotChatExplain<cr>";
129 }
130 {
131 mode = [
132 "n"
133 "v"
134 ];
135 key = "<leader>cr";
136 action = ":CopilotChatReview<cr>";
137 }
138 {
139 mode = [
140 "n"
141 "v"
142 ];
143 key = "<leader>cf";
144 action = ":CopilotChatFix<cr>";
145 }
146 {
147 mode = [
148 "n"
149 "v"
150 ];
151 key = "<leader>cd";
152 action = ":CopilotChatDocs<cr>";
153 }
154 {
155 mode = [
156 "n"
157 "x"
158 ];
159 key = "p";
160 action = "<Plug>(YankyPutAfter)";
161 }
162 {
163 mode = [
164 "n"
165 "x"
166 ];
167 key = "P";
168 action = "<Plug>(YankyPutBefore)";
169 }
170 {
171 mode = [
172 "c"
173 "i"
174 "n"
175 "x"
176 ];
177 key = "<M-CR>";
178 action = ":lua vim.lsp.buf.code_action()<CR>";
179 }
180 {
181 mode = [
182 "n"
183 ];
184 key = "gd";
185 action = ":lua vim.lsp.buf.definition()<CR>";
186 }
187 {
188 mode = [
189 "n"
190 ];
191 key = "gD";
192 action = ":lua vim.lsp.buf.declaration()<CR>";
193 }
194 ];
195 # autoCmd = [
196 # {
197 # event = "BufWritePost";
198 # desc = "run treefmt on save";
199 # # https://stackoverflow.com/questions/77466697/how-to-automatically-format-on-save
200 # callback.__raw = ''
201 # function()
202 # vim.cmd("silent !treefmt %")
203 # vim.cmd("edit")
204 # end
205 # '';
206 # }
207 # ];
208 plugins.none-ls = {
209 enable = true;
210 # sources.formatting.treefmt = {
211 # enable = true;
212 # package = pkgs.emptyDirectory;
213 # };
214 # package = pkgs.vimPlugins.none-ls-nvim.overrideAttrs (_old: {
215 # src = pkgs.fetchFromGitHub {
216 # owner = "lassulus";
217 # repo = "none-ls.nvim";
218 # rev = "292c2b5eadea0a097b9a01804aea70f5c8125200";
219 # sha256 = "sha256-nbzqXsxmYfxngdJH3NXMLmGgygh6reSEnruoc6l8t/s=";
220 # };
221 # });
222 };
223 plugins.web-devicons.enable = true;
224 plugins.telescope.extensions.undo.enable = true;
225 plugins.telescope = {
226 enable = true;
227 keymaps = {
228 "<leader>b" = "buffers";
229 "<leader>u" = "undo";
230 "<leader>ff" = "find_files";
231 "<leader>fg" = "live_grep";
232 "<leader>fh" = "help_tags";
233 "<leader>fp" = "yank_history";
234 };
235 };
236 plugins.lsp-format.enable = true;
237 plugins.lsp-lines.enable = true;
238 plugins.lsp = {
239 enable = true;
240 servers = {
241 bashls.enable = true; # bash
242 nixd = {
243 enable = true; # nix
244 extraOptions.offset_encoding = "utf-8"; # workaround https://github.com/nix-community/nixvim/issues/2390#issuecomment-2408101568
245 };
246 ruff.enable = true; # python
247 pyright.enable = true; # python
248 harper_ls.enable = true; # comments
249 jsonls.enable = true; # json
250 };
251 };
252 plugins.treesitter.enable = true;
253 plugins.copilot-cmp.enable = true;
254 plugins.copilot-lua.panel.enabled = false;
255 plugins.copilot-lua.suggestion.enabled = false;
256 plugins.cmp_yanky.enable = true;
257 plugins.cmp = {
258 enable = true;
259 autoEnableSources = true;
260 settings = {
261 experimental = {
262 ghost_text = true;
263 };
264 sources = [
265 { name = "nvim_lsp"; }
266 { name = "emoji"; }
267 {
268 name = "buffer"; # text within current buffer
269 option.get_bufnrs.__raw = "vim.api.nvim_list_bufs";
270 keywordLength = 2;
271 }
272 {
273 name = "copilot"; # enable copilot
274 }
275 {
276 name = "path"; # file system paths
277 keywordLength = 3;
278 }
279 { name = "cmp_yanky"; }
280 ];
281
282 mapping = {
283 "<Tab>" = "cmp.mapping.select_next_item()";
284 "<S-Tab>" = "cmp.mapping.select_prev_item()";
285 "<C-n>" = "cmp.mapping.select_next_item()";
286 "<C-p>" = "cmp.mapping.select_prev_item()";
287 "<C-e>" = "cmp.mapping.abort()";
288 "<C-b>" = "cmp.mapping.scroll_docs(-4)";
289 "<C-f>" = "cmp.mapping.scroll_docs(4)";
290 "<CR>" = ''
291 cmp.mapping({
292 i = function(fallback)
293 if cmp.visible() and cmp.get_active_entry() then
294 cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
295 else
296 fallback()
297 end
298 end,
299 s = cmp.mapping.confirm({ select = true }),
300 c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }),
301 })
302 '';
303 };
304 };
305 };
306 plugins.bufferline.enable = true;
307 plugins.which-key.enable = true;
308 plugins.yanky = {
309 enable = true;
310 enableTelescope = true;
311 };
312 plugins.comment.enable = true;
313 plugins.copilot-chat.enable = true;
314 plugins.undotree.enable = true; # seems to be needed for undo history in telescope
315 plugins.leap.enable = true;
316 };
317 };
318}