mirror of
https://github.com/nix-community/home-manager
synced 2024-12-25 03:09:47 +01:00
neovim runtime (#3168)
This commit is contained in:
parent
8ea0e4d6d8
commit
353d21e108
6 changed files with 88 additions and 45 deletions
|
@ -6,6 +6,11 @@ let
|
||||||
|
|
||||||
cfg = config.programs.neovim;
|
cfg = config.programs.neovim;
|
||||||
|
|
||||||
|
fileType = (import ../lib/file-type.nix {
|
||||||
|
inherit (config.home) homeDirectory;
|
||||||
|
inherit lib pkgs;
|
||||||
|
}).fileType;
|
||||||
|
|
||||||
jsonFormat = pkgs.formats.json { };
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
|
||||||
extraPython3PackageType = mkOptionType {
|
extraPython3PackageType = mkOptionType {
|
||||||
|
@ -52,6 +57,19 @@ let
|
||||||
type = types.package;
|
type = types.package;
|
||||||
description = "vim plugin";
|
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;
|
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 != [ ])
|
extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ])
|
||||||
''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
||||||
extraMakeWrapperLuaCArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) ''
|
extraMakeWrapperLuaCArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) ''
|
||||||
|
@ -188,8 +194,7 @@ in {
|
||||||
{
|
{
|
||||||
viml = '''
|
viml = '''
|
||||||
" Generated by home-manager
|
" Generated by home-manager
|
||||||
set packpath^=/nix/store/cn8vvv4ymxjf8cfzg7db15b2838nqqib-vim-pack-dir
|
map <leader> ,
|
||||||
set runtimepath^=/nix/store/cn8vvv4ymxjf8cfzg7db15b2838nqqib-vim-pack-dir
|
|
||||||
''';
|
''';
|
||||||
|
|
||||||
lua = '''
|
lua = '''
|
||||||
|
@ -249,7 +254,6 @@ in {
|
||||||
type = types.lines;
|
type = types.lines;
|
||||||
default = "";
|
default = "";
|
||||||
example = ''
|
example = ''
|
||||||
set nocompatible
|
|
||||||
set nobackup
|
set nobackup
|
||||||
'';
|
'';
|
||||||
description = ''
|
description = ''
|
||||||
|
@ -344,23 +348,25 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
config = let
|
config = let
|
||||||
# transform all plugins into an attrset
|
defaultPlugin = {
|
||||||
pluginsNormalized = map (x:
|
type = "viml";
|
||||||
if (x ? plugin) then
|
plugin = null;
|
||||||
x
|
|
||||||
else {
|
|
||||||
type = x.type or "viml";
|
|
||||||
plugin = x;
|
|
||||||
config = "";
|
config = "";
|
||||||
optional = false;
|
optional = false;
|
||||||
}) allPlugins;
|
runtime = { };
|
||||||
|
};
|
||||||
|
|
||||||
|
# transform all plugins into a standardized attrset
|
||||||
|
pluginsNormalized =
|
||||||
|
map (x: defaultPlugin // (if (x ? plugin) then x else { plugin = x; }))
|
||||||
|
allPlugins;
|
||||||
|
|
||||||
suppressNotVimlConfig = p:
|
suppressNotVimlConfig = p:
|
||||||
if p.type != "viml" then p // { config = ""; } else p;
|
if p.type != "viml" then p // { config = ""; } else p;
|
||||||
|
|
||||||
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
||||||
inherit (cfg) extraPython3Packages withPython3 withRuby viAlias vimAlias;
|
inherit (cfg) extraPython3Packages withPython3 withRuby viAlias vimAlias;
|
||||||
withNodeJs = cfg.withNodeJs || cfg.coc.enable;
|
withNodeJs = cfg.withNodeJs || cfg.coc.enable;
|
||||||
configure = cfg.configure // moduleConfigure;
|
|
||||||
plugins = map suppressNotVimlConfig pluginsNormalized;
|
plugins = map suppressNotVimlConfig pluginsNormalized;
|
||||||
customRC = cfg.extraConfig;
|
customRC = cfg.extraConfig;
|
||||||
};
|
};
|
||||||
|
@ -384,19 +390,22 @@ in {
|
||||||
|
|
||||||
home.packages = [ cfg.finalPackage ];
|
home.packages = [ cfg.finalPackage ];
|
||||||
|
|
||||||
xdg.configFile."nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
xdg.configFile = mkMerge (
|
||||||
text = neovimConfig.neovimRcContent + (optionalString
|
# writes runtime
|
||||||
(hasAttr "lua" config.programs.neovim.generatedConfigs) ''
|
(map (x: x.runtime) pluginsNormalized) ++ [{
|
||||||
lua require('init-home-manager')
|
"nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") {
|
||||||
'');
|
text = neovimConfig.neovimRcContent + lib.optionalString
|
||||||
|
(hasAttr "lua" config.programs.neovim.generatedConfigs)
|
||||||
|
"lua require('init-home-manager')";
|
||||||
};
|
};
|
||||||
xdg.configFile."nvim/lua/init-home-manager.lua" =
|
"nvim/lua/init-home-manager.lua" =
|
||||||
mkIf (hasAttr "lua" config.programs.neovim.generatedConfigs) {
|
mkIf (hasAttr "lua" config.programs.neovim.generatedConfigs) {
|
||||||
text = config.programs.neovim.generatedConfigs.lua;
|
text = config.programs.neovim.generatedConfigs.lua;
|
||||||
};
|
};
|
||||||
xdg.configFile."nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
||||||
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
||||||
};
|
};
|
||||||
|
}]);
|
||||||
|
|
||||||
programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package
|
programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package
|
||||||
(neovimConfig // {
|
(neovimConfig // {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
{
|
{
|
||||||
neovim-plugin-config = ./plugin-config.nix;
|
neovim-plugin-config = ./plugin-config.nix;
|
||||||
neovim-coc-config = ./coc-config.nix;
|
neovim-coc-config = ./coc-config.nix;
|
||||||
|
neovim-runtime = ./runtime.nix;
|
||||||
|
|
||||||
# waiting for a nixpkgs patch
|
# waiting for a nixpkgs patch
|
||||||
# neovim-no-init = ./no-init.nix;
|
neovim-no-init = ./no-init.nix;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ with lib;
|
||||||
config = {
|
config = {
|
||||||
programs.neovim = {
|
programs.neovim = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.neovim-unwrapped;
|
|
||||||
vimAlias = true;
|
vimAlias = true;
|
||||||
withNodeJs = false;
|
withNodeJs = false;
|
||||||
withPython3 = true;
|
withPython3 = true;
|
||||||
|
|
|
@ -7,14 +7,14 @@ with lib;
|
||||||
programs.neovim = {
|
programs.neovim = {
|
||||||
enable = true;
|
enable = true;
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
" This should be present in vimrc
|
" This 'extraConfig' should be present in vimrc
|
||||||
'';
|
'';
|
||||||
plugins = with pkgs.vimPlugins; [
|
plugins = with pkgs.vimPlugins; [
|
||||||
vim-nix
|
vim-nix
|
||||||
{
|
{
|
||||||
plugin = vim-commentary;
|
plugin = vim-commentary;
|
||||||
config = ''
|
config = ''
|
||||||
" This should be present too
|
" plugin-specific config
|
||||||
autocmd FileType c setlocal commentstring=//\ %s
|
autocmd FileType c setlocal commentstring=//\ %s
|
||||||
autocmd FileType c setlocal comments=://
|
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 commentstring=//\ %s
|
||||||
autocmd FileType c setlocal comments=://
|
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