1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2024-12-15 17:51:01 +00:00
nix-darwin/modules/programs/vim.nix

134 lines
3.2 KiB
Nix
Raw Normal View History

2016-12-18 12:52:03 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.vim;
2017-01-02 07:21:27 +00:00
text = import ../lib/write-text.nix {
2016-12-18 12:52:03 +00:00
inherit lib;
mkTextDerivation = name: text: pkgs.writeText "vim-options-${name}" text;
};
vimOptions = concatMapStringsSep "\n" (attr: attr.text) (attrValues cfg.vimOptions);
2018-08-03 18:31:37 +00:00
in
2016-12-18 12:52:03 +00:00
2018-08-03 18:31:37 +00:00
{
2016-12-18 12:52:03 +00:00
options = {
programs.vim.enable = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc "Whether to configure vim.";
2016-12-18 12:52:03 +00:00
};
programs.vim.enableSensible = mkOption {
type = types.bool;
default = false;
example = true;
description = lib.mdDoc "Enable sensible configuration options for vim.";
2016-12-18 12:52:03 +00:00
};
2017-03-05 23:48:56 +00:00
programs.vim.extraKnownPlugins = mkOption {
type = types.attrsOf types.package;
default = {};
example = literalExpression
2017-03-05 23:48:56 +00:00
''
{
vim-jsx = pkgs.vimUtils.buildVimPluginFrom2Nix {
name = "vim-javascript-2016-07-29";
src = pkgs.fetchgit {
url = "git://github.com/mxw/vim-jsx";
rev = "261114c925ea81eeb4db1651cc1edced66d6b5d6";
sha256 = "17pffzwnvsimnnr4ql1qifdh4a0sqqsmcwfiqqzgglvsnzw5vpls";
};
dependencies = [];
};
}
'';
description = lib.mdDoc "Custom plugin declarations to add to VAM's knownPlugins.";
2017-03-05 23:48:56 +00:00
};
2016-12-18 12:52:03 +00:00
programs.vim.plugins = mkOption {
type = types.listOf types.attrs;
default = [];
example = [ { names = [ "surround" "vim-nix" ]; } ];
description = lib.mdDoc "VAM plugin dictionaries to use for vim_configurable.";
2016-12-18 12:52:03 +00:00
};
2018-08-03 18:39:23 +00:00
programs.vim.package = mkOption {
internal = true;
type = types.package;
};
2016-12-18 12:52:03 +00:00
programs.vim.vimOptions = mkOption {
internal = true;
type = types.attrsOf (types.submodule text);
default = {};
};
programs.vim.vimConfig = mkOption {
type = types.lines;
default = "";
description = lib.mdDoc "Extra vimrcConfig to use for vim_configurable.";
2016-12-18 12:52:03 +00:00
};
};
config = mkIf cfg.enable {
environment.systemPackages =
[ # Include vim_configurable package.
2018-08-03 18:39:23 +00:00
cfg.package
2016-12-18 12:52:03 +00:00
];
2018-08-03 18:39:23 +00:00
environment.variables.EDITOR = "${cfg.package}/bin/vim";
2016-12-18 12:52:03 +00:00
environment.etc."vimrc".text = ''
${vimOptions}
${cfg.vimConfig}
if filereadable('/etc/vimrc.local')
source /etc/vimrc.local
endif
'';
2018-08-03 18:39:23 +00:00
programs.vim.package = pkgs.vim_configurable.customize {
name = "vim";
vimrcConfig.customRC = config.environment.etc."vimrc".text;
vimrcConfig.vam = {
knownPlugins = pkgs.vimPlugins // cfg.extraKnownPlugins;
pluginDictionaries = cfg.plugins;
};
};
2016-12-18 12:52:03 +00:00
programs.vim.plugins = mkIf cfg.enableSensible [
{ names = [ "fugitive" "surround" "vim-nix" ]; }
];
programs.vim.vimOptions.sensible.text = mkIf cfg.enableSensible ''
set nocompatible
filetype plugin indent on
syntax on
set et sw=2 ts=2
set bs=indent,start
set hlsearch
2016-12-18 13:32:40 +00:00
set incsearch
2016-12-18 12:52:03 +00:00
nnoremap // :nohlsearch<CR>
set list
set listchars=tab:»·,trail:·,extends:,precedes:
set fillchars+=vert:\ ,stl:\ ,stlnc:\
2016-12-18 13:32:40 +00:00
set number
2016-12-18 12:52:03 +00:00
set lazyredraw
2016-12-18 13:32:40 +00:00
set nowrap
set showcmd
set showmatch
2016-12-18 12:52:03 +00:00
'';
};
}