nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

commit 34fd3d76cedbad5b4bc438b6bdab10f7980e73aa
parent 8dbaccd5473e81e4e2e83e9dd7b4060148ffc1ff
Author: mtmn <miro@haravara.org>
Date:   Sat, 23 May 2026 14:18:38 +0200

chore: fix nvim config, misc

Diffstat:
Mhosts/void/default.nix | 2+-
Mhosts/void/overlays/config/magdalena/config.json.nix | 0
Amodules/mixins/dotfiles/config/nvim/fnl/config/blink.fnl | 20++++++++++++++++++++
Amodules/mixins/dotfiles/config/nvim/fnl/config/lsp.fnl | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Amodules/mixins/dotfiles/config/nvim/fnl/config/treesitter.fnl | 13+++++++++++++
Amodules/mixins/dotfiles/config/nvim/fnl/functions.fnl | 46++++++++++++++++++++++++++++++++++++++++++++++
Mmodules/mixins/dotfiles/config/nvim/fnl/init.fnl | 28++++++++++++++++++++++++----
Mmodules/mixins/dotfiles/config/nvim/fnl/keymaps.fnl | 54+++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mmodules/mixins/dotfiles/config/shell/rc/functions | 2+-
Mmodules/mixins/treesitter/default.nix | 2+-
Mprek.toml | 2+-
11 files changed, 211 insertions(+), 9 deletions(-)

diff --git a/hosts/void/default.nix b/hosts/void/default.nix @@ -3,7 +3,7 @@ lib, ... }: { - imports = [../../modules/mixins/dotfiles ../../modules/mixins/core ./overlays]; + imports = [../../modules/mixins/dotfiles ../../modules/mixins/core ../../modules/mixins/treesitter ./overlays]; targets.genericLinux = { enable = true; diff --git a/hosts/void/overlays/config/magdalena/config.json.nix b/hosts/void/overlays/config/magdalena/config.json.nix Binary files differ. diff --git a/modules/mixins/dotfiles/config/nvim/fnl/config/blink.fnl b/modules/mixins/dotfiles/config/nvim/fnl/config/blink.fnl @@ -0,0 +1,20 @@ +(fn config [] + (let [blink (require :blink.cmp)] + (blink.setup {:snippets {:preset :luasnip} + :appearance {:nerd_font_variant :none} + :keymap {:preset :none + :<C-p> [:select_prev :fallback] + :<C-n> [:select_next :fallback] + :<C-b> [:scroll_documentation_up :fallback] + :<C-f> [:scroll_documentation_down :fallback] + :<C-Space> [:show + :show_documentation + :hide_documentation] + :<C-e> [:hide :fallback] + :<CR> [:accept :fallback]} + :completion {:menu {:winhighlight "Normal:CmpNormal"} + :documentation {:auto_show true + :window {:winhighlight "Normal:CmpNormal"}}} + :sources {:default [:lsp :snippets :path :buffer]}}))) + +{: config} diff --git a/modules/mixins/dotfiles/config/nvim/fnl/config/lsp.fnl b/modules/mixins/dotfiles/config/nvim/fnl/config/lsp.fnl @@ -0,0 +1,51 @@ +(local {:nvim_create_augroup create-augroup + :nvim_create_autocmd create-autocmd + :nvim_clear_autocmds clear-autocmds + :nvim_get_current_buf get-current-buf} vim.api) + +(create-augroup :local-lsp-auto-format {:clear true}) + +(fn is-array [tbl] + (not (not (. tbl 1)))) + +(fn map-vals [func tbl] + (icollect [_ v (ipairs tbl)] (func v))) + +(fn create-auto-format-autocmd [extra-opts] + (let [extra-opts (or extra-opts {}) + all-extra-opts (if (is-array extra-opts) + extra-opts + [extra-opts]) + all-opts (map-vals #(vim.tbl_extend :force + {:formatting_options {:timeout_ms 5000}} + $1) + all-extra-opts) + auto-format-callback #(each [_ opts (ipairs all-opts)] + (vim.lsp.buf.format opts))] + (clear-autocmds {:event :BufWritePre + :buffer (get-current-buf) + :group :local-lsp-auto-format}) + (create-autocmd :BufWritePre + {:buffer (get-current-buf) + :callback auto-format-callback + :group :local-lsp-auto-format}) + nil)) + +(fn auto-format-on-save [filetypes extra-opts] + (let [callback #(create-auto-format-autocmd extra-opts)] + (each [_ filetype (ipairs filetypes)] + (create-autocmd :FileType {:pattern filetype : callback})))) + +(fn config [] + (vim.lsp.config :purescriptls + {:cmd [:npx :purescript-language-server :--stdio]}) + (let [open-floating-preview vim.lsp.util.open_floating_preview] + (set vim.lsp.util.open_floating_preview + (fn [contents syntax opts ...] + (let [opts (or opts {})] + (set opts.border (or opts.border :rounded)) + (open-floating-preview contents syntax opts ...)))))) + +(vim.diagnostic.config {:virtual_text true}) + +{: auto-format-on-save : config} diff --git a/modules/mixins/dotfiles/config/nvim/fnl/config/treesitter.fnl b/modules/mixins/dotfiles/config/nvim/fnl/config/treesitter.fnl @@ -0,0 +1,13 @@ +(local {:nvim_create_autocmd autocmd} vim.api) + +(fn config [] + (autocmd :FileType + {:callback (fn [] + (let [lang (vim.treesitter.language.get_lang vim.bo.filetype) + (ok) (pcall vim.treesitter.start 0 lang)] + (when (and lang ok) + (set vim.wo.foldmethod :expr) + (set vim.wo.foldexpr + "v:lua.vim.treesitter.foldexpr()"))))})) + +{: config} diff --git a/modules/mixins/dotfiles/config/nvim/fnl/functions.fnl b/modules/mixins/dotfiles/config/nvim/fnl/functions.fnl @@ -0,0 +1,46 @@ +(vim.api.nvim_create_autocmd [:BufRead :BufNewFile] + {:pattern [:*.m3u :*.m3u8] + :callback (fn [] + (set vim.bo.filetype :text) + (set vim.bo.syntax :text))}) + +(let [group (vim.api.nvim_create_augroup :MagdalenaLogFile {:clear true})] + (vim.api.nvim_create_autocmd [:BufReadPost :BufNewFile] + {: group + :callback (fn [ev] + (let [filename (vim.api.nvim_buf_get_name ev.buf)] + (when (and filename + (not= filename "") + (not (filename:match "^oil://"))) + (let [_job (vim.fn.jobstart [:magdalena + :log-file + filename] + {:detach true + :on_stderr (fn [_ + _]) + :on_exit (fn [_ + _])})] + nil))))})) + +(vim.api.nvim_create_autocmd :FileType + {:pattern :markdown + :callback (fn [] + (set vim.opt_local.suffixesadd :.md) + (set vim.opt_local.includeexpr + "v:lua.follow_md_link()") + (global follow_md_link + #(: vim.v.fname :gsub + "%[%[(.-)%]%]" "%1")) + (vim.keymap.set :n :gf + (fn [] + (let [line (vim.api.nvim_get_current_line) + col (. (vim.api.nvim_win_get_cursor 0) + 2) + link (line:match "%[([%w_%-][%w_%-]+)%]" + col)] + (if link + (vim.cmd (.. "edit " + link + :.md)) + (vim.cmd "normal! gf")))) + {:buffer true}))}) diff --git a/modules/mixins/dotfiles/config/nvim/fnl/init.fnl b/modules/mixins/dotfiles/config/nvim/fnl/init.fnl @@ -9,17 +9,32 @@ ;; fnlfmt: skip (fn setup-plugins [] + (local blink (require :config.blink)) + (local lsp (require :config.lsp)) + (local treesitter (require :config.treesitter)) + + (vim.api.nvim_create_autocmd :PackChanged + {:callback (fn [ev] + (let [{:spec {:name name} :kind kind :path path} ev.data] + (when (and (= name :blink.cmp) + (or (= kind :install) (= kind :update))) + (vim.system [:cargo :build :--release] {:cwd path}))))}) + (vim.pack.add - [(gh :aymenhafeez/doric-themes.nvim) + [(gh :aymenhafeez/doric-themes.nvim) (gh :windwp/nvim-autopairs) (gh :ibhagwan/fzf-lua) + (gh :smoka7/hop.nvim) (gh :stevearc/oil.nvim) (gh :neogitorg/neogit) (gh :sindrets/diffview.nvim) (gh :tpope/vim-commentary) (gh :tpope/vim-repeat) (gh :tpope/vim-surround) - (gh :troydm/zoomwintab.vim)] + (gh :troydm/zoomwintab.vim) + (gh :L3MON4D3/LuaSnip) + {:src (gh :neovim/nvim-lspconfig) :version :master} + {:src (gh :saghen/blink.cmp) :version (vim.version.range "^1")}] {:load true}) (vim.cmd.colorscheme :doric-obsidian) @@ -29,6 +44,7 @@ ((. (require :nvim-autopairs) :setup)) ((. (require :fzf-lua) :setup)) + ((. (require :hop) :setup) {:keys :etovxqpdygfblzhckisuran}) ((. (require :oil) :setup) {:default_file_explorer false}) ((. (require :neogit) :setup)) ((. (require :diffview) :setup) @@ -37,7 +53,10 @@ :git_cmd [:git] :use_icons false :show_help_hints false - :watch_index true})) + :watch_index true}) + (: blink :config) + (: lsp :config) + (treesitter.config)) (fn init [] (let [vimrc (.. (vim.fn.stdpath :config) :/init_.vim) @@ -52,10 +71,11 @@ (set vim.opt.undodir (.. vim-dir :undo//)) (set vim.opt.undofile true)) (set vim.opt.clipboard :unnamedplus) + (vim.opt.rtp:append (.. (vim.fn.stdpath :data) :/nix/tree-sitter)) (set package.path (.. (fs.normalize "~") "/.config/nvim/lua/?.lua;" package.path)) (setup-plugins) - (each [_ module (ipairs [:keymaps])] + (each [_ module (ipairs [:keymaps :functions])] (require module))) (init) diff --git a/modules/mixins/dotfiles/config/nvim/fnl/keymaps.fnl b/modules/mixins/dotfiles/config/nvim/fnl/keymaps.fnl @@ -9,4 +9,56 @@ (each [key func (pairs fzf-keymaps)] (vim.keymap.set :n key (.. "<cmd>lua require('fzf-lua')." func "()<CR>"))) -(local single-keymaps {:<leader>g :<cmd>Neogit<CR> :- :<cmd>Oil<CR>}) +(local single-keymaps {:<leader>g :<cmd>Neogit<CR> + :- :<cmd>Oil<CR> + :f :<cmd>HopWord<CR> + :mn :<cmd>Mnav<CR>}) + +(each [key cmd (pairs single-keymaps)] + (vim.keymap.set :n key cmd)) + +(local lsp-keymaps {:<leader>gg :hover + :<leader>gd :definition + :<leader>gD :declaration + :<leader>gi :implementation + :<leader>gt :type_definition + :<leader>gr :references + :<leader>gs :signature_help + :<leader>rr :rename + :<leader>ga :code_action + :<leader>tr :document_symbol}) + +(each [key func (pairs lsp-keymaps)] + (vim.keymap.set :n key (.. "<cmd>lua vim.lsp.buf." func "()<CR>"))) + +(vim.keymap.set :n :<leader>ta + (fn [] + (let [row (. (vim.api.nvim_win_get_cursor 0) 1)] + (vim.api.nvim_buf_set_lines 0 row row false ["- [ ] "]) + (vim.api.nvim_win_set_cursor 0 [(+ row 1) 5])))) + +(vim.keymap.set :n :<leader>tt + (fn [] + (let [line (vim.api.nvim_get_current_line)] + (var new-line nil) + (if (line:match "%[ %]") + (set new-line (line:gsub "%[ %]" "[-]" 1)) + (line:match "%[%-%]") + (set new-line (line:gsub "%[%-%]" "[x]" 1)) + (line:match "%[x%]") + (set new-line (line:gsub "%[x%]" "[ ]" 1))) + (when new-line (vim.api.nvim_set_current_line new-line))))) + +(local diagnostic-keymaps {:<leader>gl :open_float + :<leader>gp :goto_prev + :<leader>gn :goto_next}) + +(each [key func (pairs diagnostic-keymaps)] + (vim.keymap.set :n key (.. "<cmd>lua vim.diagnostic." func "()<CR>"))) + +(vim.keymap.set :v :<leader>gf + "<cmd>lua vim.lsp.buf.format({async = true})<CR>") + +(vim.keymap.set :i :<C-Space> "<cmd>lua vim.lsp.buf.completion()<CR>") + +(vim.keymap.set :n :x "\"_x") diff --git a/modules/mixins/dotfiles/config/shell/rc/functions b/modules/mixins/dotfiles/config/shell/rc/functions @@ -20,7 +20,7 @@ nvimrecomp() { nix_fennel_path="$HOME/src/sr.ht/nix/modules/mixins/dotfiles/config/nvim/fnl" config_path="$HOME/.config/nvim" - mkdir -p "$config_path"/lua + mkdir -p "$config_path"/lua/config find "$nix_fennel_path" -type f -name "*.fnl" | while read -r fnl_file; do rel_path="${fnl_file#"$nix_fennel_path"/}" diff --git a/modules/mixins/treesitter/default.nix b/modules/mixins/treesitter/default.nix @@ -3,7 +3,7 @@ lib, ... }: { - xdg.dataFile."nvim/site/tree-sitter".source = pkgs.runCommandLocal "treesitter-all" {} '' + xdg.dataFile."nvim/nix/tree-sitter".source = pkgs.runCommandLocal "treesitter-all" {} '' cp -rs ${pkgs.vimPlugins.nvim-treesitter}/runtime/. $out/ chmod -R u+w $out mkdir -p $out/parser diff --git a/prek.toml b/prek.toml @@ -9,7 +9,7 @@ hooks = [ [[repos]] repo = "https://github.com/biomejs/pre-commit" -rev = "v2.4.14" +rev = "v2.4.15" hooks = [ { id = "biome-format" } ]