Initial commit
This commit is contained in:
commit
e2cff543d6
29 changed files with 2701 additions and 0 deletions
182
nix/mkNeovim.nix
Normal file
182
nix/mkNeovim.nix
Normal file
|
@ -0,0 +1,182 @@
|
|||
# Function for creating a Neovim derivation
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
stdenv,
|
||||
}:
|
||||
with lib;
|
||||
{
|
||||
appName ? null, # NVIM_APPNAME - Defaults to 'nvim'
|
||||
plugins ? [], # List of plugins
|
||||
# List of dev plugins (will be bootstrapped) - useful for plugin developers
|
||||
# { name = <plugin-name>; url = <git-url>; }
|
||||
devPlugins ? [],
|
||||
# Regexes for config files to ignore, relative to the nvim directory.
|
||||
# e.g. [ "^plugin/neogit.lua" "^ftplugin/.*.lua" ]
|
||||
ignoreConfigRegexes ? [],
|
||||
extraPackages ? [], # Extra runtime dependencies (e.g. ripgrep, ...)
|
||||
# The below arguments can typically be left as their defaults
|
||||
resolvedExtraLuaPackages ? [], # Additional lua packages (not plugins), e.g. from luarocks.org
|
||||
extraPython3Packages ? p: [], # Additional python 3 packages
|
||||
withPython3 ? true, # Build Neovim with Python 3 support?
|
||||
withRuby ? false, # Build Neovim with Ruby support?
|
||||
withNodeJs ? false, # Build Neovim with NodeJS support?
|
||||
withSqlite ? true, # Add sqlite? This is a dependency for some plugins
|
||||
# You probably don't want to create vi or vim aliases
|
||||
# if the appName is something different than "nvim"
|
||||
viAlias ? appName == "nvim", # Add a "vi" binary to the build output as an alias?
|
||||
vimAlias ? appName == "nvim", # Add a "vim" binary to the build output as an alias?
|
||||
}: let
|
||||
# This is the structure of a plugin definition.
|
||||
# Each plugin in the `plugins` argument list can also be defined as this attrset
|
||||
defaultPlugin = {
|
||||
plugin = null; # e.g. nvim-lspconfig
|
||||
config = null; # plugin config
|
||||
# If `optional` is set to `false`, the plugin is installed in the 'start' packpath
|
||||
# set to `true`, it is installed in the 'opt' packpath, and can be lazy loaded with
|
||||
# ':packadd! {plugin-name}
|
||||
optional = false;
|
||||
runtime = {};
|
||||
};
|
||||
|
||||
externalPackages = extraPackages ++ (optionals withSqlite [pkgs.sqlite]);
|
||||
|
||||
# Map all plugins to an attrset { plugin = <plugin>; config = <config>; optional = <tf>; ... }
|
||||
normalizedPlugins = map (x:
|
||||
defaultPlugin
|
||||
// (
|
||||
if x ? plugin
|
||||
then x
|
||||
else {plugin = x;}
|
||||
))
|
||||
plugins;
|
||||
|
||||
# This nixpkgs util function creates an attrset
|
||||
# that pkgs.wrapNeovimUnstable uses to configure the Neovim build.
|
||||
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
||||
inherit extraPython3Packages withPython3 withRuby withNodeJs viAlias vimAlias;
|
||||
plugins = normalizedPlugins;
|
||||
};
|
||||
|
||||
# This uses the ignoreConfigRegexes list to filter
|
||||
# the nvim directory
|
||||
nvimRtpSrc = let
|
||||
src = ../nvim;
|
||||
in
|
||||
lib.cleanSourceWith {
|
||||
inherit src;
|
||||
name = "nvim-rtp-src";
|
||||
filter = path: tyoe: let
|
||||
srcPrefix = toString src + "/";
|
||||
relPath = lib.removePrefix srcPrefix (toString path);
|
||||
in
|
||||
lib.all (regex: builtins.match regex relPath == null) ignoreConfigRegexes;
|
||||
};
|
||||
|
||||
# Split runtimepath into 3 directories:
|
||||
# - lua, to be prepended to the rtp at the beginning of init.lua
|
||||
# - nvim, containing plugin, ftplugin, ... subdirectories
|
||||
# - after, to be sourced last in the startup initialization
|
||||
# See also: https://neovim.io/doc/user/starting.html
|
||||
nvimRtp = stdenv.mkDerivation {
|
||||
name = "nvim-rtp";
|
||||
src = nvimRtpSrc;
|
||||
|
||||
buildPhase = ''
|
||||
mkdir -p $out/nvim
|
||||
mkdir -p $out/lua
|
||||
rm init.lua
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
cp -r after $out/after
|
||||
rm -r after
|
||||
cp -r lua $out/lua
|
||||
rm -r lua
|
||||
cp -r * $out/nvim
|
||||
'';
|
||||
};
|
||||
|
||||
# The final init.lua content that we pass to the Neovim wrapper.
|
||||
# It wraps the user init.lua, prepends the lua lib directory to the RTP
|
||||
# and appends the nvim and after directory to the RTP
|
||||
# It also adds logic for bootstrapping dev plugins (for plugin developers)
|
||||
initLua =
|
||||
''
|
||||
vim.loader.enable()
|
||||
-- prepend lua directory
|
||||
vim.opt.rtp:prepend('${nvimRtp}/lua')
|
||||
''
|
||||
# Wrap init.lua
|
||||
+ (builtins.readFile ../nvim/init.lua)
|
||||
# Bootstrap/load dev plugins
|
||||
+ optionalString (devPlugins != []) (
|
||||
''
|
||||
local dev_pack_path = vim.fn.stdpath('data') .. '/site/pack/dev'
|
||||
local dev_plugins_dir = dev_pack_path .. '/opt'
|
||||
local dev_plugin_path
|
||||
''
|
||||
+ strings.concatMapStringsSep
|
||||
"\n"
|
||||
(plugin: ''
|
||||
dev_plugin_path = dev_plugins_dir .. '/${plugin.name}'
|
||||
if vim.fn.empty(vim.fn.glob(dev_plugin_path)) > 0 then
|
||||
vim.notify('Bootstrapping dev plugin ${plugin.name} ...', vim.log.levels.INFO)
|
||||
vim.cmd('!${pkgs.git}/bin/git clone ${plugin.url} ' .. dev_plugin_path)
|
||||
end
|
||||
vim.cmd('packadd! ${plugin.name}')
|
||||
'')
|
||||
devPlugins
|
||||
)
|
||||
# Append nvim and after directories to the runtimepath
|
||||
+ ''
|
||||
vim.opt.rtp:append('${nvimRtp}/nvim')
|
||||
vim.opt.rtp:append('${nvimRtp}/after')
|
||||
'';
|
||||
|
||||
# Add arguments to the Neovim wrapper script
|
||||
extraMakeWrapperArgs = builtins.concatStringsSep " " (
|
||||
# Set the NVIM_APPNAME environment variable
|
||||
(optional (appName != "nvim" && appName != null && appName != "")
|
||||
''--set NVIM_APPNAME "${appName}"'')
|
||||
# Add external packages to the PATH
|
||||
++ (optional (externalPackages != [])
|
||||
''--prefix PATH : "${makeBinPath externalPackages}"'')
|
||||
# Set the LIBSQLITE_CLIB_PATH if sqlite is enabled
|
||||
++ (optional withSqlite
|
||||
''--set LIBSQLITE_CLIB_PATH "${pkgs.sqlite.out}/lib/libsqlite3.so"'')
|
||||
# Set the LIBSQLITE environment variable if sqlite is enabled
|
||||
++ (optional withSqlite
|
||||
''--set LIBSQLITE "${pkgs.sqlite.out}/lib/libsqlite3.so"'')
|
||||
);
|
||||
|
||||
# Native Lua libraries
|
||||
extraMakeWrapperLuaCArgs = optionalString (resolvedExtraLuaPackages != []) ''
|
||||
--suffix LUA_CPATH ";" "${
|
||||
lib.concatMapStringsSep ";" pkgs.luaPackages.getLuaCPath
|
||||
resolvedExtraLuaPackages
|
||||
}"'';
|
||||
|
||||
# Lua libraries
|
||||
extraMakeWrapperLuaArgs =
|
||||
optionalString (resolvedExtraLuaPackages != [])
|
||||
''
|
||||
--suffix LUA_PATH ";" "${
|
||||
concatMapStringsSep ";" pkgs.luaPackages.getLuaPath
|
||||
resolvedExtraLuaPackages
|
||||
}"'';
|
||||
in
|
||||
# wrapNeovimUnstable is the nixpkgs utility function for building a Neovim derivation.
|
||||
pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped (neovimConfig
|
||||
// {
|
||||
luaRcContent = initLua;
|
||||
wrapperArgs =
|
||||
escapeShellArgs neovimConfig.wrapperArgs
|
||||
+ " "
|
||||
+ extraMakeWrapperArgs
|
||||
+ " "
|
||||
+ extraMakeWrapperLuaCArgs
|
||||
+ " "
|
||||
+ extraMakeWrapperLuaArgs;
|
||||
wrapRc = true;
|
||||
})
|
114
nix/neovim-overlay.nix
Normal file
114
nix/neovim-overlay.nix
Normal file
|
@ -0,0 +1,114 @@
|
|||
# This overlay, when applied to nixpkgs, adds the final neovim derivation to nixpkgs.
|
||||
{inputs}: final: prev:
|
||||
with final.pkgs.lib; let
|
||||
pkgs = final;
|
||||
|
||||
# Use this to create a plugin from a flake input
|
||||
mkNvimPlugin = src: pname:
|
||||
pkgs.vimUtils.buildVimPlugin {
|
||||
inherit pname src;
|
||||
version = src.lastModifiedDate;
|
||||
};
|
||||
|
||||
# This is the helper function that builds the Neovim derivation.
|
||||
mkNeovim = pkgs.callPackage ./mkNeovim.nix {};
|
||||
|
||||
# A plugin can either be a package or an attrset, such as
|
||||
# { plugin = <plugin>; # the package, e.g. pkgs.vimPlugins.nvim-cmp
|
||||
# config = <config>; # String; a config that will be loaded with the plugin
|
||||
# # Boolean; Whether to automatically load the plugin as a 'start' plugin,
|
||||
# # or as an 'opt' plugin, that can be loaded with `:packadd!`
|
||||
# optional = <true|false>; # Default: false
|
||||
# ...
|
||||
# }
|
||||
all-plugins = with pkgs.vimPlugins; [
|
||||
# plugins from nixpkgs go in here.
|
||||
# https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=vimPlugins
|
||||
nvim-treesitter.withAllGrammars
|
||||
luasnip # snippets | https://github.com/l3mon4d3/luasnip/
|
||||
# nvim-cmp (autocompletion) and extensions
|
||||
nvim-cmp # https://github.com/hrsh7th/nvim-cmp
|
||||
cmp_luasnip # snippets autocompletion extension for nvim-cmp | https://github.com/saadparwaiz1/cmp_luasnip/
|
||||
lspkind-nvim # vscode-like LSP pictograms | https://github.com/onsails/lspkind.nvim/
|
||||
cmp-nvim-lsp # LSP as completion source | https://github.com/hrsh7th/cmp-nvim-lsp/
|
||||
cmp-nvim-lsp-signature-help # https://github.com/hrsh7th/cmp-nvim-lsp-signature-help/
|
||||
cmp-buffer # current buffer as completion source | https://github.com/hrsh7th/cmp-buffer/
|
||||
cmp-path # file paths as completion source | https://github.com/hrsh7th/cmp-path/
|
||||
cmp-nvim-lua # neovim lua API as completion source | https://github.com/hrsh7th/cmp-nvim-lua/
|
||||
cmp-cmdline # cmp command line suggestions
|
||||
cmp-cmdline-history # cmp command line history suggestions
|
||||
# ^ nvim-cmp extensions
|
||||
# git integration plugins
|
||||
diffview-nvim # https://github.com/sindrets/diffview.nvim/
|
||||
neogit # https://github.com/TimUntersberger/neogit/
|
||||
gitsigns-nvim # https://github.com/lewis6991/gitsigns.nvim/
|
||||
vim-fugitive # https://github.com/tpope/vim-fugitive/
|
||||
# ^ git integration plugins
|
||||
# telescope and extensions
|
||||
telescope-nvim # https://github.com/nvim-telescope/telescope.nvim/
|
||||
telescope-fzy-native-nvim # https://github.com/nvim-telescope/telescope-fzy-native.nvim
|
||||
# telescope-smart-history-nvim # https://github.com/nvim-telescope/telescope-smart-history.nvim
|
||||
# ^ telescope and extensions
|
||||
# UI
|
||||
lualine-nvim # Status line | https://github.com/nvim-lualine/lualine.nvim/
|
||||
nvim-navic # Add LSP location to lualine | https://github.com/SmiteshP/nvim-navic
|
||||
statuscol-nvim # Status column | https://github.com/luukvbaal/statuscol.nvim/
|
||||
nvim-treesitter-context # nvim-treesitter-context
|
||||
# ^ UI
|
||||
# language support
|
||||
# ^ language support
|
||||
# navigation/editing enhancement plugins
|
||||
vim-unimpaired # predefined ] and [ navigation keymaps | https://github.com/tpope/vim-unimpaired/
|
||||
eyeliner-nvim # Highlights unique characters for f/F and t/T motions | https://github.com/jinh0/eyeliner.nvim
|
||||
nvim-surround # https://github.com/kylechui/nvim-surround/
|
||||
nvim-treesitter-textobjects # https://github.com/nvim-treesitter/nvim-treesitter-textobjects/
|
||||
nvim-ts-context-commentstring # https://github.com/joosepalviste/nvim-ts-context-commentstring/
|
||||
# ^ navigation/editing enhancement plugins
|
||||
# Useful utilities
|
||||
nvim-unception # Prevent nested neovim sessions | nvim-unception
|
||||
# ^ Useful utilities
|
||||
# libraries that other plugins depend on
|
||||
sqlite-lua
|
||||
plenary-nvim
|
||||
nvim-web-devicons
|
||||
vim-repeat
|
||||
# ^ libraries that other plugins depend on
|
||||
# bleeding-edge plugins from flake inputs
|
||||
# (mkNvimPlugin inputs.wf-nvim "wf.nvim") # (example) keymap hints | https://github.com/Cassin01/wf.nvim
|
||||
# ^ bleeding-edge plugins from flake inputs
|
||||
which-key-nvim
|
||||
];
|
||||
|
||||
extraPackages = with pkgs; [
|
||||
# language servers, etc.
|
||||
lua-language-server
|
||||
nil # nix LSP
|
||||
];
|
||||
in {
|
||||
# This is the neovim derivation
|
||||
# returned by the overlay
|
||||
nvim-pkg = mkNeovim {
|
||||
plugins = all-plugins;
|
||||
inherit extraPackages;
|
||||
};
|
||||
|
||||
# This can be symlinked in the devShell's shellHook
|
||||
nvim-luarc-json = final.mk-luarc-json {
|
||||
plugins = all-plugins;
|
||||
};
|
||||
|
||||
# You can add as many derivations as you like.
|
||||
# Use `ignoreConfigRegexes` to filter out config
|
||||
# files you would not like to include.
|
||||
#
|
||||
# For example:
|
||||
#
|
||||
# nvim-pkg-no-telescope = mkNeovim {
|
||||
# plugins = [];
|
||||
# ignoreConfigRegexes = [
|
||||
# "^plugin/telescope.lua"
|
||||
# "^ftplugin/.*.lua"
|
||||
# ];
|
||||
# inherit extraPackages;
|
||||
# };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue