summaryrefslogtreecommitdiffstats
path: root/common/vim.nix
blob: 613247e00d5a6c3434ca5cab28f90968eaf6c20a (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
inputs:

{ config, pkgs, lib, ... }:

let
  inherit (pkgs.unstable) vimPlugins wrapNeovim tree-sitter;

  luaFormat = inputs.self.lib.generators.lua { };

  neovim-unwrapped = inputs.neovim-master.defaultPackage.${config.nixpkgs.system};

  cfg = config.vim;

  myConfigPackage = with lib;
    pkgs.writeTextDir
      "share/vim-plugins/myConfig/lua/myConfig.lua"
      ''
        -- Autogenerated variables from the NixOS configuration

        ${(concatStringsSep
          "\n"
          (mapAttrsToList
            (variable: value: "vim.g.${variable} = ${luaFormat.generate value}")
            cfg.variables))}

        -- vim.lua from the NixOS configuration

        ${builtins.readFile ../dotfiles/vim.lua}

        -- luaConfig from the NixOS configuration

        ${cfg.luaConfig}
      '';

  myNeovim = wrapNeovim neovim-unwrapped {
    configure = {

      inherit (config.vim) beforePlugins;

      customRC = ''
        lua require("myConfig")

        ${cfg.extraConfig}
      '';

      packages.myVimPackage = with vimPlugins; {
        start = [
          myConfigPackage

          # Dependencies
          plenary-nvim
          popup-nvim

          # UI
          undotree
          gruvbox-community
          lualine-nvim
          gitsigns-nvim
          vim-dirvish
          lsp-status-nvim

          nvim-compe
          compe-latex-symbols
          compe-zsh

          vim-vsnip
          vim-vsnip-integ

          telescope-nvim

          # Treesitter
          (nvim-treesitter.withPlugins (_: tree-sitter.allGrammars))
          nvim-treesitter-textobjects
          nvim-treesitter-context

          vim-matchup

          # Motions
          camelcasemotion
          surround
          targets-vim

          neoformat

          # Languages
          vim-polyglot
          editorconfig-vim
          vim-pandoc
          vim-pandoc-syntax

          # Other
          tmux-complete-vim
          fugitive
          rhubarb
          repeat
          vim-unimpaired
          tabular
          vim-abolish
          vim-oscyank
        ] ++ config.vim.extraPlugins;
      };
    };
  };
in
{
  options.vim = with lib; {

    variables = mkOption {
      type = types.attrsOf luaFormat.type;
      default = {};
      description = "Extra global variables to add at the beginning of the vim configuration.";
    };

    extraPlugins = mkOption {
      type = with types; listOf package;
      default = [ ];
      description = "Names of extra plugins to add";
    };

    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";
    };

    luaConfig = mkOption {
      type = types.lines;
      default = "";
      description = "Lua Neovim configuration";
    };

    wrappedPackage = mkOption {
      type = types.package;
      description = "Resulting wrapped Neovim package";
      readOnly = true;
    };
  };

  config = {
    vim = {
      wrappedPackage = myNeovim;
      variables = {
        dominant_color = "${config.theme.colors.dominant}";
        ripgrep_path = "${pkgs.ripgrep}/bin/rg";
        fd_path = "${pkgs.fd}/bin/fd";
      };
    };

    environment.systemPackages = with pkgs; [
      myNeovim
    ];

    environment.sessionVariables = {
      EDITOR = "nvim";
      MANPAGER = "nvim +Man!";
    };

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

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