2017-08-28 16:33:22 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.vim;
|
2020-03-30 21:54:31 +02:00
|
|
|
defaultPlugins = [ pkgs.vimPlugins.vim-sensible ];
|
2017-08-28 16:33:22 +02:00
|
|
|
|
2017-09-21 00:15:08 +02:00
|
|
|
knownSettings = {
|
|
|
|
background = types.enum [ "dark" "light" ];
|
2018-10-15 12:47:13 +02:00
|
|
|
backupdir = types.listOf types.str;
|
2017-10-09 14:39:56 +02:00
|
|
|
copyindent = types.bool;
|
2018-10-15 12:47:13 +02:00
|
|
|
directory = types.listOf types.str;
|
2017-09-21 00:15:08 +02:00
|
|
|
expandtab = types.bool;
|
2017-10-09 14:39:56 +02:00
|
|
|
hidden = types.bool;
|
2017-09-21 00:15:08 +02:00
|
|
|
history = types.int;
|
2017-10-09 14:39:56 +02:00
|
|
|
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" ];
|
2017-09-21 00:15:08 +02:00
|
|
|
number = types.bool;
|
|
|
|
relativenumber = types.bool;
|
|
|
|
shiftwidth = types.int;
|
2017-10-09 14:39:56 +02:00
|
|
|
smartcase = types.bool;
|
2017-09-21 00:15:08 +02:00
|
|
|
tabstop = types.int;
|
2018-10-15 12:47:13 +02:00
|
|
|
undodir = types.listOf types.str;
|
|
|
|
undofile = types.bool;
|
2017-09-21 00:15:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
vimSettingsType = types.submodule {
|
2020-02-02 00:39:17 +01:00
|
|
|
options = let
|
|
|
|
opt = name: type:
|
|
|
|
mkOption {
|
2017-09-21 00:15:08 +02:00
|
|
|
type = types.nullOr type;
|
|
|
|
default = null;
|
|
|
|
visible = false;
|
|
|
|
};
|
2020-02-02 00:39:17 +01:00
|
|
|
in mapAttrs opt knownSettings;
|
2017-09-21 00:15:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
setExpr = name: value:
|
|
|
|
let
|
2020-02-02 00:39:17 +01: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 16:33:22 +02:00
|
|
|
options = {
|
|
|
|
programs.vim = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "Vim";
|
2017-08-28 16:33:22 +02:00
|
|
|
|
|
|
|
plugins = mkOption {
|
2019-08-18 16:36:46 +02:00
|
|
|
type = with types; listOf (either str package);
|
2017-08-28 16:33:22 +02:00
|
|
|
default = defaultPlugins;
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression "[ pkgs.vimPlugins.YankRing ]";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-09-15 10:58:13 +02:00
|
|
|
List of vim plugins to install. To get a list of supported plugins run:
|
2023-07-01 01:30:13 +02:00
|
|
|
{command}`nix-env -f '<nixpkgs>' -qaP -A vimPlugins`.
|
2019-08-18 16:36:46 +02:00
|
|
|
|
|
|
|
Note: String values are deprecated, please use actual packages.
|
2017-08-28 16:33:22 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-09-21 00:15:08 +02:00
|
|
|
settings = mkOption {
|
|
|
|
type = vimSettingsType;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2017-09-21 00:15:08 +02:00
|
|
|
{
|
|
|
|
expandtab = true;
|
|
|
|
history = 1000;
|
|
|
|
background = "dark";
|
|
|
|
}
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2017-09-21 00:15:08 +02:00
|
|
|
At attribute set of Vim settings. The attribute names and
|
|
|
|
corresponding values must be among the following supported
|
|
|
|
options.
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
${concatStringsSep "\n" (mapAttrsToList (n: v: ''
|
2023-07-01 08:14:03 +02:00
|
|
|
{var}`${n}`
|
|
|
|
: ${v.description}
|
2020-02-02 00:39:17 +01:00
|
|
|
'') knownSettings)}
|
2017-09-21 00:15:08 +02:00
|
|
|
|
|
|
|
See the Vim documentation for detailed descriptions of these
|
2023-07-01 08:14:03 +02:00
|
|
|
options. Use [](#opt-programs.vim.extraConfig) to manually
|
|
|
|
set any options not listed above.
|
2017-09-21 00:15:08 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-08-28 16:33:22 +02:00
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
set nocompatible
|
|
|
|
set nobackup
|
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Custom .vimrc lines";
|
2017-08-28 16:33:22 +02:00
|
|
|
};
|
2017-09-17 17:27:26 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Resulting customized vim package";
|
2017-09-17 17:27:26 +02:00
|
|
|
readOnly = true;
|
|
|
|
};
|
2021-10-06 15:56:06 +02:00
|
|
|
|
|
|
|
packageConfigurable = mkOption {
|
|
|
|
type = types.package;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Vim package to customize";
|
2022-12-29 22:36:05 +01: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-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Whether to configure {command}`vim` as the default
|
|
|
|
editor using the {env}`EDITOR` environment variable.
|
2022-12-29 22:36:05 +01:00
|
|
|
'';
|
2021-10-06 15:56:06 +02:00
|
|
|
};
|
2017-08-28 16:33:22 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
config = (let
|
|
|
|
customRC = ''
|
2021-12-27 09:03:18 +01:00
|
|
|
${concatStringsSep "\n" (remove "" (mapAttrsToList setExpr
|
2020-02-02 00:39:17 +01:00
|
|
|
(builtins.intersectAttrs knownSettings cfg.settings)))}
|
2017-08-28 16:33:22 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2017-08-28 16:33:22 +02:00
|
|
|
|
2021-10-06 15:56:06 +02:00
|
|
|
vim = cfg.packageConfigurable.customize {
|
2020-02-02 00:39:17 +01:00
|
|
|
name = "vim";
|
|
|
|
vimrcConfig = {
|
|
|
|
inherit customRC;
|
2017-08-28 16:33:22 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
packages.home-manager.start = plugins;
|
2019-08-18 16:36:46 +02:00
|
|
|
};
|
2020-02-02 00:39:17 +01: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 22:36:05 +01:00
|
|
|
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "vim"; };
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
programs.vim = {
|
|
|
|
package = vim;
|
|
|
|
plugins = defaultPlugins;
|
|
|
|
};
|
|
|
|
});
|
2017-08-28 16:33:22 +02:00
|
|
|
}
|