diff --git a/modules/misc/news.nix b/modules/misc/news.nix index ae63cd2a6f56..3179a6d235d6 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -2149,6 +2149,15 @@ in A new module is available: 'services.trayer'. ''; } + { + time = "2021-09-08T19:46:25.315Z"; + message = '' + The neovim module has a new option: 'neovim.initExtra'. + + This adds extra vimscript configuration to add to the top of the + generated configuration file. + ''; + } ]; }; } diff --git a/modules/programs/neovim.nix b/modules/programs/neovim.nix index a5ffd110d1c1..22ddc9a0cb54 100644 --- a/modules/programs/neovim.nix +++ b/modules/programs/neovim.nix @@ -53,7 +53,11 @@ let (map (x: if x ? plugin && x.optional == true then x.plugin else null) cfg.plugins); }; - beforePlugins = ""; + beforePlugins = '' + " generated by Home Manager + set nocompatible + ${cfg.initExtra} + ''; }; extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ]) @@ -79,6 +83,14 @@ in { ''; }; + initExtra = mkOption { + type = types.lines; + default = ""; + description = '' + Configuration to insert on the top of init.vim + ''; + }; + vimAlias = mkOption { type = types.bool; default = false; @@ -121,6 +133,15 @@ in { ''; }; + generatedConfigViml = mkOption { + type = types.lines; + visible = true; + readOnly = true; + description = '' + Generated vimscript config. + ''; + }; + extraPython3Packages = mkOption { type = with types; either extraPython3PackageType (listOf package); default = (_: [ ]); @@ -132,15 +153,6 @@ in { ''; }; - generatedConfigViml = mkOption { - type = types.lines; - visible = true; - readOnly = true; - description = '' - Generated vimscript config. - ''; - }; - package = mkOption { type = types.package; default = pkgs.neovim-unwrapped; @@ -289,13 +301,14 @@ in { configure.customRC -> programs.neovim.extraConfig ''; - programs.neovim.generatedConfigViml = neovimConfig.neovimRcContent; - home.packages = [ cfg.finalPackage ]; + programs.neovim.generatedConfigViml = neovimConfig.neovimRcContent; + xdg.configFile."nvim/init.vim" = mkIf (neovimConfig.neovimRcContent != "") { text = neovimConfig.neovimRcContent; }; + xdg.configFile."nvim/coc-settings.json" = mkIf cfg.coc.enable { source = jsonFormat.generate "coc-settings.json" cfg.coc.settings; }; diff --git a/tests/modules/programs/neovim/plugin-config.vim b/tests/modules/programs/neovim/plugin-config.vim index 89278a0a94c4..b69a3b681946 100644 --- a/tests/modules/programs/neovim/plugin-config.vim +++ b/tests/modules/programs/neovim/plugin-config.vim @@ -1,3 +1,7 @@ +" generated by Home Manager +set nocompatible + + set packpath^=/nix/store/00000000000000000000000000000000-vim-pack-dir set runtimepath^=/nix/store/00000000000000000000000000000000-vim-pack-dir