1
0
Fork 0
mirror of https://github.com/LnL7/nix-darwin.git synced 2025-03-28 02:37:09 +00:00

add programs.vim module

This commit is contained in:
Daiderd Jordan 2016-12-18 13:52:03 +01:00
parent cf6d081c29
commit 732866d6b6
No known key found for this signature in database
GPG key ID: D02435D05B810C96
3 changed files with 131 additions and 20 deletions

View file

@ -26,6 +26,7 @@ let
./modules/services/nix-daemon.nix
./modules/programs/bash.nix
./modules/programs/tmux.nix
./modules/programs/vim.nix
./modules/programs/zsh.nix
];
};

View file

@ -38,7 +38,7 @@ in {
type = types.str;
default = "$SHELL";
description = ''
Configure default login shell.
Configure default login shell for tmux.
'';
};
@ -47,7 +47,7 @@ in {
default = false;
example = true;
description = ''
Enable sensible configuration options.
Enable sensible configuration options for tmux.
'';
};
@ -56,7 +56,7 @@ in {
default = false;
example = true;
description = ''
Enable mouse support.
Enable mouse support for tmux.
'';
};
@ -65,7 +65,7 @@ in {
default = false;
example = true;
description = ''
Enable fzf keybindings for selecting sessions and panes.
Enable fzf keybindings for selecting tmux sessions and panes.
'';
};
@ -74,32 +74,39 @@ in {
default = false;
example = true;
description = ''
Enable vim style keybindings for copy mode, and navigation of panes.
Enable vim style keybindings for copy mode, and navigation of tmux panes.
'';
};
programs.tmux.tmuxConfig = mkOption {
type = types.lines;
default = "";
};
programs.tmux.tmuxOptions = mkOption {
internal = true;
type = types.attrsOf (types.submodule text);
default = {};
};
programs.tmux.tmuxConfig = mkOption {
type = types.lines;
default = "";
};
};
config = mkIf cfg.enable {
environment.etc."tmux.conf".text = ''
${tmuxOptions}
${cfg.tmuxConfig}
source-file -q /etc/tmux.conf.local
'';
programs.tmux.tmuxOptions.login-shell.text = if stdenv.isDarwin then ''
set -g default-command "reattach-to-user-namespace ${cfg.loginShell}"
'' else ''
set -g default-command "${cfg.loginShell}"
'';
programs.tmux.tmuxOptions.sensible.text = mkIf cfg.enableSensible (''
programs.tmux.tmuxOptions.sensible.text = mkIf cfg.enableSensible ''
set -g default-terminal "screen-256color"
setw -g aggressive-resize on
@ -119,7 +126,7 @@ in {
# set -g status-utf8 on
# set -g utf8 on
'');
'';
programs.tmux.tmuxOptions.mouse.text = mkIf cfg.enableMouse ''
set -g mouse on
@ -149,13 +156,5 @@ in {
bind -t vi-copy y copy-pipe "reattach-to-user-namespace pbcopy"
'');
environment.etc."tmux.conf".text = ''
${tmuxOptions}
${cfg.tmuxConfig}
source-file -q /etc/tmux.conf.local
'';
};
}

111
modules/programs/vim.nix Normal file
View file

@ -0,0 +1,111 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.vim;
vim = pkgs.vim_configurable.customize {
name = "vim";
vimrcConfig.customRC = config.environment.etc."vimrc".text;
vimrcConfig.vam.pluginDictionaries = cfg.plugins;
};
text = import ../system/write-text.nix {
inherit lib;
mkTextDerivation = name: text: pkgs.writeText "vim-options-${name}" text;
};
vimOptions = concatMapStringsSep "\n" (attr: attr.text) (attrValues cfg.vimOptions);
in {
options = {
programs.vim.enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to configure vim.
'';
};
programs.vim.enableSensible = mkOption {
type = types.bool;
default = false;
example = true;
description = ''
Enable sensible configuration options for vim.
'';
};
programs.vim.plugins = mkOption {
type = types.listOf types.attrs;
default = [];
example = [ { names = [ "surround" "vim-nix" ]; } ];
description = ''
VAM plugin dictionaries to use for vim_configurable.
'';
};
programs.vim.vimOptions = mkOption {
internal = true;
type = types.attrsOf (types.submodule text);
default = {};
};
programs.vim.vimConfig = mkOption {
type = types.lines;
default = "";
description = ''
Extra vimrcConfig to use for vim_configurable.
'';
};
};
config = mkIf cfg.enable {
environment.systemPackages =
[ # Include vim_configurable package.
vim
];
environment.variables.EDITOR = "${vim}/bin/vim";
environment.etc."vimrc".text = ''
${vimOptions}
${cfg.vimConfig}
if filereadable('/etc/vimrc.local')
source /etc/vimrc.local
endif
'';
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
nnoremap // :nohlsearch<CR>
set nowrap
set number
set list
set listchars=tab:»·,trail:·,extends:,precedes:
set fillchars+=vert:\ ,stl:\ ,stlnc:\
set lazyredraw
'';
};
}