2017-11-02 17:34:42 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.neovim;
|
|
|
|
|
2018-09-08 15:10:32 +00:00
|
|
|
extraPythonPackageType = mkOptionType {
|
|
|
|
name = "extra-python-packages";
|
|
|
|
description = "python packages in python.withPackages format";
|
2020-10-12 20:50:49 +00:00
|
|
|
check = with types;
|
|
|
|
(x: if isFunction x then isList (x pkgs.pythonPackages) else false);
|
2018-09-08 15:10:32 +00:00
|
|
|
merge = mergeOneOption;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2020-09-25 00:08:39 +00:00
|
|
|
pluginWithConfigType = types.submodule {
|
|
|
|
options = {
|
|
|
|
plugin = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "vim plugin";
|
|
|
|
};
|
|
|
|
config = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
description = "vimscript for this plugin to be placed in init.vim";
|
|
|
|
default = "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# A function to get the configuration string (if any) from an element of 'plugins'
|
|
|
|
pluginConfig = p:
|
|
|
|
if builtins.hasAttr "plugin" p && builtins.hasAttr "config" p then ''
|
|
|
|
" ${p.plugin.pname} {{{
|
|
|
|
${p.config}
|
|
|
|
" }}}
|
2020-10-12 20:50:49 +00:00
|
|
|
'' else
|
|
|
|
"";
|
|
|
|
|
|
|
|
moduleConfigure = optionalAttrs (cfg.extraConfig != ""
|
|
|
|
|| (lib.filter (hasAttr "config") cfg.plugins) != [ ]) {
|
|
|
|
customRC = cfg.extraConfig
|
|
|
|
+ pkgs.lib.concatMapStrings pluginConfig cfg.plugins;
|
|
|
|
} // optionalAttrs (cfg.plugins != [ ]) {
|
2020-09-25 00:08:39 +00:00
|
|
|
packages.home-manager.start = map (x: x.plugin or x) cfg.plugins;
|
2019-08-18 13:20:17 +00:00
|
|
|
};
|
2020-10-12 20:50:49 +00:00
|
|
|
extraMakeWrapperArgs = lib.optionalString (cfg.extraPackages != [ ])
|
|
|
|
''--prefix PATH : "${lib.makeBinPath cfg.extraPackages}"'';
|
2017-11-02 17:34:42 +00:00
|
|
|
|
2020-10-12 20:50:49 +00:00
|
|
|
in {
|
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
|
|
|
withPython = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Enable Python 2 provider. Set to <literal>true</literal> to
|
|
|
|
use Python 2 plugins.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraPythonPackages = mkOption {
|
2018-09-08 15:10:32 +00:00
|
|
|
type = with types; either extraPythonPackageType (listOf package);
|
2020-10-12 20:50:49 +00:00
|
|
|
default = (_: [ ]);
|
2018-09-08 15:10:32 +00:00
|
|
|
defaultText = "ps: []";
|
|
|
|
example = literalExample "(ps: with ps; [ pandas jedi ])";
|
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 2 packages required for your plugins to work.
|
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 = (_: [ ]);
|
2018-09-08 15:10:32 +00:00
|
|
|
defaultText = "ps: []";
|
|
|
|
example = literalExample "(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
|
|
|
|
2019-02-04 05:57:26 +00:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.neovim-unwrapped;
|
2019-08-27 22:12:28 +00:00
|
|
|
defaultText = literalExample "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.";
|
|
|
|
};
|
|
|
|
|
2018-01-31 08:14:01 +00:00
|
|
|
configure = mkOption {
|
2018-09-08 15:10:32 +00:00
|
|
|
type = types.attrs;
|
2020-10-12 20:50:49 +00:00
|
|
|
default = { };
|
2018-01-31 08:14:01 +00:00
|
|
|
example = literalExample ''
|
|
|
|
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 = ''
|
2018-09-08 15:10:32 +00:00
|
|
|
Generate your init file from your list of plugins and custom commands,
|
2018-01-31 08:14:01 +00:00
|
|
|
and loads it from the store via <command>nvim -u /nix/store/hash-vimrc</command>
|
2019-08-18 13:20:17 +00:00
|
|
|
|
|
|
|
</para><para>
|
|
|
|
|
2020-01-04 06:26:19 +00:00
|
|
|
This option is mutually exclusive with <varname>extraConfig</varname>
|
|
|
|
and <varname>plugins</varname>.
|
2019-08-18 13:20:17 +00: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 14:15:42 +00:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = with types; listOf package;
|
|
|
|
default = [ ];
|
|
|
|
example = "[ pkgs.shfmt ]";
|
|
|
|
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 = [ ];
|
2020-09-25 00:08:39 +00:00
|
|
|
example = literalExample ''
|
|
|
|
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
|
|
|
'';
|
|
|
|
};
|
2017-11-02 17:34:42 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2020-10-12 20:50:49 +00:00
|
|
|
assertions = [{
|
|
|
|
assertion = cfg.configure == { } || moduleConfigure == { };
|
|
|
|
message = "The programs.neovim option configure is mutually exclusive"
|
|
|
|
+ " with extraConfig and plugins.";
|
|
|
|
}];
|
2019-08-18 13:20:17 +00:00
|
|
|
|
2019-08-10 11:55:05 +00:00
|
|
|
home.packages = [ cfg.finalPackage ];
|
|
|
|
|
|
|
|
programs.neovim.finalPackage = pkgs.wrapNeovim cfg.package {
|
|
|
|
inherit (cfg)
|
2020-10-12 20:50:49 +00:00
|
|
|
extraPython3Packages withPython3 extraPythonPackages withPython
|
2019-08-18 13:20:17 +00:00
|
|
|
withNodeJs withRuby viAlias vimAlias;
|
|
|
|
|
2020-10-10 14:15:42 +00:00
|
|
|
extraMakeWrapperArgs = extraMakeWrapperArgs;
|
2019-08-18 13:20:17 +00:00
|
|
|
configure = cfg.configure // moduleConfigure;
|
2019-08-10 11:55:05 +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
|
|
|
};
|
|
|
|
}
|