-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
223 lines (195 loc) · 9.14 KB
/
flake.nix
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
{
description = "Neovim";
inputs = {
nixpkgs.url = "nixpkgs"; # I pin nixpkgs on my systems, so this gets updated to match that
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
# plugins
"plugin:vim-repeat" = { url = "github:tpope/vim-repeat"; flake = false; };
"plugin:plenary.nvim" = { url = "github:nvim-lua/plenary.nvim"; flake = false; };
"plugin:nvim-lspconfig" = { url = "github:neovim/nvim-lspconfig"; flake = false; };
"plugin:lsp_signature.nvim" = { url = "github:ray-x/lsp_signature.nvim"; flake = false; };
"plugin:nvim-lightbulb" = { url = "github:kosayoda/nvim-lightbulb"; flake = false; };
"plugin:nvim-cmp" = { url = "github:hrsh7th/nvim-cmp"; flake = false; };
"plugin:cmp-nvim-lsp" = { url = "github:hrsh7th/cmp-nvim-lsp"; flake = false; };
"plugin:cmp-buffer" = { url = "github:hrsh7th/cmp-buffer"; flake = false; };
"plugin:cmp-path" = { url = "github:hrsh7th/cmp-path"; flake = false; };
"plugin:cmp-cmdline" = { url = "github:hrsh7th/cmp-cmdline"; flake = false; };
"plugin:LuaSnip" = { url = "github:L3MON4D3/LuaSnip"; flake = false; };
"plugin:cmp_luasnip" = { url = "github:saadparwaiz1/cmp_luasnip"; flake = false; };
"plugin:goyo.vim" = { url = "github:junegunn/goyo.vim"; flake = false; };
"plugin:undotree" = { url = "github:mbbill/undotree"; flake = false; };
"plugin:telescope.nvim" = { url = "github:nvim-telescope/telescope.nvim"; flake = false; };
"plugin:vim-eunuch" = { url = "github:tpope/vim-eunuch"; flake = false; };
"plugin:vim-recover" = { url = "github:ralismark/vim-recover"; flake = false; };
"plugin:Colorizer" = { url = "github:chrisbra/Colorizer"; flake = false; };
"plugin:guess-indent.nvim" = { url = "github:NMAC427/guess-indent.nvim"; flake = false; };
# "plugin:vim-pandoc-syntax" = { url = "github:vim-pandoc/vim-pandoc-syntax"; flake = false; };
#"plugin:vim-polyglot" = { url = "github:sheerun/vim-polyglot"; flake = false; };
"plugin:vim-easy-align" = { url = "github:junegunn/vim-easy-align"; flake = false; };
"plugin:vim-textobj-user" = { url = "github:kana/vim-textobj-user"; flake = false; };
"plugin:vim-textobj-indent" = { url = "github:kana/vim-textobj-indent"; flake = false; };
"plugin:vim-textobj-parameter" = { url = "github:sgur/vim-textobj-parameter"; flake = false; };
"plugin:vim-textobj-between" = { url = "github:thinca/vim-textobj-between"; flake = false; };
"plugin:opsort.vim" = { url = "github:ralismark/opsort.vim"; flake = false; };
"plugin:vim-nix" = { url = "github:LnL7/vim-nix"; flake = false; };
"plugin:rainbow-delimiters.nvim" = { url = "github:hiphish/rainbow-delimiters.nvim"; flake = false; };
"plugin:indent-blankline.nvim" = { url = "github:lukas-reineke/indent-blankline.nvim"; flake = false; };
"plugin:base16-nvim" = { url = "github:RRethy/base16-nvim"; flake = false; };
# plugins with custom steps
"telescope-fzf-native.nvim" = { url = "github:nvim-telescope/telescope-fzf-native.nvim"; flake = false; };
"sg.nvim" = { url = "github:sourcegraph/sg.nvim"; flake = false; }; # no flake; they pull in too many dependencies
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
lib = pkgs.lib;
# parse inputs to extract everything beginning with plugin:
autoPlugins = let
buildPlug = name: src: pkgs.vimUtils.buildVimPlugin {
pname = lib.removePrefix "plugin:" name;
version = src.shortRev;
inherit src;
};
in
lib.mapAttrsToList buildPlug
(lib.filterAttrs (k: _: lib.hasPrefix "plugin:" k) inputs);
# full list of plugins
plugins = [
(pkgs.vimUtils.buildVimPlugin rec {
pname = "telescope-fzf-native.nvim";
src = inputs."${pname}";
version = src.shortRev;
buildPhase = ''
make
'';
})
(pkgs.vimUtils.buildVimPlugin rec {
pname = "sg.nvim";
src = inputs."${pname}";
version = src.shortRev;
patches = [
(builtins.toFile "set-model.patch" ''
--- a/lua/sg/cody/rpc.lua
+++ b/lua/sg/cody/rpc.lua
@@ -62,8 +62,9 @@ local get_server_config = function(creds, remote_url)
source = "IDEEXTENSION",
},
customConfiguration = {
+ ["cody.autocomplete.advanced.provider"] = vim.g.sg_provider,
+ ["cody.autocomplete.advanced.model"] = vim.g.sg_model,
-- ["cody.useContext"] = "keyword",
- ["cody.experimental.symfContext"] = true,
-- ["cody.debug.enable"] = true,
-- ["cody.debug.verbose"] = true,
},
'')
];
postInstall = let
# copied from https://github.com/NixOS/nixpkgs/blob/37e24536ec7a4e1afeb74a632fd2ae47a05ce3a9/pkgs/applications/editors/vim/plugins/non-generated/sg-nvim/default.nix
sg-nvim-rust = pkgs.rustPlatform.buildRustPackage {
inherit pname src version;
cargoHash = "sha256-zD2QvAXu2z3Q5H7n53P0xiKW9gYVu+I4SZMYLdL3L1Q=";
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ];
prePatch = ''
rm .cargo/config.toml
'';
env.OPENSSL_NO_VENDOR = true;
cargoBuildFlags = [ "--workspace" ];
# tests are broken
doCheck = false;
};
in ''
mkdir -p $out/dist
ln -s ${sg-nvim-rust}/{bin,lib}/* $out/dist
'';
})
] ++ autoPlugins;
# create a neovim package with a given RC
neovim-with-rc = customRC: pkgs.wrapNeovim pkgs.neovim-unwrapped {
withRuby = false;
withPython3 = false;
configure = {
inherit customRC;
packages.main = {
start = plugins ++ [
pkgs.vimPlugins.nvim-treesitter.withAllGrammars
];
};
};
};
# wrap neovim+vimrc in a script that runs nvr/nvim as appropriate
with-extra-scripts = final-neovim:
let
# The dependency on neovim-remote is mainly because --remote-wait is unsupported
vim = pkgs.writeScriptBin "vim" ''
if [ -n "$NVIM" ]; then
if [ "$#" -eq 0 ]; then
echo "Can't open blank nested neovim" >&2
exit 1
else
exec ${pkgs.neovim-remote}/bin/nvr --nostart -cc split -c "setl bufhidden=delete" --remote-wait "$@"
fi
else
exec ${final-neovim}/bin/nvim "$@"
fi
'';
manpager = pkgs.writeScriptBin "vim-manpager" ''
cat > /dev/null # eat the rendered page
# unescape MAN_PN -- see <https://gitlab.com/man-db/man-db/-/blob/92dd5e7fb57fd841b89e21bf16b584aa654c612b/src/man.c#L870-898>
pn=$(printf %s "$MAN_PN" | sed -e 's/\\\(.\)/\1/g')
if [ -n "$NVIM" ]; then
echo "Opening man page for '$pn' in parent vim..."
exec ${pkgs.neovim-remote}/bin/nvr --nostart -c "Man $pn"
else
exec ${final-neovim}/bin/nvim "man://$pn"
fi
'';
in
pkgs.symlinkJoin {
name = "neovim";
paths = [ final-neovim vim manpager ];
};
# common bits of rc init
common-rc = ''
" shared init
let g:flake_lock = "${./.}/flake.lock"
let $PATH .= ":${pkgs.ripgrep}/bin:${pkgs.nodejs}/bin"
'';
in
rec {
apps.default = apps.hosted;
packages.default = packages.hosted;
apps.hosted = {
type = "app";
program = "${packages.hosted}/bin/vim";
};
packages.hosted = with-extra-scripts (neovim-with-rc ''
${common-rc}
" hosted: bootstrap into actual vimrc
let &rtp = stdpath("config") .. "," .. &rtp .. "," .. stdpath("config") .. "/after"
let $MYVIMRC = stdpath("config") .. "/init.lua"
source $MYVIMRC
'');
apps.freestanding = {
type = "app";
program = "${packages.freestanding}/bin/nvim";
};
# we need to use ${./.} here instead of e.g. ${./init.lua} to ensure
# the whole directory is copied over
packages.freestanding = neovim-with-rc ''
${common-rc}
" freestanding: bootstrap into packaged vimrc
let g:freestanding = 1
let &rtp = "${./.}," .. &rtp .. ",${./.}/after"
let $MYVIMRC = "${./.}/init.lua"
source $MYVIMRC
'';
# ---------------------------------------------------------------------
});
}