2017-11-02 17:34:42 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.neovim;
|
|
|
|
|
2022-08-23 20:02:05 +00:00
|
|
|
fileType = (import ../lib/file-type.nix {
|
|
|
|
inherit (config.home) homeDirectory;
|
|
|
|
inherit lib pkgs;
|
|
|
|
}).fileType;
|
|
|
|
|
2021-07-26 02:40:07 +00:00
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
2018-09-08 15:10:32 +00:00
|
|
|
extraPython3PackageType = mkOptionType {
|
|
|
|
name = "extra-python3-packages";
|
|
|
|
description = "python3 packages in python.withPackages format";
|
2020-10-12 20:50:49 +00:00
|
|
|
check = with types;
|
|
|
|
(x: if isFunction x then isList (x pkgs.python3Packages) else false);
|
2018-09-08 15:10:32 +00:00
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
2022-02-16 15:38:10 +00:00
|
|
|
# Currently, upstream Neovim is pinned on Lua 5.1 for LuaJIT support.
|
|
|
|
# This will need to be updated if Neovim ever migrates to a newer
|
|
|
|
# version of Lua.
|
|
|
|
extraLua51PackageType = mkOptionType {
|
|
|
|
name = "extra-lua51-packages";
|
|
|
|
description = "lua5.1 packages in lua5_1.withPackages format";
|
|
|
|
check = with types;
|
|
|
|
(x: if isFunction x then isList (x pkgs.lua51Packages) else false);
|
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
2020-09-25 00:08:39 +00:00
|
|
|
pluginWithConfigType = types.submodule {
|
|
|
|
options = {
|
|
|
|
config = mkOption {
|
2022-09-22 08:39:55 +00:00
|
|
|
type = types.nullOr types.lines;
|
2022-01-27 15:27:35 +00:00
|
|
|
description =
|
|
|
|
"Script to configure this plugin. The scripting language should match type.";
|
2022-09-22 08:39:55 +00:00
|
|
|
default = null;
|
2020-09-25 00:08:39 +00:00
|
|
|
};
|
2020-12-10 21:30:16 +00:00
|
|
|
|
2022-01-27 15:27:35 +00:00
|
|
|
type = mkOption {
|
|
|
|
type =
|
|
|
|
types.either (types.enum [ "lua" "viml" "teal" "fennel" ]) types.str;
|
|
|
|
description =
|
|
|
|
"Language used in config. Configurations are aggregated per-language.";
|
|
|
|
default = "viml";
|
|
|
|
};
|
|
|
|
|
2020-12-10 21:30:16 +00:00
|
|
|
optional = mkEnableOption "optional" // {
|
|
|
|
description = "Don't load by default (load with :packadd)";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugin = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "vim plugin";
|
|
|
|
};
|
2022-08-23 20:02:05 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
2020-09-25 00:08:39 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-18 02:43:03 +00:00
|
|
|
allPlugins = cfg.plugins ++ optional cfg.coc.enable {
|
|
|
|
type = "viml";
|
2022-05-21 17:12:29 +00:00
|
|
|
plugin = cfg.coc.package;
|
2022-03-18 02:43:03 +00:00
|
|
|
config = cfg.coc.pluginConfig;
|
|
|
|
optional = false;
|
|
|
|
};
|
|
|
|
|
2020-10-12 20:50:49 +00:00
|
|
|
extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ])
|
2021-02-06 19:43:17 +00:00
|
|
|
''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
2022-02-16 15:38:10 +00:00
|
|
|
extraMakeWrapperLuaCArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) ''
|
|
|
|
--suffix LUA_CPATH ";" "${
|
|
|
|
lib.concatMapStringsSep ";" pkgs.lua51Packages.getLuaCPath
|
|
|
|
cfg.extraLuaPackages
|
|
|
|
}"'';
|
|
|
|
extraMakeWrapperLuaArgs = lib.optionalString (cfg.extraLuaPackages != [ ]) ''
|
|
|
|
--suffix LUA_PATH ";" "${
|
|
|
|
lib.concatMapStringsSep ";" pkgs.lua51Packages.getLuaPath
|
|
|
|
cfg.extraLuaPackages
|
|
|
|
}"'';
|
2017-11-02 17:34:42 +00:00
|
|
|
|
2020-10-12 20:50:49 +00:00
|
|
|
in {
|
2021-05-04 03:47:08 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "neovim" "withPython" ]
|
|
|
|
"Python2 support has been removed from neovim.")
|
|
|
|
(mkRemovedOptionModule [ "programs" "neovim" "extraPythonPackages" ]
|
|
|
|
"Python2 support has been removed from neovim.")
|
2022-08-26 20:11:34 +00:00
|
|
|
(mkRemovedOptionModule [ "programs" "neovim" "configure" ] ''
|
|
|
|
programs.neovim.configure is deprecated.
|
|
|
|
Other programs.neovim options can override its settings or ignore them.
|
|
|
|
Please use the other options at your disposal:
|
|
|
|
configure.packages.*.opt -> programs.neovim.plugins = [ { plugin = ...; optional = true; }]
|
|
|
|
configure.packages.*.start -> programs.neovim.plugins = [ { plugin = ...; }]
|
|
|
|
configure.customRC -> programs.neovim.extraConfig
|
|
|
|
'')
|
2021-05-04 03:47:08 +00:00
|
|
|
];
|
|
|
|
|
2017-11-02 17:34:42 +00:00
|
|
|
options = {
|
|
|
|
programs.neovim = {
|
|
|
|
enable = mkEnableOption "Neovim";
|
|
|
|
|
2018-08-18 02:50:49 +00:00
|
|
|
viAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2020-04-09 17:27:57 +00:00
|
|
|
Symlink <command>vi</command> to <command>nvim</command> binary.
|
2018-08-18 02:50:49 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vimAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2020-04-09 17:27:57 +00:00
|
|
|
Symlink <command>vim</command> to <command>nvim</command> binary.
|
2018-08-18 02:50:49 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-02-27 00:52:04 +00:00
|
|
|
vimdiffAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2020-04-09 17:27:57 +00:00
|
|
|
Alias <command>vimdiff</command> to <command>nvim -d</command>.
|
2020-02-27 00:52:04 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-27 11:21:37 +00:00
|
|
|
withNodeJs = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable node provider. Set to <literal>true</literal> to
|
|
|
|
use Node plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-11-02 17:34:42 +00:00
|
|
|
withRuby = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enable ruby provider.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
withPython3 = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enable Python 3 provider. Set to <literal>true</literal> to
|
|
|
|
use Python 3 plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPython3Packages = mkOption {
|
2018-09-08 15:10:32 +00:00
|
|
|
type = with types; either extraPython3PackageType (listOf package);
|
2020-10-12 20:50:49 +00:00
|
|
|
default = (_: [ ]);
|
2022-06-13 17:57:41 +00:00
|
|
|
defaultText = literalExpression "ps: [ ]";
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression "(ps: with ps; [ python-language-server ])";
|
2017-11-02 17:34:42 +00:00
|
|
|
description = ''
|
2018-11-27 11:21:37 +00:00
|
|
|
A function in python.withPackages format, which returns a
|
2018-09-08 15:10:32 +00:00
|
|
|
list of Python 3 packages required for your plugins to work.
|
2017-11-02 17:34:42 +00:00
|
|
|
'';
|
|
|
|
};
|
2018-01-31 08:14:01 +00:00
|
|
|
|
2022-02-16 15:38:10 +00:00
|
|
|
extraLuaPackages = mkOption {
|
|
|
|
type = with types; either extraLua51PackageType (listOf package);
|
|
|
|
default = [ ];
|
2022-06-13 17:57:41 +00:00
|
|
|
defaultText = literalExpression "[ ]";
|
2022-02-16 15:38:10 +00:00
|
|
|
example = literalExpression "(ps: with ps; [ luautf8 ])";
|
|
|
|
description = ''
|
|
|
|
A function in lua5_1.withPackages format, which returns a
|
|
|
|
list of Lua packages required for your plugins to work.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-07-27 13:59:50 +00:00
|
|
|
generatedConfigViml = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
visible = true;
|
|
|
|
readOnly = true;
|
|
|
|
description = ''
|
|
|
|
Generated vimscript config.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2022-01-27 15:27:35 +00:00
|
|
|
generatedConfigs = mkOption {
|
|
|
|
type = types.attrsOf types.lines;
|
|
|
|
visible = true;
|
|
|
|
readOnly = true;
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
viml = '''
|
|
|
|
" Generated by home-manager
|
2022-08-23 20:02:05 +00:00
|
|
|
map <leader> ,
|
2022-01-27 15:27:35 +00:00
|
|
|
''';
|
|
|
|
|
|
|
|
lua = '''
|
|
|
|
-- Generated by home-manager
|
|
|
|
vim.opt.background = "dark"
|
|
|
|
''';
|
|
|
|
}'';
|
|
|
|
description = ''
|
|
|
|
Generated configurations with as key their language (set via type).
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-04 05:57:26 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.neovim-unwrapped;
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression "pkgs.neovim-unwrapped";
|
2019-02-04 05:57:26 +00:00
|
|
|
description = "The package to use for the neovim binary.";
|
|
|
|
};
|
|
|
|
|
2019-08-10 11:55:05 +00:00
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
visible = false;
|
|
|
|
readOnly = true;
|
|
|
|
description = "Resulting customized neovim package.";
|
|
|
|
};
|
|
|
|
|
2019-08-18 13:20:17 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set nobackup
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Custom vimrc lines.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-10-10 14:15:42 +00:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
default = [ ];
|
2022-06-13 17:57:41 +00:00
|
|
|
example = literalExpression "[ pkgs.shfmt ]";
|
2020-10-10 14:15:42 +00:00
|
|
|
description = "Extra packages available to nvim.";
|
|
|
|
};
|
|
|
|
|
2019-08-18 13:20:17 +00:00
|
|
|
plugins = mkOption {
|
2020-09-25 00:08:39 +00:00
|
|
|
type = with types; listOf (either package pluginWithConfigType);
|
2019-08-18 13:20:17 +00:00
|
|
|
default = [ ];
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2020-09-25 00:08:39 +00:00
|
|
|
with pkgs.vimPlugins; [
|
|
|
|
yankring
|
|
|
|
vim-nix
|
|
|
|
{ plugin = vim-startify;
|
|
|
|
config = "let g:startify_change_to_vcs_root = 0";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
2019-08-18 13:20:17 +00:00
|
|
|
description = ''
|
2020-09-25 00:08:39 +00:00
|
|
|
List of vim plugins to install optionally associated with
|
|
|
|
configuration to be placed in init.vim.
|
2019-08-18 13:20:17 +00:00
|
|
|
|
|
|
|
</para><para>
|
|
|
|
|
|
|
|
This option is mutually exclusive with <varname>configure</varname>.
|
2018-01-31 08:14:01 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-07-26 02:40:07 +00:00
|
|
|
|
|
|
|
coc = {
|
|
|
|
enable = mkEnableOption "Coc";
|
|
|
|
|
2022-05-21 17:12:29 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.vimPlugins.coc-nvim;
|
|
|
|
defaultText = literalExpression "pkgs.vimPlugins.coc-nvim";
|
|
|
|
description = "The package to use for the CoC plugin.";
|
|
|
|
};
|
|
|
|
|
2021-07-26 02:40:07 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = jsonFormat.type;
|
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2021-07-26 02:40:07 +00:00
|
|
|
{
|
|
|
|
"suggest.noselect" = true;
|
|
|
|
"suggest.enablePreview" = true;
|
|
|
|
"suggest.enablePreselect" = false;
|
|
|
|
"suggest.disableKind" = true;
|
|
|
|
languageserver = {
|
|
|
|
haskell = {
|
|
|
|
command = "haskell-language-server-wrapper";
|
|
|
|
args = [ "--lsp" ];
|
|
|
|
rootPatterns = [
|
|
|
|
"*.cabal"
|
|
|
|
"stack.yaml"
|
|
|
|
"cabal.project"
|
|
|
|
"package.yaml"
|
|
|
|
"hie.yaml"
|
|
|
|
];
|
|
|
|
filetypes = [ "haskell" "lhaskell" ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra configuration lines to add to
|
|
|
|
<filename>$XDG_CONFIG_HOME/nvim/coc-settings.json</filename>
|
|
|
|
See
|
|
|
|
<link xlink:href="https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file" />
|
|
|
|
for options.
|
|
|
|
'';
|
|
|
|
};
|
2022-03-18 02:43:03 +00:00
|
|
|
|
|
|
|
pluginConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
description = "Script to configure CoC. Must be viml.";
|
|
|
|
};
|
2021-07-26 02:40:07 +00:00
|
|
|
};
|
2017-11-02 17:34:42 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-12-29 19:26:02 +00:00
|
|
|
config = let
|
2022-08-23 20:02:05 +00:00
|
|
|
defaultPlugin = {
|
|
|
|
type = "viml";
|
|
|
|
plugin = null;
|
2022-09-22 08:39:55 +00:00
|
|
|
config = null;
|
2022-08-23 20:02:05 +00:00
|
|
|
optional = false;
|
|
|
|
runtime = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
# transform all plugins into a standardized attrset
|
|
|
|
pluginsNormalized =
|
|
|
|
map (x: defaultPlugin // (if (x ? plugin) then x else { plugin = x; }))
|
|
|
|
allPlugins;
|
|
|
|
|
2022-01-27 15:27:35 +00:00
|
|
|
suppressNotVimlConfig = p:
|
2022-09-22 08:39:55 +00:00
|
|
|
if p.type != "viml" then p // { config = null; } else p;
|
2022-01-27 15:27:35 +00:00
|
|
|
|
2020-12-29 19:26:02 +00:00
|
|
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
2022-03-18 02:43:03 +00:00
|
|
|
inherit (cfg) extraPython3Packages withPython3 withRuby viAlias vimAlias;
|
2022-06-22 20:14:18 +00:00
|
|
|
withNodeJs = cfg.withNodeJs || cfg.coc.enable;
|
2022-03-18 02:43:03 +00:00
|
|
|
plugins = map suppressNotVimlConfig pluginsNormalized;
|
2021-05-27 20:05:20 +00:00
|
|
|
customRC = cfg.extraConfig;
|
2020-12-29 19:26:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
in mkIf cfg.enable {
|
2019-08-18 13:20:17 +00:00
|
|
|
|
2021-07-27 13:59:50 +00:00
|
|
|
programs.neovim.generatedConfigViml = neovimConfig.neovimRcContent;
|
|
|
|
|
2022-01-27 15:27:35 +00:00
|
|
|
programs.neovim.generatedConfigs = let
|
|
|
|
grouped = lib.lists.groupBy (x: x.type) pluginsNormalized;
|
2022-02-25 13:35:13 +00:00
|
|
|
concatConfigs = lib.concatMapStrings (p: p.config);
|
2022-09-22 08:39:55 +00:00
|
|
|
configsOnly = lib.foldl
|
|
|
|
(acc: p: if p.config != null then acc ++ [ (p.config) ] else acc) [ ];
|
|
|
|
in mapAttrs (name: vals: lib.concatStringsSep "\n" (configsOnly vals))
|
|
|
|
grouped;
|
2022-01-27 15:27:35 +00:00
|
|
|
|
2019-08-10 11:55:05 +00:00
|
|
|
home.packages = [ cfg.finalPackage ];
|
|
|
|
|
2022-09-22 08:39:55 +00:00
|
|
|
xdg.configFile =
|
|
|
|
let hasLuaConfig = hasAttr "lua" config.programs.neovim.generatedConfigs;
|
|
|
|
in mkMerge (
|
|
|
|
# writes runtime
|
|
|
|
(map (x: x.runtime) pluginsNormalized) ++ [{
|
|
|
|
"nvim/init.lua" = let
|
|
|
|
luaRcContent =
|
|
|
|
lib.optionalString (neovimConfig.neovimRcContent != "")
|
neovim: Source neovimRcContent directly from store (#3444)
The previous version linked the file into home, then sourced that. Since
nothing else expects that file to be there, this is unnecessary.
Additionally, doing so made it impossible to test a built config without
switching, e.g. using `XDG_CONFIG_HOME=… nvim` or `nvim -u`. This
remedies that, at least for this particular reference.
To test this, change from asserting contents of the config file to
actually starting nvim, outputting sentinel values, and then asserting
their values are present. This way it’s tested that nvim loaded the
config, rather than that some config is in a specific place.
This is all in one commit as the test, as written now, would not have
worked before since the previously hard-coded home path was not an
actual file in the test environment.
2022-11-30 16:19:31 +00:00
|
|
|
"vim.cmd [[source ${
|
|
|
|
pkgs.writeText "nvim-init-home-manager.vim"
|
|
|
|
neovimConfig.neovimRcContent
|
|
|
|
}]]" + lib.optionalString hasLuaConfig
|
2022-09-22 08:39:55 +00:00
|
|
|
config.programs.neovim.generatedConfigs.lua;
|
|
|
|
in mkIf (luaRcContent != "") { text = luaRcContent; };
|
|
|
|
|
|
|
|
"nvim/coc-settings.json" = mkIf cfg.coc.enable {
|
|
|
|
source = jsonFormat.generate "coc-settings.json" cfg.coc.settings;
|
|
|
|
};
|
|
|
|
}]);
|
2021-07-26 02:40:07 +00:00
|
|
|
|
2020-12-29 19:26:02 +00:00
|
|
|
programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package
|
|
|
|
(neovimConfig // {
|
|
|
|
wrapperArgs = (lib.escapeShellArgs neovimConfig.wrapperArgs) + " "
|
2022-02-16 15:38:10 +00:00
|
|
|
+ extraMakeWrapperArgs + " " + extraMakeWrapperLuaCArgs + " "
|
|
|
|
+ extraMakeWrapperLuaArgs;
|
2021-06-03 19:37:53 +00:00
|
|
|
wrapRc = false;
|
2020-12-29 19:26:02 +00:00
|
|
|
});
|
2020-02-27 00:52:04 +00:00
|
|
|
|
|
|
|
programs.bash.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };
|
|
|
|
programs.fish.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };
|
2020-10-12 20:50:49 +00:00
|
|
|
programs.zsh.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };
|
2017-11-02 17:34:42 +00:00
|
|
|
};
|
|
|
|
}
|