neovim runtime (#3168)
This commit is contained in:
parent
8ea0e4d6d8
commit
353d21e108
|
@ -6,6 +6,11 @@ let
|
|||
|
||||
cfg = config.programs.neovim;
|
||||
|
||||
fileType = (import ../lib/file-type.nix {
|
||||
inherit (config.home) homeDirectory;
|
||||
inherit lib pkgs;
|
||||
}).fileType;
|
||||
|
||||
jsonFormat = pkgs.formats.json { };
|
||||
|
||||
extraPython3PackageType = mkOptionType {
|
||||
|
@ -52,6 +57,19 @@ let
|
|||
type = types.package;
|
||||
description = "vim plugin";
|
||||
};
|
||||
|
||||
runtime = mkOption {
|
||||
default = { };
|
||||
# passing actual "${xdg.configHome}/nvim" as basePath was a bit tricky
|
||||
# due to how fileType.target is implemented
|
||||
type = fileType "<varname>xdg.configHome/nvim</varname>" "nvim";
|
||||
example = literalExpression ''
|
||||
{ "ftplugin/c.vim".text = "setlocal omnifunc=v:lua.vim.lsp.omnifunc"; }
|
||||
'';
|
||||
description = lib.mdDoc ''
|
||||
Set of files that have to be linked in nvim config folder.
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -62,18 +80,6 @@ let
|
|||
optional = false;
|
||||
};
|
||||
|
||||
moduleConfigure = {
|
||||
packages.home-manager = {
|
||||
start = remove null (map
|
||||
(x: if x ? plugin && x.optional == true then null else (x.plugin or x))
|
||||
allPlugins);
|
||||
opt = remove null
|
||||
(map (x: if x ? plugin && x.optional == true then x.plugin else null)
|
||||
allPlugins);
|
||||
};
|
||||
beforePlugins = "";
|
||||
};
|
||||
|
||||
extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ])
|
||||
''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
||||
extraMakeWrapperLuaCArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) ''
|
||||
|
@ -188,8 +194,7 @@ in {
|
|||
{
|
||||
viml = '''
|
||||
" Generated by home-manager
|
||||
set packpath^=/nix/store/cn8vvv4ymxjf8cfzg7db15b2838nqqib-vim-pack-dir
|
||||
set runtimepath^=/nix/store/cn8vvv4ymxjf8cfzg7db15b2838nqqib-vim-pack-dir
|
||||
map <leader> ,
|
||||
''';
|
||||
|
||||
lua = '''
|
||||
|
@ -249,7 +254,6 @@ in {
|
|||
type = types.lines;
|
||||
default = "";
|
||||
example = ''
|
||||
set nocompatible
|
||||
set nobackup
|
||||
'';
|
||||
description = ''
|
||||
|
@ -344,23 +348,25 @@ in {
|
|||
};
|
||||
|
||||
config = let
|
||||
# transform all plugins into an attrset
|
||||
pluginsNormalized = map (x:
|
||||
if (x ? plugin) then
|
||||
x
|
||||
else {
|
||||
type = x.type or "viml";
|
||||
plugin = x;
|
||||
config = "";
|
||||
optional = false;
|
||||
}) allPlugins;
|
||||
defaultPlugin = {
|
||||
type = "viml";
|
||||
plugin = null;
|
||||
config = "";
|
||||
optional = false;
|
||||
runtime = { };
|
||||
};
|
||||
|
||||
# transform all plugins into a standardized attrset
|
||||
pluginsNormalized =
|
||||
map (x: defaultPlugin // (if (x ? plugin) then x else { plugin = x; }))
|
||||
allPlugins;
|
||||
|
||||
suppressNotVimlConfig = p:
|
||||
if p.type != "viml" then p // { config = ""; } else p;
|
||||
|
||||
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
||||
inherit (cfg) extraPython3Packages withPython3 withRuby viAlias vimAlias;
|
||||
withNodeJs = cfg.withNodeJs || cfg.coc.enable;
|
||||
configure = cfg.configure // moduleConfigure;
|
||||
plugins = map suppressNotVimlConfig pluginsNormalized;
|
||||
customRC = cfg.extraConfig;
|
||||
};
|
||||
|
@ -384,19 +390,22 @@ in {
|
|||
|
||||
home.packages = [ cfg.finalPackage ];
|
||||
|
||||
xdg.configFile."nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
||||
text = neovimConfig.neovimRcContent + (optionalString
|
||||
(hasAttr "lua" config.programs.neovim.generatedConfigs) ''
|
||||
lua require('init-home-manager')
|
||||
'');
|
||||
};
|
||||
xdg.configFile."nvim/lua/init-home-manager.lua" =
|
||||
mkIf (hasAttr "lua" config.programs.neovim.generatedConfigs) {
|
||||
text = config.programs.neovim.generatedConfigs.lua;
|
||||
};
|
||||
xdg.configFile."nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
||||
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
||||
};
|
||||
xdg.configFile = mkMerge (
|
||||
# writes runtime
|
||||
(map (x: x.runtime) pluginsNormalized) ++ [{
|
||||
"nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
||||
text = neovimConfig.neovimRcContent + lib.optionalString
|
||||
(hasAttr "lua" config.programs.neovim.generatedConfigs)
|
||||
"lua require('init-home-manager')";
|
||||
};
|
||||
"nvim/lua/init-home-manager.lua" =
|
||||
mkIf (hasAttr "lua" config.programs.neovim.generatedConfigs) {
|
||||
text = config.programs.neovim.generatedConfigs.lua;
|
||||
};
|
||||
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
||||
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
||||
};
|
||||
}]);
|
||||
|
||||
programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package
|
||||
(neovimConfig // {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
{
|
||||
neovim-plugin-config = ./plugin-config.nix;
|
||||
neovim-coc-config = ./coc-config.nix;
|
||||
neovim-runtime = ./runtime.nix;
|
||||
|
||||
# waiting for a nixpkgs patch
|
||||
# neovim-no-init = ./no-init.nix;
|
||||
neovim-no-init = ./no-init.nix;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ with lib;
|
|||
config = {
|
||||
programs.neovim = {
|
||||
enable = true;
|
||||
package = pkgs.neovim-unwrapped;
|
||||
vimAlias = true;
|
||||
withNodeJs = false;
|
||||
withPython3 = true;
|
||||
|
|
|
@ -7,14 +7,14 @@ with lib;
|
|||
programs.neovim = {
|
||||
enable = true;
|
||||
extraConfig = ''
|
||||
" This should be present in vimrc
|
||||
" This 'extraConfig' should be present in vimrc
|
||||
'';
|
||||
plugins = with pkgs.vimPlugins; [
|
||||
vim-nix
|
||||
{
|
||||
plugin = vim-commentary;
|
||||
config = ''
|
||||
" This should be present too
|
||||
" plugin-specific config
|
||||
autocmd FileType c setlocal commentstring=//\ %s
|
||||
autocmd FileType c setlocal comments=://
|
||||
'';
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
" This should be present too
|
||||
|
||||
" plugin-specific config
|
||||
autocmd FileType c setlocal commentstring=//\ %s
|
||||
autocmd FileType c setlocal comments=://
|
||||
" This should be present in vimrc
|
||||
|
||||
" This 'extraConfig' should be present in vimrc
|
||||
|
|
31
tests/modules/programs/neovim/runtime.nix
Normal file
31
tests/modules/programs/neovim/runtime.nix
Normal file
|
@ -0,0 +1,31 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
{
|
||||
config = {
|
||||
programs.neovim = {
|
||||
enable = true;
|
||||
plugins = with pkgs.vimPlugins; [
|
||||
vim-nix
|
||||
{
|
||||
plugin = vim-commentary;
|
||||
runtime = {
|
||||
"after/ftplugin/c.vim".text = ''
|
||||
" plugin-specific config
|
||||
setlocal commentstring=//\ %s
|
||||
setlocal comments=://
|
||||
'';
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
extraPython3Packages = (ps: with ps; [ jedi pynvim ]);
|
||||
};
|
||||
nmt.script = ''
|
||||
ftplugin="home-files/.config/nvim/after/ftplugin/c.vim"
|
||||
assertFileExists "$ftplugin"
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in a new issue