summaryrefslogtreecommitdiff
path: root/modules/programs
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2016-12-18 13:52:03 +0100
committerDaiderd Jordan <daiderd@gmail.com>2016-12-18 13:53:11 +0100
commit732866d6b67a85d77e020029909546e5e55e72d4 (patch)
treed1b26c8b9d3db03be4c07ef591a164c0b1afeaa6 /modules/programs
parentcf6d081c29dc7e4549e1a91c5c66dd211119d5ce (diff)
add programs.vim module
Diffstat (limited to 'modules/programs')
-rw-r--r--modules/programs/tmux.nix39
-rw-r--r--modules/programs/vim.nix111
2 files changed, 130 insertions, 20 deletions
diff --git a/modules/programs/tmux.nix b/modules/programs/tmux.nix
index 79abeb1..dc233fb 100644
--- a/modules/programs/tmux.nix
+++ b/modules/programs/tmux.nix
@@ -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
- '';
-
};
}
diff --git a/modules/programs/vim.nix b/modules/programs/vim.nix
new file mode 100644
index 0000000..115fa0f
--- /dev/null
+++ b/modules/programs/vim.nix
@@ -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
+ '';
+
+ };
+}