diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix
index ced4a39a..50f30d92 100644
--- a/modules/programs/neovim.nix
+++ b/modules/programs/neovim.nix
@@ -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 "xdg.configHome/nvim" "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 ,
''';
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 // {
diff --git a/tests/modules/programs/neovim/default.nix b/tests/modules/programs/neovim/default.nix
index 8a6c316e..3950dc8b 100644
--- a/tests/modules/programs/neovim/default.nix
+++ b/tests/modules/programs/neovim/default.nix
@@ -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;
}
diff --git a/tests/modules/programs/neovim/no-init.nix b/tests/modules/programs/neovim/no-init.nix
index 1156529d..3ec9b067 100644
--- a/tests/modules/programs/neovim/no-init.nix
+++ b/tests/modules/programs/neovim/no-init.nix
@@ -6,7 +6,6 @@ with lib;
config = {
programs.neovim = {
enable = true;
- package = pkgs.neovim-unwrapped;
vimAlias = true;
withNodeJs = false;
withPython3 = true;
diff --git a/tests/modules/programs/neovim/plugin-config.nix b/tests/modules/programs/neovim/plugin-config.nix
index 5c26abe8..9647fb5a 100644
--- a/tests/modules/programs/neovim/plugin-config.nix
+++ b/tests/modules/programs/neovim/plugin-config.nix
@@ -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=://
'';
diff --git a/tests/modules/programs/neovim/plugin-config.vim b/tests/modules/programs/neovim/plugin-config.vim
index ee45a863..8b5f3546 100644
--- a/tests/modules/programs/neovim/plugin-config.vim
+++ b/tests/modules/programs/neovim/plugin-config.vim
@@ -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
diff --git a/tests/modules/programs/neovim/runtime.nix b/tests/modules/programs/neovim/runtime.nix
new file mode 100644
index 00000000..839b2790
--- /dev/null
+++ b/tests/modules/programs/neovim/runtime.nix
@@ -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"
+ '';
+ };
+}
+