Giter Site home page Giter Site logo

luarocks.nvim's Introduction

luarocks.nvim

luarocks.nvim is a Neovim plugin designed to streamline the installation of luarocks packages directly within Neovim. It simplifies the process of managing Lua dependencies, ensuring a hassle-free experience for Neovim users.

Requirements

  • Neovim 0.9 or greater.

  • The git CLI tool.

  • Lua 5.1 or LuaJIT installed on your system and available in your system's PATH.

    On unix systems, this is as simple as using your system package manager (brew, pacman, apt etc.). Just make sure that you're installing the 5.1 or JIT version of lua! Here's a list of known package names for various package managers (choose the one your distro uses):

    • brew (MacOS): brew install luajit
    • apt: sudo apt install liblua5.1-0-dev
    • dnf: sudo dnf install compat-lua-devel-5.1.5
    • pacman: sudo pacman -Syu lua51 or sudo pacman -Syu luajit

    On Windows systems, it's recommended to use an all-in-one installer like https://github.com/rjpcomputing/luaforwindows. Be sure to restart your terminal after installing Lua for the PATH to be updated!

Usage

Lazy.nvim Integration

For users employing the Lazy.nvim plugin manager, luarocks.nvim can be added to your configuration with the following code:

{
  "vhyrro/luarocks.nvim",
  priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config.
  config = true,
}

Upon installing, an automatic build step will be invoked by lazy.nvim in an attempt to compile a local luarocks installation on your machine. If you're having issues with this, be sure to manually run :Lazy build luarocks.nvim!

Generally, other plugins which rely on luarocks.nvim as their dependency manager perform automatic dependency installation in their build.luas, so you don't even have to touch any options yourself! Just set up this plugin and the rest should be automatic.

Installing a Rock List

To install a set of rocks (with the ability to add version constraints) use the following configuration instead:

{
  "vhyrro/luarocks.nvim",
  priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config.
  opts = {
    rocks = { "fzy", "pathlib.nvim ~> 1.0" }, -- specifies a list of rocks to install
    -- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script
  },
}

The latest version of a rock will be pulled if the version constraint is not provided.

Other Plugin Managers

For users utilizing other plugin managers, manual setup is required. Use the following code to initialize luarocks.nvim:

require("luarocks-nvim").setup()

Not only this, you will also need to set up a manual build trigger. This is supported by most plugin managers like packer/pckr and vim-plug. See manual build trigger for more info.

Build Process

The luarocks.nvim plugin includes a build process to ensure proper functionality. The build process involves the following steps:

  1. Checking for the existence of lua and its respective version as well as git.
  2. Cloning the luarocks/luarocks repository at the lowest possible depth.
  3. Compiling luarocks into a .rocks directory directly in this plugin's root. On Windows the install process may prompt for administrative permissions.

Manual Build Trigger

You can manually trigger the build process using the following command inside the plugin root:

nvim -l build.lua

Executing this command initiates the complete build process, ensuring that all dependencies are properly installed. This manual trigger can be useful in scenarios where you want to ensure a fresh installation or troubleshoot any issues related to the build process.

Please note that the build process is automatically invoked during the setup phase, so manual triggering may be unnecessary in most cases.

luarocks.nvim's People

Contributors

vhyrro avatar camspiers avatar pysan3 avatar theleop avatar

Stargazers

rootiest avatar Mark Ferree avatar Feliche-Demian Netliukh avatar Michael Wu avatar Daniel Holström avatar Muhammad Saad avatar Amir Mohtasebi avatar Rodrigo Hashimoto avatar Notas Hellout avatar yetone avatar  avatar Mike avatar Timo Leistner avatar Milan Divkovic avatar  avatar  avatar Soli Tsaagane avatar Artyom avatar kohane27 avatar  avatar Brandon Pollack avatar Renzo Mondragón avatar Michael Goerz avatar Phan Tấn Thắng avatar yongnianliu avatar Andy Shevchenko avatar Jasha Sommer-Simpson avatar Danial Hanif avatar Sadman Tariq avatar Ken Brucker avatar J.Hale avatar  avatar Kenneth Jefferson avatar Mike Funk avatar 飞 avatar Taylor avatar Izel Nakri | izelnakri.eth avatar Michael Benford avatar Khenzii avatar Stuart Wright avatar  avatar Eduardo Bellido Bellido avatar Yunus avatar Lucas Moog avatar  avatar Ivar Abusdal avatar Kevin Manca avatar  avatar Alif Prihantoro avatar raypenha avatar Nicolas Lasso avatar Laker Turner avatar  avatar Jannik Buhr avatar Ben Lubas avatar Besufikad Micheal avatar  avatar Phillip Bonhomme avatar hebe ⚸ dite avatar  avatar David Guevara avatar juburan avatar Drake Bott avatar Brent Williams avatar Henry Sequeda González avatar Minsoo Park avatar Viv Sedov avatar  avatar  avatar Pavel Atanasov avatar  avatar zjw57 avatar Chaz avatar deatharte avatar Anthony Perrett avatar  avatar Will Hopkins avatar RitchielRez avatar Aquib Javed avatar Yi Ming avatar

Watchers

Izel Nakri | izelnakri.eth avatar  avatar

luarocks.nvim's Issues

Incorrect manual build trigger instruction

Hello,

Calling nvim -l ./build.lua ignores settings from init.vim file and didn't install rocks specified there.

For vim-plug I was managed to fix this using :source ./build.lua command as post-install hook. It seems that for other plugin managers this is correct way of building as well.

A snippet from my init.vim

Plug 'vhyrro/luarocks.nvim', {'do': ':source ./build.lua'}

And config

lua <<EOF
require("luarocks-nvim").setup {
    rocks = { },
}

EOF

Luarocks not finding git?

luarocks-nvim: require("luarocks-nvim.health").check()

luarocks.nvim ~

  • luarocks system is not prepared
  • ERROR git is not installed! Please install it at https://git-scm.com/downloads.
  • OK lua is installed
  • OK make is installed

This is the output of checkhealth, I have no idea how its not picking up my git installation?

Error:packer/start/luarocks.nvim/lua/luarocks-nvim/init.lua:40: attempt to index local 'opts' (a nil value)

I am using the nvim v0.9.5.

nvim --version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

The packer.nvim is used to install the plugin.

{
        "vhyrro/luarocks.nvim",
        config = function()
          require('luarocks-nvim').setup()
        end
 },

However, I got error the error message

packer.nvim: Error running config for luarocks.nvim: ...ck/packer/start/luarocks.nvim/lua/luarocks-nvim/init.lua:40: attempt to index local 'opts' (a nil value)

, when I start the neovim after trigger the build the process with the command

nvim -l build.lua

[Request]: Attempt to use the Neovim Lua interpreter by default.

Instead of looking for a global Lua installation on the user's system, perhaps it would be possible to use Neovim builtin Lua interpreter as the driver for Luarocks itself.

Not even sure if this is possible, but it doesn't sound that difficult either. Perhaps with some trickery it could be done.

[windows] [feature request] expose additional args to pass to luarocks install command

Some rocks, like lua-curl, need a binary installation. This is not a problem on Unix like system because of how they handle libraries. On windows, most of the time a user would need to pass a custom path for the location of the headers needed for said binary installations.

In the case of lua-curl, the variable LUA_CURLDIR needs to be defined (for example, in my case, I installed the headers files needed on C:\Users\pcx\Desktop\vcpkg\installed\x64-windows). The option to pass aditional arguments to the luarocks install command would solve this issue (LUA_CURLDIR=C:\Users\pcx\Desktop\vcpkg\installed\x64-windows on my example).

local output = vim.fn.system({ paths.luarocks, "install", "--deps-only", paths.rockspec })

I could create a PR handling this if the feature is deemed desirable and an interface for plugins/end users is agreed upon (or I could propose one).

luarocks is not executable because .rocks directory is installed in temporary dir instead of plugin root

When manually running nvim -l build.lua from within the plugin root directory, the .rocks directory ends up in /run/user/1000/luarocks-* instead of within the plugin root directory.

I tested this by I adding a print statement to paths.lua on the plugin_path variable:

local utils = require("luarocks-nvim.utils")

local plugin_path = utils.get_plugin_path()
print(plugin_path) <-- HERE
local rocks_path = utils.combine_paths(plugin_path, ".rocks")
local lib_extension = utils.is_win() and "?.dll" or "?.so"

When executing the build directly from the plugin root, the plugin path was printed as ".", whereas when run from inside Neovim, it was printed as the full path to the plugin root directory.

I wrote some code to fix the issue and it worked here.

-- utils.lua
local utils = {}

function utils.is_win()
	return vim.loop.os_uname().sysname:lower():find("windows")
end

function utils.get_path_separator()
	if utils.is_win() then
		return "\\"
	end
	return "/"
end

function utils.combine_paths(...)
	return table.concat({ ... }, utils.get_path_separator())
end

local function get_current_dir()
	if utils.is_win() then
		return os.getenv("CD")
	else
		return os.getenv("PWD")
	end
end

local function change_relative_to_absolute_path(path)
	local string_without_dot = path:sub(2)
	local absolute_path = get_current_dir()
	return (absolute_path .. string_without_dot)
end

local function path_is_relative(path)
	if path:sub(1,1) == "." and (path:sub(2,2) == "/" or path:sub(2,2) == "\\") then
		return true
	else
		return false
	end
end


function utils.get_plugin_path()
	local str = debug.getinfo(2, "S").source:sub(2)
	if utils.is_win() then
		str = str:gsub("/", "\\")
	end
	if path_is_relative(str) then
		str = change_relative_to_absolute_path(str)
	end
	return vim.fn.fnamemodify(str:match("(.*" .. utils.get_path_separator() .. ")"), ":h:h:h")
end

return utils

All I did was checking if the first char in the path is a '.' and if it is change the dot for the $PWD or CD for windows.

Error during installation

Hi, I'm getting error during installation:

❌ Installing LuaJIT
Vim:E731: using Dictionary as a String

I'm using Neovim 0.9.5 on macos 14.3.1.

checkhealth luarocks:

luarocks
- luarocks system is not prepared
- OK python3 is available on PATH, and rocks system is ready to be built

Could you please help with it?

Error with notify

Hi, when loading luarocks.nvim

I got this error :

lazy.nvim
 Failed to run `config` for luarocks.nvim 
 ...m/lazy/nvim-notify/lua/notify/render/wrapped-compact.lua:69: E565: Not allowe 
 ed to change text or change window 
 # stacktrace: 
 - /luarocks.nvim/lua/luarocks-nvim/notify.lua:17 _in_ **error** 
 - /luarocks.nvim/lua/luarocks-nvim/init.lua:27 _in_ **setup** 

[feture request] more flexible package config

I ran into an issue where i wanted to install a package from a different server and the package was expecting more cmd args to install properly. Namely this was ldbus. I propose a solution where each package has its own table. Something like

{
  "vhyrro/luarocks.nvim",
  opts = {
    rocks = { 
      {"fzy", <url>, { list, of, args}},
      {"pathlib.nvim ~> 1.0"}, -- leaf empty for default
  },
}

Of course this gets cluttered really fast and it would require a few design changes if I'm not wrong.
I'd be interested in hearing more thoughts on this

luarocks is not executable

Following the guide for install neorg with lazy.nvim. There is error during building.

Error executing vim.schedule lua callback: Vim:E475: Invalid value for argument cmd: '/home/x/.local/share/nvim/lazy/luarocks.nvim/.rocks/bin/luarocks' is not executable                                                  
stack traceback:
        [C]: in function 'system'
        ...hare/nvim/lazy/luarocks.nvim/lua/luarocks-nvim/rocks.lua:39: in function 'ensure'
        /home/x/.local/share/nvim/lazy/neorg/build.lua:14: in function </home/x/.local/share/nvim/lazy/neorg/build.lua:9>

No more `:Neorg` command after update to v8

Everything seems to have installed correctly but I don't have access to :Neorg command. I'm using Lazy.

Using v7 works.

$ nv --version
NVIM v0.10.0-dev-2686+g7dd6fd422b
Build type: RelWithDebInfo
LuaJIT 2.1.1702233742
Run "nvim -V1 -v" for more info

This is my config:

-- neorg.lua
local M = {}
function M.setup()
  local neorg = require("neorg")
  neorg.setup {
    load = {
      ["core.defaults"] = {}, -- Loads default behaviour
      ["core.ui.calendar"] = {},
      ["core.concealer"] = {
        config = {
          icon_preset = "basic",
          folds = true,
        }
      },
      ["core.dirman"] = { -- Manages Neorg workspaces
        config = {
          workspaces = {
            notes = "~/notes",
          },
          default_workspace = "notes",
        },
      },
    },
  }
end

return {
  "nvim-neorg/neorg",
  dependencies = { "luarocks.nvim" },
  -- build = ":Neorg sync-parsers",
  lazy = false,  -- Disable lazy loading as some `lazy.nvim` distributions set `lazy = true` by default
  version = "*", -- Pin Neorg to the latest stable release
  config = M.setup
}

-- luarocks.lua
return {
    "vhyrro/luarocks.nvim",
    priority = 1000,
    config = true,
}

change dir for build output or cleanup dir before new builds

When a new update (commit) is available, and Lazy updates the plugin it brings it in a detached HEAD because of course with :build command that follow the installation it creates new files in the directory of the plugin.

I think that is possible to manage this in some ways:

  • add a .gitignore file to ignore generated file from the build (.rocks/)
  • change directory for the build output (this leads to update the rtp path)

luarocks-nvim/build.lua: Failed to install luarocks (configure file)

I get the following error installing neorg version 8.0.0 and 7.0.0 while running Lazy build luarocks.nvim

luarocks_install_error

Neovim version:

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068

My system information:

DISTRIB_DESCRIPTION="Linux Mint 21 Vanessa"
VERSION_ID="21"
UBUNTU_CODENAME=jammy

Many thanks for the plugin and some hints to solve the error!

Display more insightful error messages.

Because of the way we are managing system calls (vim.fn.jobstart()), propagating errors through the build stage isn't the easiest thing in the world.

Despite this, it's important to display detailed error logs if something goes wrong. An on_stderr hook is required to achieve this.

Wrong name for 5.1 lua package in Fedora

I'm using Fedora 40.

The following worked for fulfilling the lua 5.1 requirement of this plugin:

sudo dnf install compat-lua

The following did not work for fulfilling the lua 5.1 requirement of this plugin:

sudo dnf install compat-lua-devel-5.1.5

I believe that the README.md must be updated, then.

Use system `luarocks` by default

Looking at the instructions you suggest dnf install compat-lua-devel. Shouldn't it suggest to do: dnf install luarocks and use that instead? I really don't see why it should download and compile luarocks if I can install it with the package manager and use that one. You could make it configurable if you want to compile it, but the default should always be the distro system package.

[Feature]: Detect/handle non-gnu installations of wget

wget comes in many shapes and sizes (with the most notable other implementation being busybox), and not every wget allows the same flags. This causes errors like "unable to pull manifest" when a user tries to pull rocks.

It might be interesting to check for the version of wget that is being used during the build stage, or make it very clear in the README to use a GNU version of wget or curl instead.

Make rocks installation directory configurable

I use NixOS, and right now, the directory used to install rocks is inside of the plugin directory. Since my plugins are installed with Nix, this directory is read-only, and I cannot install any rocks here.

I made a small patch to enable this for my own use case, as follows:

diff --git a/lua/luarocks-nvim/paths.lua b/lua/luarocks-nvim/paths.lua
index fa10bc8..33a9774 100644
--- a/lua/luarocks-nvim/paths.lua
+++ b/lua/luarocks-nvim/paths.lua
@@ -1,7 +1,7 @@
 local utils = require("luarocks-nvim.utils")
 
 local plugin_path = utils.get_plugin_path()
-local rocks_path = utils.combine_paths(plugin_path, ".rocks")
+local rocks_path = utils.combine_paths(vim.fn.stdpath("data"), "luarocks.nvim-rocks")
 local lib_extension = utils.is_win() and "?.dll" or "?.so"
 
 return {

However, I would like for it to be an option that I can pass to the setup function, if possible. I'm willing to contribute a PR if this is something you would be OK with having upstream.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.