2017-08-28 16:33:22 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.vim;
|
|
|
|
defaultPlugins = [ "sensible" ];
|
|
|
|
|
2017-09-21 00:15:08 +02:00
|
|
|
knownSettings = {
|
|
|
|
background = types.enum [ "dark" "light" ];
|
|
|
|
expandtab = types.bool;
|
|
|
|
history = types.int;
|
|
|
|
number = types.bool;
|
|
|
|
relativenumber = types.bool;
|
|
|
|
shiftwidth = types.int;
|
|
|
|
tabstop = types.int;
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
else name + "=" + toString value;
|
|
|
|
in
|
|
|
|
optionalString (value != null) ("set " + v);
|
|
|
|
|
2017-08-28 16:33:22 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.vim = {
|
|
|
|
enable = mkEnableOption "Vim";
|
|
|
|
|
|
|
|
lineNumbers = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
2017-09-21 00:15:08 +02:00
|
|
|
description = ''
|
|
|
|
Whether to show line numbers. DEPRECATED: Use
|
|
|
|
<varname>programs.vim.settings.number</varname>.
|
|
|
|
'';
|
2017-08-28 16:33:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
tabSize = mkOption {
|
|
|
|
type = types.nullOr types.int;
|
2017-09-21 00:15:08 +02:00
|
|
|
default = null;
|
2017-08-28 16:33:22 +02:00
|
|
|
example = 4;
|
2017-09-21 00:15:08 +02:00
|
|
|
description = ''
|
|
|
|
Set tab size and shift width to a specified number of
|
|
|
|
spaces. DEPRECATED: Use
|
|
|
|
<varname>programs.vim.settings.tabstop</varname> and
|
|
|
|
<varname>programs.vim.settings.shiftwidth</varname>.
|
|
|
|
'';
|
2017-08-28 16:33:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
plugins = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = defaultPlugins;
|
|
|
|
example = [ "YankRing" ];
|
|
|
|
description = ''
|
2017-09-30 12:10:52 +02:00
|
|
|
List of vim plugins to install. For supported plugins see:
|
|
|
|
<link xlink:href="https://github.com/NixOS/nixpkgs/blob/master/pkgs/misc/vim-plugins/vim-plugin-names"/>.
|
2017-08-28 16:33:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-21 00:15:08 +02: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 16:33:22 +02:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set nocompatible
|
|
|
|
set nobackup
|
|
|
|
'';
|
|
|
|
description = "Custom .vimrc lines";
|
|
|
|
};
|
2017-09-17 17:27:26 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
description = "Resulting customized vim package";
|
|
|
|
readOnly = true;
|
|
|
|
};
|
2017-08-28 16:33:22 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = (
|
|
|
|
let
|
|
|
|
customRC = ''
|
2017-09-21 00:15:08 +02:00
|
|
|
${concatStringsSep "\n" (
|
|
|
|
filter (v: v != "") (
|
|
|
|
mapAttrsToList setExpr (
|
|
|
|
builtins.intersectAttrs knownSettings cfg.settings)))}
|
2017-08-28 16:33:22 +02:00
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
vim = pkgs.vim_configurable.customize {
|
|
|
|
name = "vim";
|
|
|
|
vimrcConfig.customRC = customRC;
|
|
|
|
vimrcConfig.vam.knownPlugins = pkgs.vimPlugins;
|
|
|
|
vimrcConfig.vam.pluginDictionaries = [
|
|
|
|
{ names = defaultPlugins ++ cfg.plugins; }
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2017-09-21 00:15:08 +02:00
|
|
|
in mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
programs.vim.package = vim;
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
}
|
|
|
|
|
|
|
|
(mkIf (cfg.lineNumbers != null) {
|
|
|
|
warnings = [
|
|
|
|
("'programs.vim.lineNumbers' is deprecated, "
|
|
|
|
+ "use 'programs.vim.settings.number'")
|
|
|
|
];
|
|
|
|
|
|
|
|
programs.vim.settings.number = cfg.lineNumbers;
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.tabSize != null) {
|
|
|
|
warnings = [
|
|
|
|
("'programs.vim.tabSize' is deprecated, use "
|
|
|
|
+ "'programs.vim.settings.tabstop' and "
|
|
|
|
+ "'programs.vim.settings.shiftwidth'")
|
|
|
|
];
|
|
|
|
|
|
|
|
programs.vim.settings.tabstop = cfg.tabSize;
|
|
|
|
programs.vim.settings.shiftwidth = cfg.tabSize;
|
|
|
|
})
|
|
|
|
])
|
2017-08-28 16:33:22 +02:00
|
|
|
);
|
|
|
|
}
|