From 6576509cd559aec3da271d12fa911d04d44708ec Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 9 Mar 2025 02:37:13 +0300 Subject: [PATCH 1/6] docs: fix typo in project README I should hire someone to proofread my writing... --- .github/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/README.md b/.github/README.md index 01395211..7c0974c3 100644 --- a/.github/README.md +++ b/.github/README.md @@ -237,7 +237,7 @@ customizability of plugin inputs, which is one of our primary features. an imperative path (e.g., `~/.config/nvim`) for my Neovim configuration instead of a configuration generated from Nix? -**A**: Yes! Add `"~/.config.nvim"` to `vim.additionalRuntimePaths = [ ... ]` and +**A**: Yes! Add `"~/.config/nvim"` to `vim.additionalRuntimePaths = [ ... ]` and any plugins you want to load to `vim.startPlugins`. This will load your configuration from `~/.config/nvim`. You may still use `vim.*` to modify Neovim's behaviour with Nix. From c8fd6204d02596462e354cf35b029cd6a86ce24b Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 9 Mar 2025 21:55:04 +0300 Subject: [PATCH 2/6] languages/nix: fully deprecate nixpkgs-fmt --- modules/plugins/languages/nix.nix | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/plugins/languages/nix.nix b/modules/plugins/languages/nix.nix index 1ae2693e..54c11af2 100644 --- a/modules/plugins/languages/nix.nix +++ b/modules/plugins/languages/nix.nix @@ -121,8 +121,6 @@ ) ''; }; - - nixpkgs-fmt = null; # removed }; defaultDiagnosticsProvider = ["statix" "deadnix"]; @@ -219,7 +217,6 @@ in { ${concatStringsSep ", " (attrNames formats)} ''; } - { assertion = cfg.lsp.server != "rnix"; message = '' From 9f276a0c5fac8039087b765d0762095ef61694e1 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang <59727193+horriblename@users.noreply.github.com> Date: Mon, 10 Mar 2025 09:43:34 +0100 Subject: [PATCH 3/6] languages/rust: fix unused lsp settings option (#641) Co-authored-by: raf --- modules/plugins/languages/rust.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/plugins/languages/rust.nix b/modules/plugins/languages/rust.nix index 7e9cb627..aea10687 100644 --- a/modules/plugins/languages/rust.nix +++ b/modules/plugins/languages/rust.nix @@ -62,6 +62,15 @@ in { description = "Options to pass to rust analyzer"; type = str; default = ""; + example = '' + ['rust-analyzer'] = { + cargo = {allFeature = true}, + checkOnSave = true, + procMacro = { + enable = true, + }, + }, + ''; }; }; @@ -142,6 +151,9 @@ in { then expToLua cfg.lsp.package else ''{"${cfg.lsp.package}/bin/rust-analyzer"}'' }, + default_settings = { + ${cfg.lsp.opts} + }, on_attach = function(client, bufnr) default_on_attach(client, bufnr) local opts = { noremap=true, silent=true, buffer = bufnr } From dd281b78e50072b7311c0a4480bf94ec026cc20e Mon Sep 17 00:00:00 2001 From: raf Date: Mon, 10 Mar 2025 08:46:07 +0000 Subject: [PATCH 4/6] neovim/init: add API for autocmds and autogroups (#656) --- docs/release-notes/rl-0.8.md | 8 ++ modules/neovim/init/autocmds.nix | 185 +++++++++++++++++++++++++++++++ modules/neovim/init/default.nix | 1 + 3 files changed, 194 insertions(+) create mode 100644 modules/neovim/init/autocmds.nix diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index 6b5ed694..bfe21e9b 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -52,6 +52,14 @@ - Add [yazi.nvim] as a companion plugin for Yazi, the terminal file manager. +- Add [](#opt-vim.autocmds) and [](#opt-vim.augroups) to allow declaring + autocommands via Nix. + +- Fix plugin `setupOpts` for yanky.nvim and assert if shada is configured as a + backend while shada is disabled in Neovim options. + +- Add [yazi.nvim] as a companion plugin for Yazi, the terminal file manager. + [amadaluzia](https://github.com/amadaluzia): [haskell-tools.nvim]: https://github.com/MrcJkb/haskell-tools.nvim diff --git a/modules/neovim/init/autocmds.nix b/modules/neovim/init/autocmds.nix new file mode 100644 index 00000000..5da7bc55 --- /dev/null +++ b/modules/neovim/init/autocmds.nix @@ -0,0 +1,185 @@ +{ + config, + lib, + ... +}: let + inherit (lib.options) mkOption mkEnableOption literalExpression; + inherit (lib.lists) filter; + inherit (lib.strings) optionalString; + inherit (lib.types) nullOr submodule listOf str bool; + inherit (lib.nvim.types) luaInline; + inherit (lib.nvim.lua) toLuaObject; + inherit (lib.nvim.dag) entryAfter; + + autocommandType = submodule { + options = { + enable = + mkEnableOption "" + // { + default = true; + description = "Whether to enable this autocommand"; + }; + + event = mkOption { + type = nullOr (listOf str); + default = null; + example = ["BufRead" "BufWritePre"]; + description = "The event(s) that trigger the autocommand."; + }; + + pattern = mkOption { + type = nullOr (listOf str); + default = null; + example = ["*.lua" "*.vim"]; + description = "The file pattern(s) that determine when the autocommand applies)."; + }; + + callback = mkOption { + type = nullOr luaInline; + default = null; + example = literalExpression '' + mkLuaInline ''' + function() + print("Saving a Lua file...") + end + '''' + ''; + description = "The file pattern(s) that determine when the autocommand applies."; + }; + + command = mkOption { + type = nullOr str; + default = null; + description = "Vim command string instead of a Lua function."; + }; + + group = mkOption { + type = nullOr str; + default = null; + example = "MyAutoCmdGroup"; + description = "An optional autocommand group to manage related autocommands."; + }; + + desc = mkOption { + type = nullOr str; + default = null; + example = "Notify when saving a Lua file"; + description = "A description for the autocommand."; + }; + + once = mkOption { + type = bool; + default = false; + description = "Whether autocommand run only once."; + }; + + nested = mkOption { + type = bool; + default = false; + description = "Whether to allow nested autocommands to trigger."; + }; + }; + }; + + autogroupType = submodule { + options = { + enable = + mkEnableOption "" + // { + default = true; + description = "Whether to enable this autogroup"; + }; + + name = mkOption { + type = str; + example = "MyAutoCmdGroup"; + description = "The name of the autocommand group."; + }; + + clear = mkOption { + type = bool; + default = true; + description = '' + Whether to clear existing autocommands in this group before defining new ones. + This helps avoid duplicate autocommands. + ''; + }; + }; + }; + + cfg = config.vim; +in { + options.vim = { + augroups = mkOption { + type = listOf autogroupType; + default = []; + description = '' + A list of Neovim autogroups, which are used to organize and manage related + autocommands together. Groups allow multiple autocommands to be cleared + or redefined collectively, preventing duplicate definitions. + + Each autogroup consists of a name, a boolean indicating whether to clear + existing autocommands, and a list of associated autocommands. + ''; + }; + + autocmds = mkOption { + type = listOf autocommandType; + default = []; + description = '' + A list of Neovim autocommands to be registered. + + Each entry defines an autocommand, specifying events, patterns, optional + callbacks, commands, groups, and execution settings. + ''; + }; + }; + + config = { + vim = let + enabledAutocommands = filter (cmd: cmd.enable) cfg.autocmds; + enabledAutogroups = filter (au: au.enable) cfg.augroups; + in { + luaConfigRC = { + augroups = entryAfter ["pluginConfigs"] (optionalString (enabledAutogroups != []) '' + local nvf_autogroups = {} + for _, group in ipairs(${toLuaObject enabledAutogroups}) do + if group.name then + nvf_autogroups[group.name] = { clear = group.clear } + end + end + + for group_name, options in pairs(nvf_autogroups) do + vim.api.nvim_create_augroup(group_name, options) + end + ''); + + autocmds = entryAfter ["pluginConfigs"] (optionalString (enabledAutocommands != []) '' + local nvf_autocommands = ${toLuaObject enabledAutocommands} + for _, autocmd in ipairs(nvf_autocommands) do + vim.api.nvim_create_autocmd( + autocmd.event, + { + group = autocmd.group, + pattern = autocmd.pattern, + buffer = autocmd.buffer, + desc = autocmd.desc, + callback = autocmd.callback, + command = autocmd.command, + once = autocmd.once, + nested = autocmd.nested + } + ) + end + ''); + }; + }; + + assertions = [ + { + assertion = builtins.all (cmd: (cmd.command == null || cmd.callback == null)) cfg.autocmds; + message = "An autocommand cannot have both 'command' and 'callback' defined at the same time."; + } + ]; + }; +} diff --git a/modules/neovim/init/default.nix b/modules/neovim/init/default.nix index b0c7e0ce..ac9d29e5 100644 --- a/modules/neovim/init/default.nix +++ b/modules/neovim/init/default.nix @@ -1,5 +1,6 @@ { imports = [ + ./autocmds.nix ./basic.nix ./debug.nix ./highlight.nix From 3c52dbfd72bc1ef3c72e5910ab2737a6b012ca50 Mon Sep 17 00:00:00 2001 From: Nikita <68944906+BANanaD3V@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:56:50 +0300 Subject: [PATCH 5/6] dashboard/alpha: configure with nix (#699) Co-authored-by: raf --- .github/typos.toml | 2 +- docs/release-notes/rl-0.8.md | 6 + modules/plugins/dashboard/alpha/alpha.nix | 20 +- modules/plugins/dashboard/alpha/config.nix | 228 +++------------------ 4 files changed, 52 insertions(+), 204 deletions(-) diff --git a/.github/typos.toml b/.github/typos.toml index 2ea46a8c..e2c0d59d 100644 --- a/.github/typos.toml +++ b/.github/typos.toml @@ -1,5 +1,5 @@ -default.extend-ignore-words-re = ["(?i)(noice)", "befores", "annote", "viw"] +default.extend-ignore-words-re = ["(?i)(noice)", "befores", "annote", "viw", "BANanaD3V"] files.extend-exclude = [ "npins/sources.json" ] diff --git a/docs/release-notes/rl-0.8.md b/docs/release-notes/rl-0.8.md index bfe21e9b..1a5b7e4c 100644 --- a/docs/release-notes/rl-0.8.md +++ b/docs/release-notes/rl-0.8.md @@ -5,6 +5,8 @@ - `git-conflict` keybinds are now prefixed with `` to avoid conflicting with builtins. +- `alpha` is now configured with nix, default config removed. + [NotAShelf](https://github.com/notashelf): [typst-preview.nvim]: https://github.com/chomosuke/typst-preview.nvim @@ -235,3 +237,7 @@ [projekt0n/github-nvim-theme]: https://github.com/projekt0n/github-nvim-theme - Add `github-nvim-theme` theme from [projekt0n/github-nvim-theme]. + +[BANanaD3V](https://github.com/BANanaD3V): + +- `alpha` is now configured with nix. diff --git a/modules/plugins/dashboard/alpha/alpha.nix b/modules/plugins/dashboard/alpha/alpha.nix index d5329cc7..90d02f30 100644 --- a/modules/plugins/dashboard/alpha/alpha.nix +++ b/modules/plugins/dashboard/alpha/alpha.nix @@ -1,7 +1,23 @@ {lib, ...}: let - inherit (lib.options) mkEnableOption; + inherit (lib.options) mkEnableOption mkOption; + inherit (lib.types) listOf attrsOf anything nullOr enum; in { options.vim.dashboard.alpha = { - enable = mkEnableOption "fast and fully programmable greeter for neovim [alpha.mvim]"; + enable = mkEnableOption "fast and fully programmable greeter for neovim [alpha.nvim]"; + theme = mkOption { + type = nullOr (enum ["dashboard" "startify" "theta"]); + default = "dashboard"; + description = "Alpha default theme to use"; + }; + layout = mkOption { + type = listOf (attrsOf anything); + default = []; + description = "Alpha dashboard layout"; + }; + opts = mkOption { + type = attrsOf anything; + default = {}; + description = "Optional global options"; + }; }; } diff --git a/modules/plugins/dashboard/alpha/config.nix b/modules/plugins/dashboard/alpha/config.nix index bb648a50..804189b9 100644 --- a/modules/plugins/dashboard/alpha/config.nix +++ b/modules/plugins/dashboard/alpha/config.nix @@ -5,8 +5,11 @@ }: let inherit (lib.modules) mkIf; inherit (lib.nvim.dag) entryAnywhere; + inherit (lib.nvim.lua) toLuaObject; cfg = config.vim.dashboard.alpha; + themeDefined = cfg.theme != null; + layoutDefined = cfg.layout != []; in { config = mkIf cfg.enable { vim.startPlugins = [ @@ -14,207 +17,30 @@ in { "nvim-web-devicons" ]; - # the entire credit for this dashboard configuration to https://github.com/Rishabh672003 - # honestly, excellent work - vim.pluginRC.alpha = entryAnywhere '' - local alpha = require("alpha") - local plenary_path = require("plenary.path") - local dashboard = require("alpha.themes.dashboard") - local cdir = vim.fn.getcwd() - local if_nil = vim.F.if_nil - - local nvim_web_devicons = { - enabled = true, - highlight = true, - } - - local function get_extension(fn) - local match = fn:match("^.+(%..+)$") - local ext = "" - if match ~= nil then - ext = match:sub(2) - end - return ext - end - - local function icon(fn) - local nwd = require("nvim-web-devicons") - local ext = get_extension(fn) - return nwd.get_icon(fn, ext, { default = true }) - end - - local function file_button(fn, sc, short_fn) - short_fn = short_fn or fn - local ico_txt - local fb_hl = {} - - if nvim_web_devicons.enabled then - local ico, hl = icon(fn) - local hl_option_type = type(nvim_web_devicons.highlight) - if hl_option_type == "boolean" then - if hl and nvim_web_devicons.highlight then - table.insert(fb_hl, { hl, 0, 3 }) - end - end - if hl_option_type == "string" then - table.insert(fb_hl, { nvim_web_devicons.highlight, 0, 3 }) - end - ico_txt = ico .. " " - else - ico_txt = "" - end - local file_button_el = dashboard.button(sc, ico_txt .. short_fn, "e " .. fn .. " ") - local fn_start = short_fn:match(".*[/\\]") - if fn_start ~= nil then - table.insert(fb_hl, { "Comment", #ico_txt - 2, #fn_start + #ico_txt }) - end - file_button_el.opts.hl = fb_hl - return file_button_el - end - - local default_mru_ignore = { "gitcommit" } - - local mru_opts = { - ignore = function(path, ext) - return (string.find(path, "COMMIT_EDITMSG")) or (vim.tbl_contains(default_mru_ignore, ext)) - end, - } - - --- @param start number - --- @param cwd string optional - --- @param items_number number optional number of items to generate, default = 10 - local function mru(start, cwd, items_number, opts) - opts = opts or mru_opts - items_number = if_nil(items_number, 15) - - local oldfiles = {} - for _, v in pairs(vim.v.oldfiles) do - if #oldfiles == items_number then - break - end - local cwd_cond - if not cwd then - cwd_cond = true - else - cwd_cond = vim.startswith(v, cwd) - end - local ignore = (opts.ignore and opts.ignore(v, get_extension(v))) or false - if (vim.fn.filereadable(v) == 1) and cwd_cond and not ignore then - oldfiles[#oldfiles + 1] = v - end - end - local target_width = 35 - - local tbl = {} - for i, fn in ipairs(oldfiles) do - local short_fn - if cwd then - short_fn = vim.fn.fnamemodify(fn, ":.") - else - short_fn = vim.fn.fnamemodify(fn, ":~") - end - - if #short_fn > target_width then - short_fn = plenary_path.new(short_fn):shorten(1, { -2, -1 }) - if #short_fn > target_width then - short_fn = plenary_path.new(short_fn):shorten(1, { -1 }) - end - end - - local shortcut = tostring(i + start - 1) - - local file_button_el = file_button(fn, shortcut, short_fn) - tbl[i] = file_button_el - end - return { - type = "group", - val = tbl, - opts = {}, - } - end - - local default_header = { - type = "text", - val = { - - [[███ ██ ███████ ██████ ██ ██ ██ ███ ███]], - [[████ ██ ██ ██ ██ ██ ██ ██ ████ ████]], - [[██ ██ ██ █████ ██ ██ ██ ██ ██ ██ ████ ██]], - [[██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██]], - [[██ ████ ███████ ██████ ████ ██ ██ ██]], - - -- [[ __ ]], - -- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]], - -- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]], - -- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]], - -- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]], - -- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]], - }, - opts = { - position = "center", - hl = "Type", - -- wrap = "overflow"; - }, - } - - local section_mru = { - type = "group", - val = { - { - type = "text", - val = "Recent files", - opts = { - hl = "SpecialComment", - shrink_margin = false, - position = "center", - }, - }, - { type = "padding", val = 1 }, - { - type = "group", - val = function() - return { mru(0, cdir) } - end, - opts = { shrink_margin = false }, - }, - }, - } - - local buttons = { - type = "group", - val = { - { type = "text", val = "Quick links", opts = { hl = "SpecialComment", position = "center" } }, - { type = "padding", val = 1 }, - -- TODO: buttons should be added based on whether or not the relevant plugin is available - dashboard.button("e", " New file", "ene"), -- available all the time - dashboard.button("SPC F", "󰈞 Find file"), -- telescope - dashboard.button("SPC ff", "󰊄 Live grep"), -- telescope - dashboard.button("SPC p", " Projects"), -- any project - dashboard.button("q", "󰅚 Quit", "qa"), -- available all the time - }, - position = "center", - } - - local config = { - layout = { - { type = "padding", val = 2 }, - default_header, - { type = "padding", val = 2 }, - section_mru, - { type = "padding", val = 2 }, - buttons, - }, - opts = { - margin = 5, - setup = function() - vim.cmd([[ - autocmd alpha_temp DirChanged * lua require('alpha').redraw() - ]]) - end, - }, - } - - alpha.setup(config) + vim.pluginRC.alpha = let + setupOpts = + if themeDefined + then lib.generators.mkLuaInline "require'alpha.themes.${cfg.theme}'.config" + else { + inherit (cfg) layout opts; + }; + in '' + require('alpha').setup(${toLuaObject setupOpts}) ''; + + assertions = [ + { + assertion = themeDefined || layoutDefined; + message = '' + One of 'theme' or 'layout' should be defined in Alpha configuration. + ''; + } + { + assertion = !(themeDefined && layoutDefined); + message = '' + 'theme' and 'layout' cannot be defined at the same time. + ''; + } + ]; }; } From 28b48565f024a20a44bee850f6819d1e5b3972ec Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Mon, 10 Mar 2025 12:03:48 +0300 Subject: [PATCH 6/6] ci: update typos config --- .editorconfig | 2 +- .github/typos.toml | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2f767ae8..c7fdc76d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,7 +14,7 @@ indent_style = space indent_size = 2 trim_trailing_whitespace = false -[*.{js,json,nix,yml,yaml}] +[*.{js,json,nix,yml,yaml,toml}] indent_style = space indent_size = 2 tab_width = 2 diff --git a/.github/typos.toml b/.github/typos.toml index e2c0d59d..2cd18dde 100644 --- a/.github/typos.toml +++ b/.github/typos.toml @@ -1,5 +1,10 @@ -default.extend-ignore-words-re = ["(?i)(noice)", "befores", "annote", "viw", "BANanaD3V"] -files.extend-exclude = [ -"npins/sources.json" +files.extend-exclude = ["npins/sources.json"] +default.extend-ignore-words-re = [ + "(?i)(noice)", + "befores", + "annote", + "viw", + "BA", # somehow "BANanaD3V" is valid, but BA is not... ] +