From db8bae6f312d6d4a9c1309282045829cc1885deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Fri, 16 Feb 2024 20:36:20 +0100 Subject: [PATCH] feat(docs): Add neovim module documentation --- docs/default.nix | 24 ++--- docs/src/SUMMARY.md | 1 + docs/src/nvim-options.md | 13 +++ nvim/default.nix | 192 ++++++++++++++++++++++----------------- nvim/options.nix | 23 +---- 5 files changed, 132 insertions(+), 121 deletions(-) create mode 100644 docs/src/nvim-options.md diff --git a/docs/default.nix b/docs/default.nix index c9c6786..18aeba9 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -6,22 +6,15 @@ let hash = "sha256-pLP73zlmGkbC/zV6bwnB6ijRf9gVkj5/VYMGLhiQ1/Q="; }; filterVisible = toplevelOption: option: option // { visible = option.visible && builtins.elemAt option.loc 0 == toplevelOption; }; + home-eval = lib.evalModules { modules = [ ../home/options.nix ]; specialArgs = { inherit pkgs; }; }; + nvim-eval = lib.evalModules { modules = [ ../nvim/options.nix ]; }; nixos-eval = lib.evalModules { modules = [ ../nixos/options.nix ]; }; - home-eval = lib.evalModules { - modules = [ ../home/options.nix ]; - specialArgs = { inherit pkgs; }; - }; - nixos-markdown = (pkgs.nixosOptionsDoc { - inherit (nixos-eval) options; - transformOptions = filterVisible "jconfig"; - }).optionsCommonMark; - home-markdown = (pkgs.nixosOptionsDoc { - inherit (home-eval) options; - transformOptions = filterVisible "jhome"; - }).optionsCommonMark; + home-markdown = (pkgs.nixosOptionsDoc { inherit (home-eval) options; transformOptions = filterVisible "jhome"; }).optionsCommonMark; + nvim-markdown = (pkgs.nixosOptionsDoc { inherit (nvim-eval) options; transformOptions = filterVisible "jhome"; }).optionsCommonMark; + nixos-markdown = (pkgs.nixosOptionsDoc { inherit (nixos-eval) options; transformOptions = filterVisible "jconfig"; }).optionsCommonMark; in { - inherit nixos-markdown home-markdown; + inherit nixos-markdown nvim-markdown home-markdown; docs = pkgs.stdenvNoCC.mkDerivation { name = "nixos-configuration-book"; src = ./.; @@ -31,8 +24,9 @@ in ln -s ${highlight} ./theme/highlight.js # copy generated options removing the declared by statement - sed '/^\*Declared by:\*$/,/^$/d' <${home-markdown} >> src/home-options.md - sed '/^\*Declared by:\*$/,/^$/d' <${nixos-markdown} >> src/nixos-options.md + sed '/^\*Declared by:\*$/,/^$/d' <${home-markdown} >> ./src/home-options.md + sed '/^\*Declared by:\*$/,/^$/d' <${nvim-markdown} >> ./src/nvim-options.md + sed '/^\*Declared by:\*$/,/^$/d' <${nixos-markdown} >> ./src/nixos-options.md ''; nativeBuildInputs = [ pkgs.mdbook-toc ]; diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 9af3e96..16ff37a 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -2,4 +2,5 @@ - [Nix Based Configuration](./configuration-overview.md) - [NixOS Module Options](./nixos-options.md) + - [Neovim Module Options](./nvim-options.md) - [Home Manager Module Options](./home-options.md) diff --git a/docs/src/nvim-options.md b/docs/src/nvim-options.md new file mode 100644 index 0000000..828d8dc --- /dev/null +++ b/docs/src/nvim-options.md @@ -0,0 +1,13 @@ +# Neovim Module Options + +Here you will find the neovim options and their default values (if they have +any). + +You might also want to take a look at the [NixNeovim +Manual](https://nixneovim.github.io/NixNeovim/options.html) or search the +available options through [NixNeovim option +search](https://nixneovim.github.io/nixneovim-option-search/). + +## Table of Contents + + diff --git a/nvim/default.nix b/nvim/default.nix index 4828531..c5c7cd9 100644 --- a/nvim/default.nix +++ b/nvim/default.nix @@ -1,90 +1,112 @@ -{ pkgs, ... }: { +{ pkgs, config, lib, ... }: +let + cfg = config.jhome.nvim; +in +{ + imports = [ + ./options.nix + ]; - programs.nixneovim = { - enable = true; - package = pkgs.neovim-nightly; - defaultEditor = true; - colorschemes.gruvbox-nvim = { + config = lib.mkIf cfg.enable { + programs.nixneovim = { enable = true; - bold = true; - transparentBg = true; - trueColor = true; + package = pkgs.neovim-nightly; + defaultEditor = true; + globals.mapleader = " "; + # Appearance + colorschemes.gruvbox-nvim.enable = true; + colorschemes.gruvbox-nvim.bold = true; + colorschemes.gruvbox-nvim.transparentBg = true; + colorschemes.gruvbox-nvim.trueColor = true; + options.number = true; + options.relativenumber = true; + options.colorcolumn = "+1"; + options.cursorline = true; + options.wrap = false; + options.splitright = true; + # Tabs & indentation + options.smarttab = true; + options.autoindent = true; + options.smartindent = true; + # Search path + options.path = ".,/usr/include,**"; + options.wildmenu = true; + options.hlsearch = true; + options.incsearch = true; + options.ignorecase = true; # Search ignores cases + options.smartcase = true; # Unless it has a capital letter + # Enable local configuration :h 'exrc' + options.exrc = true; # safe since nvim 0.9 + plugins = import ./plugins; + mappings = import ./mappings.nix; + augroups = import ./augroups.nix; + extraPlugins = + (with pkgs.vimExtraPlugins; [ dressing-nvim rustaceanvim idris2-nvim nui-nvim nvim-lint ]) + ++ (with pkgs.vimPlugins; [ lualine-lsp-progress nvim-web-devicons FTerm-nvim cmp-cmdline formatter-nvim ]); + # Formatting + extraPackages = with pkgs; [ stylua shfmt taplo yamlfmt nixpkgs-fmt ]; + extraLuaPreConfig = '' + -- Lua Pre Config + if vim.fn.has 'termguicolors' then + -- Enable RGB colors + vim.g.termguicolors = true + end + + -- Useful function + local has_words_before = function() + -- unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 + and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil + end + -- END: Lua Pre Config + ''; + extraLuaPostConfig = '' + do -- Setup cmp-cmdline + local cmp = require "cmp" + cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources { {name = "rg" }, { name = "buffer" } }, + }) + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } }) + }) + end + + do -- Setup dressing.nvim + -- require("dressing").setup() + end + + do -- Setup formatter.nvim + -- local util = require "formatter.util" + require("formatter").setup { + logging = true, + log_level = vim.log.levels.WARN, + ["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace }, + -- Filetype Formatting + c = { require("formatter.filetypes.c").clangformat }, + sh = { require("formatter.filetypes.sh").shfmt }, + cpp = { require("formatter.filetypes.cpp").clangformat }, + lua = { require("formatter.filetypes.lua").stylua }, + nix = { require("formatter.filetypes.nix").nixpkgs-fmt }, + zig = { require("formatter.filetypes.zig").zigfmt }, + rust = { require("formatter.filetypes.rust").rustfmt }, + toml = { require("formatter.filetypes.toml").taplo }, + yaml = { require("formatter.filetypes.yaml").yamlfmt }, + } + end + + do -- Setup idris2-nvim + require("idris2").setup { } + end + + do -- Setup nvim-lint + require("lint").linters_by_ft = { + latex = { "chktex", "typos" }, + } + end + ''; }; - globals.mapleader = " "; - options = import ./options.nix; - plugins = import ./plugins; - mappings = import ./mappings.nix; - augroups = import ./augroups.nix; - extraPlugins = builtins.attrValues { - inherit (pkgs.vimExtraPlugins) dressing-nvim rustaceanvim idris2-nvim nui-nvim nvim-lint; - inherit (pkgs.vimPlugins) lualine-lsp-progress nvim-web-devicons FTerm-nvim cmp-cmdline formatter-nvim; - }; - # Formatting - extraPackages = builtins.attrValues { - # Formatters - inherit (pkgs) stylua shfmt taplo yamlfmt alejandra; - }; - extraLuaPreConfig = '' - -- Lua Pre Config - if vim.fn.has 'termguicolors' then - -- Enable RGB colors - vim.g.termguicolors = true - end - - -- Useful function - local has_words_before = function() - -- unpack = unpack or table.unpack - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 - and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil - end - -- END: Lua Pre Config - ''; - extraLuaPostConfig = '' - do -- Setup cmp-cmdline - local cmp = require "cmp" - cmp.setup.cmdline("/", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources { {name = "rg" }, { name = "buffer" } }, - }) - cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } }) - }) - end - - do -- Setup dressing.nvim - -- require("dressing").setup() - end - - do -- Setup formatter.nvim - -- local util = require "formatter.util" - require("formatter").setup { - logging = true, - log_level = vim.log.levels.WARN, - ["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace }, - -- Filetype Formatting - c = { require("formatter.filetypes.c").clangformat }, - sh = { require("formatter.filetypes.sh").shfmt }, - cpp = { require("formatter.filetypes.cpp").clangformat }, - lua = { require("formatter.filetypes.lua").stylua }, - nix = { require("formatter.filetypes.nix").alejandra }, - zig = { require("formatter.filetypes.zig").zigfmt }, - rust = { require("formatter.filetypes.rust").rustfmt }, - toml = { require("formatter.filetypes.toml").taplo }, - yaml = { require("formatter.filetypes.yaml").yamlfmt }, - } - end - - do -- Setup idris2-nvim - require("idris2").setup { } - end - - do -- Setup nvim-lint - require("lint").linters_by_ft = { - latex = { "chktex", "typos" }, - } - end - ''; }; } diff --git a/nvim/options.nix b/nvim/options.nix index f4b1449..d12a9f7 100644 --- a/nvim/options.nix +++ b/nvim/options.nix @@ -1,22 +1,3 @@ -{ - # Appearance - number = true; - relativenumber = true; - colorcolumn = "+1"; - cursorline = true; - wrap = false; - splitright = true; - # Tabs & indentation - smarttab = true; - autoindent = true; - smartindent = true; - # Search path - path = ".,/usr/include,**"; - wildmenu = true; - hlsearch = true; - incsearch = true; - ignorecase = true; # Search ignores cases - smartcase = true; # Unless it has a capital letter - # Enable local configuration :h 'exrc' - exrc = true; # safe since nvim 0.9 +{ lib, ... }: { + options.jhome.nvim.enable = lib.mkEnableOption "jalil's neovim configuration" // { default = true; example = false; }; }