2017-08-28 14:33:22 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.vim;
|
2020-03-30 19:54:31 +00:00
|
|
|
defaultPlugins = [ pkgs.vimPlugins.vim-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 {
|
2020-02-01 23:39:17 +00:00
|
|
|
options = let
|
|
|
|
opt = name: type:
|
|
|
|
mkOption {
|
2017-09-20 22:15:08 +00:00
|
|
|
type = types.nullOr type;
|
|
|
|
default = null;
|
|
|
|
visible = false;
|
|
|
|
};
|
2020-02-01 23:39:17 +00:00
|
|
|
in mapAttrs opt knownSettings;
|
2017-09-20 22:15:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
setExpr = name: value:
|
|
|
|
let
|
2020-02-01 23:39:17 +00:00
|
|
|
v = if isBool value then
|
|
|
|
(if value then "" else "no") + name
|
|
|
|
else
|
|
|
|
"${name}=${
|
|
|
|
if isList value then concatStringsSep "," value else toString value
|
|
|
|
}";
|
|
|
|
in optionalString (value != null) ("set " + v);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
in {
|
2017-08-28 14:33:22 +00:00
|
|
|
options = {
|
|
|
|
programs.vim = {
|
2023-07-01 23:45:18 +00:00
|
|
|
enable = mkEnableOption "Vim";
|
2017-08-28 14:33:22 +00:00
|
|
|
|
|
|
|
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;
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression "[ pkgs.vimPlugins.YankRing ]";
|
2023-07-01 23:45:18 +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:
|
2023-06-30 23:30:13 +00:00
|
|
|
{command}`nix-env -f '<nixpkgs>' -qaP -A vimPlugins`.
|
2019-08-18 14:36:46 +00:00
|
|
|
|
|
|
|
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;
|
2020-02-01 23:39:17 +00:00
|
|
|
default = { };
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''
|
2017-09-20 22:15:08 +00:00
|
|
|
{
|
|
|
|
expandtab = true;
|
|
|
|
history = 1000;
|
|
|
|
background = "dark";
|
|
|
|
}
|
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2017-09-20 22:15:08 +00:00
|
|
|
At attribute set of Vim settings. The attribute names and
|
|
|
|
corresponding values must be among the following supported
|
|
|
|
options.
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
${concatStringsSep "\n" (mapAttrsToList (n: v: ''
|
2023-07-01 06:14:03 +00:00
|
|
|
{var}`${n}`
|
|
|
|
: ${v.description}
|
2020-02-01 23:39:17 +00:00
|
|
|
'') knownSettings)}
|
2017-09-20 22:15:08 +00:00
|
|
|
|
|
|
|
See the Vim documentation for detailed descriptions of these
|
2023-07-01 06:14:03 +00:00
|
|
|
options. Use [](#opt-programs.vim.extraConfig) to manually
|
|
|
|
set any options not listed above.
|
2017-09-20 22:15:08 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-08-28 14:33:22 +00:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set nocompatible
|
|
|
|
set nobackup
|
|
|
|
'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Custom .vimrc lines";
|
2017-08-28 14:33:22 +00:00
|
|
|
};
|
2017-09-17 15:27:26 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Resulting customized vim package";
|
2017-09-17 15:27:26 +00:00
|
|
|
readOnly = true;
|
|
|
|
};
|
2021-10-06 13:56:06 +00:00
|
|
|
|
|
|
|
packageConfigurable = mkOption {
|
|
|
|
type = types.package;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = "Vim package to customize";
|
2022-12-29 21:36:05 +00:00
|
|
|
default = pkgs.vim-full or pkgs.vim_configurable;
|
|
|
|
defaultText = literalExpression "pkgs.vim-full";
|
|
|
|
example = literalExpression "pkgs.vim";
|
|
|
|
};
|
|
|
|
|
|
|
|
defaultEditor = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2023-06-30 23:30:13 +00:00
|
|
|
Whether to configure {command}`vim` as the default
|
|
|
|
editor using the {env}`EDITOR` environment variable.
|
2022-12-29 21:36:05 +00:00
|
|
|
'';
|
2021-10-06 13:56:06 +00:00
|
|
|
};
|
2017-08-28 14:33:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
config = (let
|
|
|
|
customRC = ''
|
2021-12-27 08:03:18 +00:00
|
|
|
${concatStringsSep "\n" (remove "" (mapAttrsToList setExpr
|
2020-02-01 23:39:17 +00:00
|
|
|
(builtins.intersectAttrs knownSettings cfg.settings)))}
|
2017-08-28 14:33:22 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2017-08-28 14:33:22 +00:00
|
|
|
|
2021-10-06 13:56:06 +00:00
|
|
|
vim = cfg.packageConfigurable.customize {
|
2020-02-01 23:39:17 +00:00
|
|
|
name = "vim";
|
|
|
|
vimrcConfig = {
|
|
|
|
inherit customRC;
|
2017-08-28 14:33:22 +00:00
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
packages.home-manager.start = plugins;
|
2019-08-18 14:36:46 +00:00
|
|
|
};
|
2020-02-01 23:39:17 +00:00
|
|
|
};
|
|
|
|
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 ];
|
|
|
|
|
2022-12-29 21:36:05 +00:00
|
|
|
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "vim"; };
|
|
|
|
|
2020-02-01 23:39:17 +00:00
|
|
|
programs.vim = {
|
|
|
|
package = vim;
|
|
|
|
plugins = defaultPlugins;
|
|
|
|
};
|
|
|
|
});
|
2017-08-28 14:33:22 +00:00
|
|
|
}
|