1
0
mirror of https://github.com/nix-community/home-manager synced 2024-06-30 18:38:31 +02:00
home-manager/modules/programs/vim.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

185 lines
5.0 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.vim;
defaultPlugins = [ pkgs.vimPlugins.vim-sensible ];
knownSettings = {
background = types.enum [ "dark" "light" ];
backupdir = types.listOf types.str;
copyindent = types.bool;
directory = types.listOf types.str;
expandtab = types.bool;
hidden = types.bool;
history = types.int;
ignorecase = types.bool;
modeline = types.bool;
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;
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
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 {
options = {
programs.vim = {
enable = mkEnableOption (lib.mdDoc "Vim");
plugins = mkOption {
type = with types; listOf (either str package);
default = defaultPlugins;
example = literalExpression "[ pkgs.vimPlugins.YankRing ]";
description = lib.mdDoc ''
List of vim plugins to install. To get a list of supported plugins run:
{command}`nix-env -f '<nixpkgs>' -qaP -A vimPlugins`.
Note: String values are deprecated, please use actual packages.
'';
};
settings = mkOption {
type = vimSettingsType;
default = { };
example = literalExpression ''
{
expandtab = true;
history = 1000;
background = "dark";
}
'';
description = lib.mdDoc ''
At attribute set of Vim settings. The attribute names and
corresponding values must be among the following supported
options.
${concatStringsSep "\n" (mapAttrsToList (n: v: ''
{var}`${n}`
: ${v.description}
'') knownSettings)}
See the Vim documentation for detailed descriptions of these
options. Use [](#opt-programs.vim.extraConfig) to manually
set any options not listed above.
'';
};
extraConfig = mkOption {
type = types.lines;
default = "";
example = ''
set nocompatible
set nobackup
'';
description = lib.mdDoc "Custom .vimrc lines";
};
package = mkOption {
type = types.package;
description = lib.mdDoc "Resulting customized vim package";
readOnly = true;
};
packageConfigurable = mkOption {
type = types.package;
description = lib.mdDoc "Vim package to customize";
default = pkgs.vim-full or pkgs.vim_configurable;
defaultText = literalExpression "pkgs.vim-full";
example = literalExpression "pkgs.vim";
};
defaultEditor = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Whether to configure {command}`vim` as the default
editor using the {env}`EDITOR` environment variable.
'';
};
};
};
config = (let
customRC = ''
${concatStringsSep "\n" (remove "" (mapAttrsToList setExpr
(builtins.intersectAttrs knownSettings cfg.settings)))}
${cfg.extraConfig}
'';
vim = cfg.packageConfigurable.customize {
name = "vim";
vimrcConfig = {
inherit customRC;
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 ];
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "vim"; };
programs.vim = {
package = vim;
plugins = defaultPlugins;
};
});
}