neovim configuration using rocks.nvim plugin manager
1do
2 -- Specifies where to install/use rocks.nvim
3 local install_location = vim.fs.joinpath(vim.fn.stdpath("data"), "rocks")
4
5 -- Set up configuration options related to rocks.nvim (recommended to leave as default)
6 local rocks_config = {
7 rocks_path = vim.fs.normalize(install_location),
8 }
9 if vim.fn.has('mac') == 1 then
10 -- NOTE: don't know why but rocks.nvim in macos can't set the correct value to
11 -- `luarocks_binary` so set it manually.
12 rocks_config.luarocks_binary = "luarocks"
13 rocks_config.luarocks_config = {
14 arch = "macosx-aarch64",
15 variables = {
16 LUA_DIR = "/nix/store/8438aynxm813i6ksassvgq8bb40f8fln-lua-5.1.5-env",
17 LUA_INCDIR = "/nix/store/8438aynxm813i6ksassvgq8bb40f8fln-lua-5.1.5-env/include",
18 }
19 }
20 end
21
22 vim.g.rocks_nvim = rocks_config
23
24 -- Configure the package path (so that plugin code can be found)
25 local luarocks_path = {
26 vim.fs.joinpath(rocks_config.rocks_path, "share", "lua", "5.1", "?.lua"),
27 vim.fs.joinpath(rocks_config.rocks_path, "share", "lua", "5.1", "?", "init.lua"),
28 }
29 package.path = package.path .. ";" .. table.concat(luarocks_path, ";")
30
31 -- Configure the C path (so that e.g. tree-sitter parsers can be found)
32 local luarocks_cpath = {
33 vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.so"),
34 vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.so"),
35 }
36 package.cpath = package.cpath .. ";" .. table.concat(luarocks_cpath, ";")
37
38 -- Load all installed plugins, including rocks.nvim itself
39 vim.opt.runtimepath:append(vim.fs.joinpath(rocks_config.rocks_path, "lib", "luarocks", "rocks-5.1", "rocks.nvim", "*"))
40end
41
42-- If rocks.nvim is not installed then install it!
43if not pcall(require, "rocks") then
44 local rocks_location = vim.fs.joinpath(vim.fn.stdpath("cache"), "rocks.nvim")
45
46 if not vim.uv.fs_stat(rocks_location) then
47 -- Pull down rocks.nvim
48 vim.fn.system({
49 "git",
50 "clone",
51 "--filter=blob:none",
52 "https://github.com/nvim-neorocks/rocks.nvim",
53 rocks_location,
54 })
55 end
56
57 -- If the clone was successful then source the bootstrapping script
58 assert(vim.v.shell_error == 0, "rocks.nvim installation failed. Try exiting and re-entering Neovim!")
59
60 vim.cmd.source(vim.fs.joinpath(rocks_location, "bootstrap.lua"))
61
62 vim.fn.delete(rocks_location, "rf")
63end