Files
neovim-config/lua/config/rocks.lua
T
rootiest 273580f533 ♻️ refactor(full-scope)!: major revision refactoring
Code layout has been changed and improoved. Annotations are added for documentation. Automated through utility functions and data tables

BREAKING CHANGE: Tested from clean. Now properly uses LuaRocks to install dependencies.
2024-09-04 16:07:12 -04:00

104 lines
3.5 KiB
Lua

--- @module "config.rocks"
--- This module bootstraps rocks.nvim.
--- Rocks is a package manager for Neovim.
-- ╭─────────────────────────────────────────────────────────╮
-- │ ROCKS │
-- ╰─────────────────────────────────────────────────────────╯
local M = {}
-- ━━━━━━━━━━━━━━━━━━━━━━━━ Bootstrap rocks.nvim ━━━━━━━━━━━━━━━━━━━━━
do
local rocks_config = {
rocks_path = vim.env.HOME .. "/.local/share/nvim/rocks",
}
vim.g.rocks_nvim = rocks_config
local luarocks_path = {
vim.fs.joinpath(rocks_config.rocks_path, "share", "lua", "5.1", "?.lua"),
vim.fs.joinpath(
rocks_config.rocks_path,
"share",
"lua",
"5.1",
"?",
"init.lua"
),
}
package.path = package.path .. ";" .. table.concat(luarocks_path, ";")
local luarocks_cpath = {
vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.so"),
vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.so"),
-- Remove the dylib and dll paths if you do not need macos or windows support
vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.dylib"),
vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.dylib"),
vim.fs.joinpath(rocks_config.rocks_path, "lib", "lua", "5.1", "?.dll"),
vim.fs.joinpath(rocks_config.rocks_path, "lib64", "lua", "5.1", "?.dll"),
}
package.cpath = package.cpath .. ";" .. table.concat(luarocks_cpath, ";")
vim.opt.runtimepath:append(
vim.fs.joinpath(
rocks_config.rocks_path,
"lib",
"luarocks",
"rocks-5.1",
"rocks.nvim",
"*"
)
)
end
-- If rocks.nvim is not installed then install it!
if not pcall(require, "rocks") then
---@diagnostic disable-next-line: param-type-mismatch
local rocks_location = vim.fs.joinpath(vim.fn.stdpath("cache"), "rocks.nvim")
if not vim.uv.fs_stat(rocks_location) then
-- Pull down rocks.nvim
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/nvim-neorocks/rocks.nvim",
rocks_location,
})
end
-- If the clone was successful then source the bootstrapping script
assert(
vim.v.shell_error == 0,
"rocks.nvim installation failed. Try exiting and re-entering Neovim!"
)
vim.cmd.source(vim.fs.joinpath(rocks_location, "bootstrap.lua"))
vim.fn.delete(rocks_location, "rf")
end
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━ Rocks plugin spec ━━━━━━━━━━━━━━━━━━━━━━
M.plugin_spec = {
"vhyrro/luarocks.nvim",
priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config.
opts = {
rocks = { "magick" }, -- specifies a list of rocks to install
},
}
-- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Load plugins ━━━━━━━━━━━━━━━━━━━━━━━━━
-- Load rocks package manager
M.load_rocks = function()
require("rocks")
end
-- Perform setup
M.setup = function()
M.load_rocks()
end
-- Execute the setup function
M.setup()
return M