2017-08-28 14:33:22 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.vim;
|
2019-08-18 14:36:46 +00:00
|
|
|
defaultPlugins = [ pkgs.vimPlugins.sensible ];
|
2017-08-28 14:33:22 +00:00
|
|
|
|
2017-09-20 22:15:08 +00:00
|
|
|
knownSettings = {
|
|
|
|
background = types.enum [ "dark" "light" ];
|
2018-10-15 10:47:13 +00:00
|
|
|
backupdir = types.listOf types.str;
|
2017-10-09 12:39:56 +00:00
|
|
|
copyindent = types.bool;
|
2018-10-15 10:47:13 +00:00
|
|
|
directory = types.listOf types.str;
|
2017-09-20 22:15:08 +00:00
|
|
|
expandtab = types.bool;
|
2017-10-09 12:39:56 +00:00
|
|
|
hidden = types.bool;
|
2017-09-20 22:15:08 +00:00
|
|
|
history = types.int;
|
2017-10-09 12:39:56 +00:00
|
|
|
ignorecase = types.bool;
|
|
|
|
modeline = types.bool;
|
2018-10-15 10:47:13 +00:00
|
|
|
mouse = types.enum [ "n" "v" "i" "c" "h" "a" "r" ];
|
|
|
|
mousefocus = types.bool;
|
|
|
|
mousehide = types.bool;
|
|
|
|
mousemodel = types.enum [ "extend" "popup" "popup_setpos" ];
|
2017-09-20 22:15:08 +00:00
|
|
|
number = types.bool;
|
|
|
|
relativenumber = types.bool;
|
|
|
|
shiftwidth = types.int;
|
2017-10-09 12:39:56 +00:00
|
|
|
smartcase = types.bool;
|
2017-09-20 22:15:08 +00:00
|
|
|
tabstop = types.int;
|
2018-10-15 10:47:13 +00:00
|
|
|
undodir = types.listOf types.str;
|
|
|
|
undofile = types.bool;
|
2017-09-20 22:15:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
vimSettingsType = types.submodule {
|
|
|
|
options =
|
|
|
|
let
|
|
|
|
opt = name: type: mkOption {
|
|
|
|
type = types.nullOr type;
|
|
|
|
default = null;
|
|
|
|
visible = false;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
mapAttrs opt knownSettings;
|
|
|
|
};
|
|
|
|
|
|
|
|
setExpr = name: value:
|
|
|
|
let
|
|
|
|
v =
|
|
|
|
if isBool value then (if value then "" else "no") + name
|
2018-10-15 10:47:13 +00:00
|
|
|
else
|
|
|
|
"${name}=${
|
|
|
|
if isList value
|
|
|
|
then concatStringsSep "," value
|
|
|
|
else toString value
|
|
|
|
}";
|
2017-09-20 22:15:08 +00:00
|
|
|
in
|
|
|
|
optionalString (value != null) ("set " + v);
|
|
|
|
|
2019-08-18 14:36:46 +00:00
|
|
|
plugins =
|
|
|
|
let
|
|
|
|
vpkgs = pkgs.vimPlugins;
|
|
|
|
getPkg = p:
|
|
|
|
if isDerivation p
|
|
|
|
then [ p ]
|
|
|
|
else optional (isString p && hasAttr p vpkgs) vpkgs.${p};
|
|
|
|
in
|
|
|
|
concatMap getPkg cfg.plugins;
|
|
|
|
|
2017-08-28 14:33:22 +00:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.vim = {
|
|
|
|
enable = mkEnableOption "Vim";
|
|
|
|
|
|
|
|
plugins = mkOption {
|
2019-08-18 14:36:46 +00:00
|
|
|
type = with types; listOf (either str package);
|
2017-08-28 14:33:22 +00:00
|
|
|
default = defaultPlugins;
|
2019-08-18 14:36:46 +00:00
|
|
|
example = literalExample ''[ pkgs.vimPlugins.YankRing ]'';
|
2017-08-28 14:33:22 +00:00
|
|
|
description = ''
|
2018-09-15 08:58:13 +00:00
|
|
|
List of vim plugins to install. To get a list of supported plugins run:
|
|
|
|
<command>nix-env -f '<nixpkgs>' -qaP -A vimPlugins</command>.
|
2019-08-18 14:36:46 +00:00
|
|
|
|
|
|
|
</para><para>
|
|
|
|
|
|
|
|
Note: String values are deprecated, please use actual packages.
|
2017-08-28 14:33:22 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-20 22:15:08 +00:00
|
|
|
settings = mkOption {
|
|
|
|
type = vimSettingsType;
|
|
|
|
default = {};
|
|
|
|
example = literalExample ''
|
|
|
|
{
|
|
|
|
expandtab = true;
|
|
|
|
history = 1000;
|
|
|
|
background = "dark";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
At attribute set of Vim settings. The attribute names and
|
|
|
|
corresponding values must be among the following supported
|
|
|
|
options.
|
|
|
|
|
|
|
|
<informaltable frame="none"><tgroup cols="1"><tbody>
|
|
|
|
${concatStringsSep "\n" (
|
|
|
|
mapAttrsToList (n: v: ''
|
|
|
|
<row>
|
|
|
|
<entry><varname>${n}</varname></entry>
|
|
|
|
<entry>${v.description}</entry>
|
|
|
|
</row>
|
|
|
|
'') knownSettings
|
|
|
|
)}
|
|
|
|
</tbody></tgroup></informaltable>
|
|
|
|
|
|
|
|
See the Vim documentation for detailed descriptions of these
|
|
|
|
options. Note, use <varname>extraConfig</varname> to
|
|
|
|
manually set any options not listed above.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-08-28 14:33:22 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set nocompatible
|
|
|
|
set nobackup
|
|
|
|
'';
|
|
|
|
description = "Custom .vimrc lines";
|
|
|
|
};
|
2017-09-17 15:27:26 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "Resulting customized vim package";
|
|
|
|
readOnly = true;
|
|
|
|
};
|
2017-08-28 14:33:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = (
|
|
|
|
let
|
|
|
|
customRC = ''
|
2017-09-20 22:15:08 +00:00
|
|
|
${concatStringsSep "\n" (
|
|
|
|
filter (v: v != "") (
|
|
|
|
mapAttrsToList setExpr (
|
|
|
|
builtins.intersectAttrs knownSettings cfg.settings)))}
|
2017-08-28 14:33:22 +00:00
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
vim = pkgs.vim_configurable.customize {
|
|
|
|
name = "vim";
|
2019-08-18 14:36:46 +00:00
|
|
|
vimrcConfig = {
|
|
|
|
inherit customRC;
|
2017-08-28 14:33:22 +00:00
|
|
|
|
2019-08-18 14:36:46 +00:00
|
|
|
packages.home-manager.start = plugins;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
mkIf cfg.enable {
|
|
|
|
assertions =
|
|
|
|
let
|
|
|
|
packagesNotFound = filter (p: isString p && (!hasAttr p pkgs.vimPlugins)) cfg.plugins;
|
|
|
|
in
|
|
|
|
[
|
|
|
|
{
|
|
|
|
assertion = packagesNotFound == [];
|
|
|
|
message = "Following VIM plugin not found in pkgs.vimPlugins: ${
|
|
|
|
concatMapStringsSep ", " (p: ''"${p}"'') packagesNotFound
|
|
|
|
}";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
warnings =
|
|
|
|
let
|
|
|
|
stringPlugins = filter isString cfg.plugins;
|
|
|
|
in
|
|
|
|
optional (stringPlugins != []) ''
|
|
|
|
Specifying VIM plugins using strings is deprecated, found ${
|
|
|
|
concatMapStringsSep ", " (p: ''"${p}"'') stringPlugins
|
|
|
|
} as strings.
|
|
|
|
'';
|
|
|
|
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2019-08-29 21:18:11 +00:00
|
|
|
programs.vim = {
|
|
|
|
package = vim;
|
|
|
|
plugins = defaultPlugins;
|
|
|
|
};
|
2019-08-18 14:36:46 +00:00
|
|
|
}
|
2017-08-28 14:33:22 +00:00
|
|
|
);
|
|
|
|
}
|