2017-11-02 18:34:42 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.neovim;
|
|
|
|
|
2021-07-26 04:40:07 +02:00
|
|
|
jsonFormat = pkgs.formats.json { };
|
|
|
|
|
2018-09-08 17:10:32 +02:00
|
|
|
extraPython3PackageType = mkOptionType {
|
|
|
|
name = "extra-python3-packages";
|
|
|
|
description = "python3 packages in python.withPackages format";
|
2020-10-12 22:50:49 +02:00
|
|
|
check = with types;
|
|
|
|
(x: if isFunction x then isList (x pkgs.python3Packages) else false);
|
2018-09-08 17:10:32 +02:00
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
2020-09-25 02:08:39 +02:00
|
|
|
pluginWithConfigType = types.submodule {
|
|
|
|
options = {
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "vimscript for this plugin to be placed in init.vim";
|
|
|
|
default = "";
|
|
|
|
};
|
2020-12-10 22:30:16 +01:00
|
|
|
|
|
|
|
optional = mkEnableOption "optional" // {
|
|
|
|
description = "Don't load by default (load with :packadd)";
|
|
|
|
};
|
|
|
|
|
|
|
|
plugin = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "vim plugin";
|
|
|
|
};
|
2020-09-25 02:08:39 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# A function to get the configuration string (if any) from an element of 'plugins'
|
|
|
|
pluginConfig = p:
|
2021-02-06 20:43:17 +01:00
|
|
|
if p ? plugin && (p.config or "") != "" then ''
|
2021-03-17 01:09:16 +01:00
|
|
|
" ${p.plugin.pname or p.plugin.name} {{{
|
2020-09-25 02:08:39 +02:00
|
|
|
${p.config}
|
|
|
|
" }}}
|
2020-10-12 22:50:49 +02:00
|
|
|
'' else
|
|
|
|
"";
|
|
|
|
|
2021-02-06 20:43:17 +01:00
|
|
|
moduleConfigure = {
|
|
|
|
packages.home-manager = {
|
|
|
|
start = filter (f: f != null) (map
|
|
|
|
(x: if x ? plugin && x.optional == true then null else (x.plugin or x))
|
|
|
|
cfg.plugins);
|
|
|
|
opt = filter (f: f != null)
|
|
|
|
(map (x: if x ? plugin && x.optional == true then x.plugin else null)
|
2020-12-10 22:30:16 +01:00
|
|
|
cfg.plugins);
|
2019-08-18 15:20:17 +02:00
|
|
|
};
|
2021-06-03 21:37:53 +02:00
|
|
|
beforePlugins = "";
|
2021-02-06 20:43:17 +01:00
|
|
|
};
|
|
|
|
|
2020-10-12 22:50:49 +02:00
|
|
|
extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ])
|
2021-02-06 20:43:17 +01:00
|
|
|
''--suffix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
2017-11-02 18:34:42 +01:00
|
|
|
|
2020-10-12 22:50:49 +02:00
|
|
|
in {
|
2021-05-04 05:47:08 +02:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "neovim" "withPython" ]
|
|
|
|
"Python2 support has been removed from neovim.")
|
|
|
|
(mkRemovedOptionModule [ "programs" "neovim" "extraPythonPackages" ]
|
|
|
|
"Python2 support has been removed from neovim.")
|
|
|
|
];
|
|
|
|
|
2017-11-02 18:34:42 +01:00
|
|
|
options = {
|
|
|
|
programs.neovim = {
|
|
|
|
enable = mkEnableOption "Neovim";
|
|
|
|
|
2018-08-18 04:50:49 +02:00
|
|
|
viAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2020-04-09 19:27:57 +02:00
|
|
|
Symlink <command>vi</command> to <command>nvim</command> binary.
|
2018-08-18 04:50:49 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vimAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2020-04-09 19:27:57 +02:00
|
|
|
Symlink <command>vim</command> to <command>nvim</command> binary.
|
2018-08-18 04:50:49 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-02-27 01:52:04 +01:00
|
|
|
vimdiffAlias = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
2020-04-09 19:27:57 +02:00
|
|
|
Alias <command>vimdiff</command> to <command>nvim -d</command>.
|
2020-02-27 01:52:04 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-11-27 12:21:37 +01:00
|
|
|
withNodeJs = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Enable node provider. Set to <literal>true</literal> to
|
|
|
|
use Node plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-11-02 18:34:42 +01: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 17:10:32 +02:00
|
|
|
type = with types; either extraPython3PackageType (listOf package);
|
2020-10-12 22:50:49 +02:00
|
|
|
default = (_: [ ]);
|
2018-09-08 17:10:32 +02:00
|
|
|
defaultText = "ps: []";
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression "(ps: with ps; [ python-language-server ])";
|
2017-11-02 18:34:42 +01:00
|
|
|
description = ''
|
2018-11-27 12:21:37 +01:00
|
|
|
A function in python.withPackages format, which returns a
|
2018-09-08 17:10:32 +02:00
|
|
|
list of Python 3 packages required for your plugins to work.
|
2017-11-02 18:34:42 +01:00
|
|
|
'';
|
|
|
|
};
|
2018-01-31 09:14:01 +01:00
|
|
|
|
2021-07-27 15:59:50 +02:00
|
|
|
generatedConfigViml = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
visible = true;
|
|
|
|
readOnly = true;
|
|
|
|
description = ''
|
|
|
|
Generated vimscript config.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-02-04 06:57:26 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.neovim-unwrapped;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.neovim-unwrapped";
|
2019-02-04 06:57:26 +01:00
|
|
|
description = "The package to use for the neovim binary.";
|
|
|
|
};
|
|
|
|
|
2019-08-10 13:55:05 +02:00
|
|
|
finalPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
visible = false;
|
|
|
|
readOnly = true;
|
|
|
|
description = "Resulting customized neovim package.";
|
|
|
|
};
|
|
|
|
|
2018-01-31 09:14:01 +01:00
|
|
|
configure = mkOption {
|
2020-11-30 03:54:55 +01:00
|
|
|
type = types.attrsOf types.anything;
|
2020-10-12 22:50:49 +02:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2018-01-31 09:14:01 +01:00
|
|
|
configure = {
|
|
|
|
customRC = $''''
|
|
|
|
" here your custom configuration goes!
|
|
|
|
$'''';
|
|
|
|
packages.myVimPackage = with pkgs.vimPlugins; {
|
|
|
|
# loaded on launch
|
|
|
|
start = [ fugitive ];
|
|
|
|
# manually loadable by calling `:packadd $plugin-name`
|
|
|
|
opt = [ ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
description = ''
|
2021-02-19 09:52:46 +01:00
|
|
|
Deprecated. Please use the other options.
|
|
|
|
|
2018-09-08 17:10:32 +02:00
|
|
|
Generate your init file from your list of plugins and custom commands,
|
2018-01-31 09:14:01 +01:00
|
|
|
and loads it from the store via <command>nvim -u /nix/store/hash-vimrc</command>
|
2019-08-18 15:20:17 +02:00
|
|
|
|
|
|
|
</para><para>
|
|
|
|
|
2020-01-04 07:26:19 +01:00
|
|
|
This option is mutually exclusive with <varname>extraConfig</varname>
|
|
|
|
and <varname>plugins</varname>.
|
2019-08-18 15:20:17 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set nocompatible
|
|
|
|
set nobackup
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Custom vimrc lines.
|
|
|
|
|
|
|
|
</para><para>
|
|
|
|
|
|
|
|
This option is mutually exclusive with <varname>configure</varname>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2020-10-10 16:15:42 +02:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
default = [ ];
|
|
|
|
example = "[ pkgs.shfmt ]";
|
|
|
|
description = "Extra packages available to nvim.";
|
|
|
|
};
|
|
|
|
|
2019-08-18 15:20:17 +02:00
|
|
|
plugins = mkOption {
|
2020-09-25 02:08:39 +02:00
|
|
|
type = with types; listOf (either package pluginWithConfigType);
|
2019-08-18 15:20:17 +02:00
|
|
|
default = [ ];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2020-09-25 02:08:39 +02:00
|
|
|
with pkgs.vimPlugins; [
|
|
|
|
yankring
|
|
|
|
vim-nix
|
|
|
|
{ plugin = vim-startify;
|
|
|
|
config = "let g:startify_change_to_vcs_root = 0";
|
|
|
|
}
|
|
|
|
]
|
|
|
|
'';
|
2019-08-18 15:20:17 +02:00
|
|
|
description = ''
|
2020-09-25 02:08:39 +02:00
|
|
|
List of vim plugins to install optionally associated with
|
|
|
|
configuration to be placed in init.vim.
|
2019-08-18 15:20:17 +02:00
|
|
|
|
|
|
|
</para><para>
|
|
|
|
|
|
|
|
This option is mutually exclusive with <varname>configure</varname>.
|
2018-01-31 09:14:01 +01:00
|
|
|
'';
|
|
|
|
};
|
2021-07-26 04:40:07 +02:00
|
|
|
|
|
|
|
coc = {
|
|
|
|
enable = mkEnableOption "Coc";
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = jsonFormat.type;
|
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2021-07-26 04:40:07 +02: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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2017-11-02 18:34:42 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-12-29 20:26:02 +01:00
|
|
|
config = let
|
|
|
|
neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
|
|
|
|
inherit (cfg)
|
2021-05-04 05:47:08 +02:00
|
|
|
extraPython3Packages withPython3 withNodeJs withRuby viAlias vimAlias;
|
2020-12-29 20:26:02 +01:00
|
|
|
configure = cfg.configure // moduleConfigure;
|
2021-07-26 04:40:07 +02:00
|
|
|
plugins = cfg.plugins
|
|
|
|
++ optionals cfg.coc.enable [ pkgs.vimPlugins.coc-nvim ];
|
2021-05-27 22:05:20 +02:00
|
|
|
customRC = cfg.extraConfig;
|
2020-12-29 20:26:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
in mkIf cfg.enable {
|
2021-02-19 09:52:46 +01:00
|
|
|
warnings = optional (cfg.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
|
|
|
|
'';
|
2019-08-18 15:20:17 +02:00
|
|
|
|
2021-07-27 15:59:50 +02:00
|
|
|
programs.neovim.generatedConfigViml = neovimConfig.neovimRcContent;
|
|
|
|
|
2019-08-10 13:55:05 +02:00
|
|
|
home.packages = [ cfg.finalPackage ];
|
|
|
|
|
2021-07-26 04:40:07 +02:00
|
|
|
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;
|
2021-06-03 21:37:53 +02:00
|
|
|
};
|
2021-07-26 04:40:07 +02:00
|
|
|
|
2020-12-29 20:26:02 +01:00
|
|
|
programs.neovim.finalPackage = pkgs.wrapNeovimUnstable cfg.package
|
|
|
|
(neovimConfig // {
|
|
|
|
wrapperArgs = (lib.escapeShellArgs neovimConfig.wrapperArgs) + " "
|
|
|
|
+ extraMakeWrapperArgs;
|
2021-06-03 21:37:53 +02:00
|
|
|
wrapRc = false;
|
2020-12-29 20:26:02 +01:00
|
|
|
});
|
2020-02-27 01:52:04 +01:00
|
|
|
|
|
|
|
programs.bash.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };
|
|
|
|
programs.fish.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };
|
2020-10-12 22:50:49 +02:00
|
|
|
programs.zsh.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };
|
2017-11-02 18:34:42 +01:00
|
|
|
};
|
|
|
|
}
|