This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / nvim / flake-module.nix
11 kB 358 lines
1{ inputs, ... }: 2{ 3 perSystem = 4 { system, pkgs, ... }: 5 { 6 packages.nvim = inputs.nixvim.legacyPackages.${system}.makeNixvim { 7 vimAlias = true; 8 colorschemes = { 9 ayu = { 10 enable = true; 11 settings = { 12 mirage = false; 13 dark = true; 14 }; 15 settings.overrides = { 16 EoLSpace = { 17 bg = "#883333"; 18 }; 19 }; 20 }; 21 everforest = { 22 enable = true; 23 settings.overrides = { 24 EoLSpace = { 25 bg = "#FF2222"; # doesn't work 26 }; 27 }; 28 }; 29 }; 30 extraConfigLua = '' 31 -- Cross-platform background detection and colorscheme switching 32 local last_theme = nil 33 34 local function detect_and_set_theme() 35 local is_dark = false 36 37 if vim.fn.has("mac") == 1 then 38 -- macOS: check system appearance 39 local result = vim.fn.system("defaults read -g AppleInterfaceStyle 2>/dev/null") 40 is_dark = result:match("Dark") ~= nil 41 elseif vim.fn.has("unix") == 1 then 42 -- Linux: check if running under a dark theme 43 -- Try multiple methods to detect dark theme 44 local methods = { 45 -- GNOME/GTK 46 "gsettings get org.gnome.desktop.interface gtk-theme 2>/dev/null", 47 "gsettings get org.gnome.desktop.interface color-scheme 2>/dev/null", 48 -- KDE 49 "kreadconfig5 --file kdeglobals --group General --key ColorScheme 2>/dev/null", 50 -- Check if COLORFGBG suggests dark background 51 function() 52 local colorfgbg = vim.env.COLORFGBG 53 if colorfgbg then 54 local fg, bg = colorfgbg:match("(%d+);(%d+)") 55 if fg and bg then 56 -- If foreground is lighter than background, likely dark theme 57 return tonumber(fg) > tonumber(bg) 58 end 59 end 60 return false 61 end 62 } 63 64 for _, method in ipairs(methods) do 65 if type(method) == "function" then 66 is_dark = method() 67 if is_dark then break end 68 else 69 local result = vim.fn.system(method) 70 if result:match("[Dd]ark") or result:match("prefer%-dark") then 71 is_dark = true 72 break 73 end 74 end 75 end 76 end 77 78 local new_theme = is_dark and "dark" or "light" 79 80 if new_theme ~= last_theme then 81 last_theme = new_theme 82 vim.o.background = new_theme 83 84 if is_dark then 85 vim.cmd("colorscheme ayu") 86 print("Switched to dark theme (ayu)") 87 else 88 vim.cmd("colorscheme everforest") 89 print("Switched to light theme (everforest)") 90 end 91 end 92 end 93 94 -- Set initial theme 95 vim.defer_fn(detect_and_set_theme, 100) 96 97 -- Check for theme changes every 3 seconds (less frequent to be less resource intensive) 98 local timer = vim.loop.new_timer() 99 timer:start(3000, 3000, vim.schedule_wrap(detect_and_set_theme)) 100 101 -- Create a command to manually refresh theme 102 vim.api.nvim_create_user_command("RefreshTheme", detect_and_set_theme, {}) 103 ''; 104 globals = { 105 mapleader = " "; 106 }; 107 opts = { 108 mouse = "a"; 109 number = true; 110 shiftwidth = 2; 111 clipboard = "unnamedplus"; 112 # undo stuff 113 undofile = true; 114 undolevels = 10000; 115 undoreload = 10000; 116 listchars = "tab:⇥ ,extends:❯,precedes:❮,nbsp:␣,trail:·,eol:↲"; 117 }; 118 extraConfigVim = '' 119 set et 120 121 " show special characters 122 set list 123 124 " match trailing whitespace 125 match EoLSpace /\s\+$/ 126 127 " need to use lua to expand $HOME 128 lua vim.o.undodir = vim.fs.normalize('$HOME/.vim/undodir') 129 ''; 130 extraPlugins = [ 131 pkgs.vimPlugins.vim-fetch 132 ]; 133 keymaps = [ 134 { 135 mode = "i"; 136 key = "<C-p>"; 137 action = "<Nop>"; 138 } 139 { 140 mode = "i"; 141 key = "<C-n>"; 142 action = "<Nop>"; 143 } 144 { 145 mode = "n"; 146 key = "<C-c>"; 147 action = ":q<cr>"; 148 } 149 { 150 mode = "n"; 151 key = "<Space>"; 152 action = "<Nop>"; 153 } 154 { 155 mode = [ 156 "n" 157 "v" 158 ]; 159 key = "<leader>cc"; 160 action = ":CopilotChatOpen<cr>"; 161 } 162 { 163 mode = [ 164 "n" 165 "v" 166 ]; 167 key = "<leader>ce"; 168 action = ":CopilotChatExplain<cr>"; 169 } 170 { 171 mode = [ 172 "n" 173 "v" 174 ]; 175 key = "<leader>cr"; 176 action = ":CopilotChatReview<cr>"; 177 } 178 { 179 mode = [ 180 "n" 181 "v" 182 ]; 183 key = "<leader>cf"; 184 action = ":CopilotChatFix<cr>"; 185 } 186 { 187 mode = [ 188 "n" 189 "v" 190 ]; 191 key = "<leader>cd"; 192 action = ":CopilotChatDocs<cr>"; 193 } 194 { 195 mode = [ 196 "n" 197 "x" 198 ]; 199 key = "p"; 200 action = "<Plug>(YankyPutAfter)"; 201 } 202 { 203 mode = [ 204 "n" 205 "x" 206 ]; 207 key = "P"; 208 action = "<Plug>(YankyPutBefore)"; 209 } 210 { 211 mode = [ 212 "c" 213 "i" 214 "n" 215 "x" 216 ]; 217 key = "<M-CR>"; 218 action = ":lua vim.lsp.buf.code_action()<CR>"; 219 } 220 { 221 mode = [ 222 "n" 223 ]; 224 key = "gd"; 225 action = ":lua vim.lsp.buf.definition()<CR>"; 226 } 227 { 228 mode = [ 229 "n" 230 ]; 231 key = "gD"; 232 action = ":lua vim.lsp.buf.declaration()<CR>"; 233 } 234 ]; 235 # autoCmd = [ 236 # { 237 # event = "BufWritePost"; 238 # desc = "run treefmt on save"; 239 # # https://stackoverflow.com/questions/77466697/how-to-automatically-format-on-save 240 # callback.__raw = '' 241 # function() 242 # vim.cmd("silent !treefmt %") 243 # vim.cmd("edit") 244 # end 245 # ''; 246 # } 247 # ]; 248 plugins.none-ls = { 249 enable = true; 250 # sources.formatting.treefmt = { 251 # enable = true; 252 # package = pkgs.emptyDirectory; 253 # }; 254 # package = pkgs.vimPlugins.none-ls-nvim.overrideAttrs (_old: { 255 # src = pkgs.fetchFromGitHub { 256 # owner = "lassulus"; 257 # repo = "none-ls.nvim"; 258 # rev = "292c2b5eadea0a097b9a01804aea70f5c8125200"; 259 # sha256 = "sha256-nbzqXsxmYfxngdJH3NXMLmGgygh6reSEnruoc6l8t/s="; 260 # }; 261 # }); 262 sources.formatting.nix_flake_fmt.enable = true; 263 }; 264 plugins.web-devicons.enable = true; 265 plugins.telescope.extensions.undo.enable = true; 266 plugins.telescope = { 267 enable = true; 268 keymaps = { 269 "<leader>b" = "buffers"; 270 "<leader>u" = "undo"; 271 "<leader>ff" = "find_files"; 272 "<leader>fg" = "live_grep"; 273 "<leader>fh" = "help_tags"; 274 "<leader>fp" = "yank_history"; 275 }; 276 }; 277 plugins.lsp-format.enable = true; 278 plugins.lsp-lines.enable = true; 279 plugins.lsp = { 280 enable = true; 281 servers = { 282 bashls.enable = true; # bash 283 nixd = { 284 enable = true; # nix 285 extraOptions.offset_encoding = "utf-8"; # workaround https://github.com/nix-community/nixvim/issues/2390#issuecomment-2408101568 286 }; 287 ruff.enable = true; # python 288 pyright.enable = true; # python 289 jsonls.enable = true; # json 290 }; 291 }; 292 plugins.treesitter.enable = true; 293 plugins.copilot-cmp.enable = true; 294 plugins.copilot-lua.settings.panel.enabled = false; 295 plugins.copilot-lua.settings.suggestion.enabled = false; 296 plugins.cmp_yanky.enable = true; 297 plugins.cmp = { 298 enable = true; 299 autoEnableSources = true; 300 settings = { 301 experimental = { 302 ghost_text = true; 303 }; 304 sources = [ 305 { name = "nvim_lsp"; } 306 { name = "emoji"; } 307 { 308 name = "buffer"; # text within current buffer 309 option.get_bufnrs.__raw = "vim.api.nvim_list_bufs"; 310 keywordLength = 2; 311 } 312 { 313 name = "copilot"; # enable copilot 314 } 315 { 316 name = "path"; # file system paths 317 keywordLength = 3; 318 } 319 { name = "cmp_yanky"; } 320 ]; 321 322 mapping = { 323 "<Tab>" = "cmp.mapping.select_next_item()"; 324 "<S-Tab>" = "cmp.mapping.select_prev_item()"; 325 "<C-n>" = "cmp.mapping.select_next_item()"; 326 "<C-p>" = "cmp.mapping.select_prev_item()"; 327 "<C-e>" = "cmp.mapping.abort()"; 328 "<C-b>" = "cmp.mapping.scroll_docs(-4)"; 329 "<C-f>" = "cmp.mapping.scroll_docs(4)"; 330 "<CR>" = '' 331 cmp.mapping({ 332 i = function(fallback) 333 if cmp.visible() and cmp.get_active_entry() then 334 cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }) 335 else 336 fallback() 337 end 338 end, 339 s = cmp.mapping.confirm({ select = true }), 340 c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true }), 341 }) 342 ''; 343 }; 344 }; 345 }; 346 plugins.bufferline.enable = true; 347 plugins.which-key.enable = true; 348 plugins.yanky = { 349 enable = true; 350 enableTelescope = true; 351 }; 352 plugins.comment.enable = true; 353 plugins.copilot-chat.enable = true; 354 plugins.undotree.enable = true; # seems to be needed for undo history in telescope 355 plugins.gitsigns.enable = true; 356 }; 357 }; 358}