Skip to content

Commit 346f573

Browse files
authored
feat(wrapperModules.neovim): init (#180)
a wrapper module which hopes to capture all the good parts of nixCats, nvf, and mnw in a general implementation module system Also comes with a starter template
1 parent d745ebf commit 346f573

29 files changed

+3067
-0
lines changed

templates/default.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
path = ./flake;
44
description = "An example flake wrapping a package with a module";
55
};
6+
neovim = {
7+
path = ./neovim;
8+
description = "An example flake showing basic usage of the neovim module";
9+
};
610
}

templates/neovim/flake.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
description = "Flake exporting a configured package using wlib.evalModule";
3+
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
4+
inputs.wrappers.url = "github:BirdeeHub/nix-wrapper-modules";
5+
inputs.wrappers.inputs.nixpkgs.follows = "nixpkgs";
6+
inputs.nvim-treesitter-textobjects = {
7+
url = "github:nvim-treesitter/nvim-treesitter-textobjects/main";
8+
flake = false;
9+
};
10+
outputs =
11+
{
12+
self,
13+
nixpkgs,
14+
wrappers,
15+
...
16+
}@inputs:
17+
let
18+
forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.all;
19+
module = nixpkgs.lib.modules.importApply ./module.nix inputs;
20+
wrapper = wrappers.lib.evalModule module;
21+
in
22+
{
23+
overlays = {
24+
default = final: prev: { neovim = wrapper.config.wrap { pkgs = final; }; };
25+
neovim = self.overlays.default;
26+
};
27+
wrapperModules = {
28+
default = module;
29+
neovim = self.wrapperModules.default;
30+
};
31+
wrappedModules = {
32+
default = wrapper.config;
33+
neovim = self.wrappedModules.default;
34+
};
35+
packages = forAllSystems (
36+
system:
37+
let
38+
pkgs = import nixpkgs { inherit system; };
39+
in
40+
{
41+
default = wrapper.config.wrap { inherit pkgs; };
42+
neovim = self.packages.${system}.default;
43+
}
44+
);
45+
};
46+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
These files are ran on the filetype corresponding to their name.
2+
3+
see [`:h 'rtp'`](https://neovim.io/doc/user/options.html#'rtp')

templates/neovim/ftplugin/lua.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- NOTE: Lazydev will make your Lua LSP stronger for Neovim config
2+
-- we are also using this as an opportunity to show you how to lazy load plugins!
3+
-- This plugin was added to the optionalPlugins section of the main nix file of this template.
4+
-- Thus, it is not loaded and must be packadded.
5+
-- NOTE: Use `=require(vim.g.nix_info_plugin_name).plugins.lazy` to see the names of all lazy plugins downloaded via Nix for packadd.
6+
vim.cmd.packadd('lazydev.nvim')
7+
require('lazydev').setup({
8+
library = { },
9+
})

templates/neovim/init.lua

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
-- NOTE: init.lua gets ran before anything else.
2+
3+
-- NOTE: These 2 need to be set up before any plugins are loaded.
4+
vim.g.mapleader = ' '
5+
vim.g.maplocalleader = ' '
6+
7+
-- [[ Setting options ]]
8+
-- See `:help vim.o`
9+
10+
-- Sets how neovim will display certain whitespace characters in the editor.
11+
-- See `:help 'list'`
12+
-- and `:help 'listchars'`
13+
vim.opt.list = true
14+
vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '' }
15+
16+
-- Set highlight on search
17+
vim.opt.hlsearch = true
18+
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')
19+
20+
-- Preview substitutions live, as you type!
21+
vim.opt.inccommand = 'split'
22+
23+
-- Minimal number of screen lines to keep above and below the cursor.
24+
vim.opt.scrolloff = 10
25+
26+
-- Make line numbers default
27+
vim.wo.number = true
28+
29+
-- Enable mouse mode
30+
vim.o.mouse = 'a'
31+
32+
-- Indent
33+
-- vim.o.smarttab = true
34+
vim.opt.cpoptions:append('I')
35+
vim.o.expandtab = true
36+
-- vim.o.smartindent = true
37+
-- vim.o.autoindent = true
38+
-- vim.o.tabstop = 4
39+
-- vim.o.softtabstop = 4
40+
-- vim.o.shiftwidth = 4
41+
42+
-- stops line wrapping from being confusing
43+
vim.o.breakindent = true
44+
45+
-- Save undo history
46+
vim.o.undofile = true
47+
48+
-- Case-insensitive searching UNLESS \C or capital in search
49+
vim.o.ignorecase = true
50+
vim.o.smartcase = true
51+
52+
-- Keep signcolumn on by default
53+
vim.wo.signcolumn = 'yes'
54+
vim.wo.relativenumber = true
55+
56+
-- Decrease update time
57+
vim.o.updatetime = 250
58+
vim.o.timeoutlen = 300
59+
60+
-- Set completeopt to have a better completion experience
61+
vim.o.completeopt = 'menu,preview,noselect'
62+
63+
-- NOTE: You should make sure your terminal supports this
64+
vim.o.termguicolors = true
65+
66+
vim.g.netrw_liststyle=0
67+
vim.g.netrw_banner=0
68+
-- [[ Disable auto comment on enter ]]
69+
-- See :help formatoptions
70+
vim.api.nvim_create_autocmd("FileType", {
71+
desc = "remove formatoptions",
72+
callback = function()
73+
vim.opt.formatoptions:remove({ "c", "r", "o" })
74+
end,
75+
})
76+
-- [[ Highlight on yank ]]
77+
-- See `:help vim.highlight.on_yank()`
78+
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
79+
vim.api.nvim_create_autocmd('TextYankPost', {
80+
callback = function()
81+
vim.highlight.on_yank()
82+
end,
83+
group = highlight_group,
84+
pattern = '*',
85+
})
86+
87+
-- Keymaps for better default experience
88+
-- See `:help vim.keymap.set()`
89+
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv", { desc = 'Moves Line Down' })
90+
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv", { desc = 'Moves Line Up' })
91+
vim.keymap.set("n", "<C-d>", "<C-d>zz", { desc = 'Scroll Down' })
92+
vim.keymap.set("n", "<C-u>", "<C-u>zz", { desc = 'Scroll Up' })
93+
vim.keymap.set("n", "n", "nzzzv", { desc = 'Next Search Result' })
94+
vim.keymap.set("n", "N", "Nzzzv", { desc = 'Previous Search Result' })
95+
vim.keymap.set("n", "<leader><leader>[", "<cmd>bprev<CR>", { desc = 'Previous buffer' })
96+
vim.keymap.set("n", "<leader><leader>]", "<cmd>bnext<CR>", { desc = 'Next buffer' })
97+
vim.keymap.set("n", "<leader><leader>l", "<cmd>b#<CR>", { desc = 'Last buffer' })
98+
vim.keymap.set("n", "<leader><leader>d", "<cmd>bdelete<CR>", { desc = 'delete buffer' })
99+
100+
-- Remap for dealing with word wrap
101+
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
102+
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
103+
104+
-- Diagnostic keymaps
105+
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Open floating diagnostic message' })
106+
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostics list' })
107+
108+
-- Sync clipboard between OS and Neovim.
109+
-- But it constantly clobbers your system clipboard whenever you delete anything.
110+
-- See `:help 'clipboard'`
111+
-- vim.o.clipboard = 'unnamedplus'
112+
-- You should instead use these keybindings to use the clipboard so that they are still easy to use, but dont conflict
113+
vim.keymap.set({"v", "x", "n"}, '<leader>y', '"+y', { noremap = true, silent = true, desc = 'Yank to clipboard' })
114+
vim.keymap.set({"n", "v", "x"}, '<leader>Y', '"+yy', { noremap = true, silent = true, desc = 'Yank line to clipboard' })
115+
vim.keymap.set({'n', 'v', 'x'}, '<leader>p', '"+p', { noremap = true, silent = true, desc = 'Paste from clipboard' })
116+
vim.keymap.set('i', '<C-p>', '<C-r><C-p>+', { noremap = true, silent = true, desc = 'Paste from clipboard from within insert mode' })
117+
vim.keymap.set("x", "<leader>P", '"_dP', { noremap = true, silent = true, desc = 'Paste over selection without erasing unnamed register' })

templates/neovim/module.nix

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
inputs:
2+
{
3+
config,
4+
wlib,
5+
lib,
6+
pkgs,
7+
...
8+
}:
9+
{
10+
imports = [ wlib.wrapperModules.neovim ];
11+
# choose a directory for your config.
12+
# this can be a string, for if you don't want nix to manage it right now.
13+
# but be careful, it also doesn't get provisioned by nix if it isnt in the store.
14+
config.settings.config_directory = ./.;
15+
16+
# The makeWrapper options are available
17+
config.extraPackages = with pkgs; [
18+
lazygit
19+
lua-language-server
20+
tree-sitter
21+
stylua
22+
nixd
23+
alejandra
24+
];
25+
# your config/plugin specifications
26+
# a set of plugins or specs, which can contain a list of plugins or specs if desired.
27+
config.specs.general = with pkgs.vimPlugins; [
28+
{
29+
# These can be specs too!
30+
data = snacks-nvim;
31+
# maybe you want to do something like this?
32+
33+
# lazy = false | true;
34+
# type = "lua" | "fnl" | "vim";
35+
# info = { /* some opts from nix to the config */ };
36+
# config = ''
37+
# local info, pname, lazy = ...
38+
# -- run snacks bigfile or something
39+
# '';
40+
41+
# before = [ "INIT_MAIN" ];
42+
# putting before = [ "INIT_MAIN" ] here will run this before the main init
43+
44+
# things can target any spec that has a name.
45+
name = "snacks-spec";
46+
# now something else can be after = [ "snacks-spec" ]
47+
# the spec name is not the plugin name.
48+
# to override the plugin name, use `pname`
49+
}
50+
onedark-nvim
51+
vim-sleuth
52+
mini-ai
53+
mini-icons
54+
mini-pairs
55+
nvim-lspconfig
56+
vim-startuptime
57+
blink-cmp
58+
lualine-nvim
59+
lualine-lsp-progress
60+
gitsigns-nvim
61+
which-key-nvim
62+
nvim-lint
63+
conform-nvim
64+
nvim-dap-ui
65+
nvim-dap-virtual-text
66+
# building a plugin from a source outside of nixpkgs
67+
(config.nvim-lib.mkPlugin "treesitter-textobjects" inputs.nvim-treesitter-textobjects)
68+
# treesitter + grammars
69+
nvim-treesitter.withAllGrammars
70+
# This is for if you only want some of the grammars
71+
# (nvim-treesitter.withPlugins (
72+
# plugins: with plugins; [
73+
# nix
74+
# lua
75+
# ]
76+
# ))
77+
];
78+
79+
# you can name these whatever you want. These ones are named `general` and `lazy`
80+
# You can use the before and after fields to run them before or after other specs or spec of lists of specs
81+
config.specs.lazy = {
82+
# this `lazy = true` definition will transfer to specs in the contained DAL, if there is one.
83+
# This is because the definition of lazy in `config.specMods` checks `parentSpec.lazy or false`
84+
# the submodule type for `config.specMods` gets `parentSpec` as a `specialArg`.
85+
# you can define options like this too!
86+
lazy = true;
87+
# here we chose a DAL of plugins, but we can also pass a single plugin, or null
88+
# plugins are of type wlib.types.stringable
89+
data = with pkgs.vimPlugins; [
90+
lazydev-nvim
91+
];
92+
# top level specs don't need to declare their dag name to be targetable.
93+
# so we can target general here, without adding name = "general" in the `general` spec above.
94+
# in fact, we didn't even need to give `general` a spec, its just a list!
95+
after = [ "general" ];
96+
};
97+
98+
# These specMods are modules which modify your specs in config.specs
99+
# you can override defaults, or make your own options.
100+
config.specMods =
101+
{ parentSpec, ... }:
102+
{
103+
config.collateGrammars = lib.mkDefault (parentSpec.collateGrammars or true);
104+
};
105+
# or, if you dont care about propagating parent values:
106+
# config.specMods.collateGrammars = lib.mkDefault true;
107+
108+
# There are some default hosts!
109+
# python, ruby, and node are enabled by default
110+
# perl and neovide are not.
111+
112+
# To add a wrapped $out/bin/${config.binName}-neovide to the resulting neovim derivation
113+
# config.hosts.neovide.nvim-host.enable = true;
114+
115+
# If you want to install multiple neovim derivations via home.packages or environment.systemPackages
116+
# in order to prevent path collisions:
117+
118+
# set this to false:
119+
# config.settings.dont_link = true;
120+
121+
# and make sure these dont share values:
122+
# config.binName = "nvim";
123+
# config.settings.aliases = [ ];
124+
}

templates/neovim/plugin/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
all files in this directory get ran at startup
2+
3+
see [`:h 'rtp'`](https://neovim.io/doc/user/options.html#'rtp')
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require("blink.cmp").setup({
2+
-- 'default' (recommended) for mappings similar to built-in completions (C-y to accept)
3+
-- See :h blink-cmp-config-keymap for configuring keymaps
4+
keymap = { preset = 'default' },
5+
appearance = {
6+
nerd_font_variant = 'mono'
7+
},
8+
signature = { enabled = true, },
9+
sources = {
10+
default = { 'lsp', 'path', 'snippets', 'buffer' },
11+
providers = {
12+
path = {
13+
score_offset = 50,
14+
},
15+
lsp = {
16+
score_offset = 40,
17+
},
18+
snippets = {
19+
score_offset = 40,
20+
},
21+
},
22+
},
23+
})

0 commit comments

Comments
 (0)