summaryrefslogtreecommitdiffstats
path: root/common/vim.nix
blob: 481542a56a87a888174330219bc657e12ec756b8 (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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
inputs: {
  config,
  pkgs,
  lib,
  ...
}: let
  inherit (pkgs.unstable) neovim-unwrapped vimPlugins wrapNeovim;

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

  cfg = config.vim;

  variables = with lib;
    pkgs.writeTextDir "lua/myVariables.lua" ''
      -- Autogenerated variables from the NixOS configuration

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

  extraConfig = pkgs.writeTextDir "lua/myExtraConfig.lua" ''
    -- luaConfig from the NixOS configuration

    ${cfg.luaConfig}
  '';

  myGeneratedConfigPackage = pkgs.symlinkJoin {
    name = "myGeneratedConfig-nvim";
    paths = [variables extraConfig];
  };

  myConfigPackage = pkgs.unstable.vimUtils.buildVimPlugin {
    name = "myConfig-nvim";
    src = ../dotfiles/vim;
  };

  myNeovim = wrapNeovim neovim-unwrapped {
    configure = {
      inherit (config.vim) beforePlugins;

      customRC = ''
        lua require("myVariables")
        lua require("myConfig")
        lua require("myExtraConfig")

        ${cfg.extraConfig}
      '';

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

            # Dependencies
            plenary-nvim
            popup-nvim

            # UI
            undotree
            gruvbox-community
            lualine-nvim
            lualine-lsp-progress
            (gitsigns-nvim.overrideAttrs (_old: {
              src = pkgs.fetchFromGitHub {
                owner = "lewis6991";
                repo = "gitsigns.nvim";
                rev = "v0.6";
                sha256 = "sha256-e7JLXKupgk1TjQnUB1pSV+9QWWjeLbyNCqvP6ni1pb4=";
              };
            }))
            diffview-nvim
            nvim-notify
            indent-blankline-nvim
            oil-nvim
            dressing-nvim

            # Completion
            nvim-cmp
            cmp-buffer
            cmp-calc
            cmp-cmdline
            cmp-latex-symbols
            cmp-nvim-lsp
            cmp-path
            cmp-spell
            cmp-tmux
            cmp-treesitter
            cmp-vsnip

            # Snippets
            vim-vsnip
            vim-vsnip-integ

            # Telescope
            telescope-nvim

            # Treesitter
            nvim-treesitter.withAllGrammars
            nvim-treesitter-textobjects
            nvim-treesitter-context
            nvim-treesitter-refactor

            vim-matchup

            # Motions
            camelcasemotion
            vim-surround
            targets-vim

            neoformat

            # Languages
            vim-polyglot
            # Fixes "duplicated vim plugin" issue
            (refactoring-nvim.overrideAttrs (old: {dependencies = [];}))

            # Other
            comment-nvim
            fugitive-gitlab-vim
            none-ls-nvim
            tabular
            tmux-complete-vim
            vim-abolish
            vim-fugitive
            vim-oscyank
            vim-repeat
            vim-rhubarb
            vim-unimpaired
          ]
          ++ 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 = [myNeovim];

    environment.variables = {
      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 = "";
  };
}