1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-30 15:09:46 +01:00
home-manager/modules/programs/vim.nix

151 lines
3.7 KiB
Nix
Raw Normal View History

2017-08-28 16:33:22 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.vim;
defaultPlugins = [ "sensible" ];
knownSettings = {
background = types.enum [ "dark" "light" ];
2018-10-15 12:47:13 +02:00
backupdir = types.listOf types.str;
copyindent = types.bool;
2018-10-15 12:47:13 +02:00
directory = types.listOf types.str;
expandtab = types.bool;
hidden = types.bool;
history = types.int;
ignorecase = types.bool;
modeline = types.bool;
2018-10-15 12:47:13 +02:00
mouse = types.enum [ "n" "v" "i" "c" "h" "a" "r" ];
mousefocus = types.bool;
mousehide = types.bool;
mousemodel = types.enum [ "extend" "popup" "popup_setpos" ];
number = types.bool;
relativenumber = types.bool;
shiftwidth = types.int;
smartcase = types.bool;
tabstop = types.int;
2018-10-15 12:47:13 +02:00
undodir = types.listOf types.str;
undofile = types.bool;
};
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 12:47:13 +02:00
else
"${name}=${
if isList value
then concatStringsSep "," value
else toString value
}";
in
optionalString (value != null) ("set " + v);
2017-08-28 16:33:22 +02:00
in
{
options = {
programs.vim = {
enable = mkEnableOption "Vim";
plugins = mkOption {
type = types.listOf types.str;
default = defaultPlugins;
example = [ "YankRing" ];
description = ''
List of vim plugins to install. To get a list of supported plugins run:
<command>nix-env -f '&lt;nixpkgs&gt;' -qaP -A vimPlugins</command>.
2017-08-28 16:33:22 +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";
};
package = mkOption {
type = types.package;
description = "Resulting customized vim package";
readOnly = true;
};
2017-08-28 16:33:22 +02:00
};
};
config = (
let
customRC = ''
${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; }
];
};
2018-10-20 10:54:44 +02:00
in mkIf cfg.enable {
programs.vim.package = vim;
home.packages = [ cfg.package ];
}
2017-08-28 16:33:22 +02:00
);
}