summaryrefslogtreecommitdiffstats
path: root/common/vim.nix
blob: 821d43b1cf68776a9c9f35bdbb2f27c8ae6c51b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{ config, pkgs, lib, ... }:

let myNeovim = (pkgs.neovim.override {
  configure = {

    inherit (config.vim) beforePlugins;

    customRC = with lib;
      (concatStringsSep
        "\n"
        (mapAttrsToList
          (variable: value: "let g:${variable} = ${value}")
          config.vim.variables))
      + "\n"
      + builtins.readFile ../dotfiles/vimrc.vim + config.vim.extraConfig;

    vam = with pkgs; {
      pluginDictionaries = [
            # UI
            { name = "undotree"; }
            { name = "gruvbox-community"; }
            { name = "gitgutter"; }
            { name = "lightline-vim"; }
            { name = "vim-dirvish"; }

            # Motions
            { name = "camelcasemotion"; }
            { name = "surround"; }
            { name = "targets-vim"; }

            # Frameworks
            { name = "deoplete-nvim"; }
            { name = "neosnippet"; }
            { name = "neosnippet-snippets"; }
            { name = "neoformat"; }
            { name = "ctrlp"; }
            # Syntax generic completion for deoplete
            { name = "neco-syntax"; }

            # Languages
            { name = "vim-polyglot"; }
            { name = "editorconfig-vim"; }
            # Vim completion for deoplete
            { name = "neco-vim"; }
            { name = "deoplete-zsh"; }
            { name = "vim-pandoc"; }
            { name = "vim-pandoc-syntax"; }

            # Languages (but not programming languages)
            { name = "vim-grammarous"; }

            # Other
            { name = "tmux-complete-vim"; }
            { name = "fugitive"; }
            { name = "rhubarb"; }
            { name = "repeat"; }
            { name = "vim-unimpaired"; }
            { name = "tabular"; }
            { name = "vimwiki"; }
            { name = "vim-abolish"; }

          ] ++ config.vim.extraPlugins;

    };

  };
});
in {
  options.vim = with lib; {

    variables = mkOption {
      type = types.attrsOf types.str;
      default = {
        dominant_color = "'${config.theme.colors.dominant}'";
        ripgrep_path = "'${pkgs.ripgrep}/bin/rg'";
        fd_path = "'${pkgs.fd}/bin/fd'";
      };
      description = ''
        Extra global variables to add at the beginning of the vim configuration.

        Remember to escape strings with single-quotes.
      '';
    };

    extraPlugins = mkOption {
      type = types.listOf (types.attrsOf types.str);
      default = [];
      description = "Names of extra plugins to add";
    };

    extraRepoPlugins = mkOption {
      type = types.listOf (types.attrsOf types.str);
      default = [];
      description = "Names of extra plugins to add that are present in the local repository";
    };

    beforePlugins = mkOption {
      type = types.lines;
      default = "";
      description = "Extra lines to add in the vim configuration before loading plugins";
    };

    extraConfig = mkOption {
      type = types.lines;
      default = "";
      description = "Extra lines to add at the end of the vim configuration";
    };
  };

  config = {
    environment.systemPackages = with pkgs; [
      myNeovim
    ];

    environment.sessionVariables = {
      EDITOR = "nvim";
    };

    home-manager.users.minijackson = { ... }:
    {
      xdg.dataFile."nvim/backup/.keep".text = "";
    };

    home-manager.users.root = { ... }:
    {
      xdg.dataFile."nvim/backup/.keep".text = "";
    };
  };
}