diff --git a/.github/workflows/luarocks.yml b/.github/workflows/luarocks.yml index 951a52a1..94663d8d 100644 --- a/.github/workflows/luarocks.yml +++ b/.github/workflows/luarocks.yml @@ -31,6 +31,7 @@ jobs: version: ${{ env.LUAROCKS_VERSION }} test_interpreters: "" dependencies: | + luarocks >= 3.11.0, < 4.0.0 toml-edit >= 0.3.6 fidget.nvim >= 1.1.0 fzy diff --git a/bootstrap.lua b/bootstrap.lua index 0666d69e..4fa2765c 100644 --- a/bootstrap.lua +++ b/bootstrap.lua @@ -11,7 +11,10 @@ math.randomseed(os.time()) local config_data = vim.g.rocks_nvim or {} local install_path = config_data.rocks_path or vim.fs.joinpath(vim.fn.stdpath("data") --[[@as string]], "rocks") -local luarocks_binary = config_data.luarocks_binary or vim.fs.joinpath(install_path, "bin", "luarocks") +local temp_luarocks_path = + ---@diagnostic disable-next-line: param-type-mismatch + vim.fs.joinpath(vim.fn.stdpath("run"), ("luarocks-%X"):format(math.random(256 ^ 7))) +local luarocks_binary = vim.fs.joinpath(temp_luarocks_path, "bin", "luarocks") ---@param dep string ---@return boolean is_missing @@ -104,7 +107,7 @@ local function set_up_luarocks(path) return true end -assert(set_up_luarocks(install_path), "failed to install luarocks! Please try again :)") +assert(set_up_luarocks(temp_luarocks_path), "failed to install luarocks! Please try again :)") vim.notify("Installing rocks.nvim...") diff --git a/doc/rocks.txt b/doc/rocks.txt index 280d2f1e..30bc9a7b 100644 --- a/doc/rocks.txt +++ b/doc/rocks.txt @@ -62,7 +62,7 @@ RocksOpts *RocksOpts* Fields: ~ {rocks_path?} (string) Local path in your filesystem to install rocks. Defaults to a `rocks` directory in `vim.fn.stdpath("data")`. {config_path?} (string) Rocks declaration file path. Defaults to `rocks.toml` in `vim.fn.stdpath("config")`. - {luarocks_binary?} (string) Luarocks binary path. Defaults to `luarocks`. + {luarocks_binary?} (string) Luarocks binary path. Defaults to `{rocks_path}/bin/luarocks`. {lazy?} (boolean) Whether to query luarocks.org lazily. Defaults to `false`. Setting this to `true` may improve startup time, but features like auto-completion will lag initially. {dynamic_rtp?} (boolean) Whether to automatically add freshly installed plugins to the 'runtimepath'. Defaults to `true` for the best default experience. {generate_help_pages?} (boolean) Whether to re-generate plugins help pages after installation/upgrade. diff --git a/flake.lock b/flake.lock index a4d92da4..2ca13345 100644 --- a/flake.lock +++ b/flake.lock @@ -103,11 +103,11 @@ "nixpkgs-lib": "nixpkgs-lib_2" }, "locked": { - "lastModified": 1706830856, - "narHash": "sha256-a0NYyp+h9hlb7ddVz4LUn1vT/PLwqfrWYcHMvFB1xYg=", + "lastModified": 1715865404, + "narHash": "sha256-/GJvTdTpuDjNn84j82cU6bXztE0MSkdnTWClUCRub78=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "b253292d9c0a5ead9bc98c4e9a26c6312e27d69f", + "rev": "8dc45382d5206bd292f9c2768b8058a8fd8311d9", "type": "github" }, "original": { @@ -184,11 +184,11 @@ "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1710933866, - "narHash": "sha256-GtYTuxY6AdFxl3uwFkTkqpvOP4lQLzu2YwqnejhDs1Q=", + "lastModified": 1717108591, + "narHash": "sha256-Sn6jrh9Nqp5UKJzNT0rg/DQCJCpFs/d+RM2/iENPpBo=", "owner": "mrcjkb", "repo": "nix-gen-luarc-json", - "rev": "6e8912ea4fbfaa10797caafb1f5628fb4178b6e8", + "rev": "39704e58b5227a82a14a00f5912e4bfccfa2b687", "type": "github" }, "original": { @@ -197,12 +197,41 @@ "type": "github" } }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat_3", + "gitignore": "gitignore", + "nixpkgs": [ + "neorocks", + "neovim-nightly", + "nixpkgs" + ], + "nixpkgs-stable": [ + "neorocks", + "neovim-nightly", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1716213921, + "narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ "neorocks", "neovim-nightly", - "pre-commit-hooks", + "git-hooks", "nixpkgs" ] }, @@ -292,14 +321,14 @@ "flake-utils": "flake-utils", "neovim-nightly": "neovim-nightly", "nixpkgs": "nixpkgs_3", - "pre-commit-hooks": "pre-commit-hooks_2" + "pre-commit-hooks": "pre-commit-hooks" }, "locked": { - "lastModified": 1716614585, - "narHash": "sha256-twfhGMyDqjtEP30HapozagEiGndM7kx9gl93lc5s8cg=", + "lastModified": 1717046486, + "narHash": "sha256-wFJaINjn9w1V2GrhvISh7LoYzEf+06PuYLYe1DXhcwY=", "owner": "nvim-neorocks", "repo": "neorocks", - "rev": "e3830fc54ee24860270eae1a61a5dc95d4290ff4", + "rev": "f289cc48abdb326accf49edaa72baf25d3872fc0", "type": "github" }, "original": { @@ -312,17 +341,17 @@ "inputs": { "flake-compat": "flake-compat_2", "flake-parts": "flake-parts_3", + "git-hooks": "git-hooks", "hercules-ci-effects": "hercules-ci-effects", "neovim-src": "neovim-src", - "nixpkgs": "nixpkgs_2", - "pre-commit-hooks": "pre-commit-hooks" + "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1716561825, - "narHash": "sha256-v9V74Xd1/n0n/1eB3gZ+LqcOCurWqTfBum5azqjWMII=", + "lastModified": 1716827514, + "narHash": "sha256-5qS9Jn3FaEFMGGhS/1mLOUifMFDLPcLczjcdaN7xgyE=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "d83afee1f19108100bd2fef1f86d87d2942d734d", + "rev": "7849e018a09688cd71bde887113954b3ce08739c", "type": "github" }, "original": { @@ -334,11 +363,11 @@ "neovim-src": { "flake": false, "locked": { - "lastModified": 1716501420, - "narHash": "sha256-VO9RCUNwiU627oVjR5gfsyz8z6VHkuW2VFT53xth1ig=", + "lastModified": 1716642936, + "narHash": "sha256-l53vGzYIy6tI1rYBlbxW502sDgpmZ4i/uTdWWtPKPtM=", "owner": "neovim", "repo": "neovim", - "rev": "e7859d2ad504a3e3cae1d540d5fd4f9b560d154a", + "rev": "52389e724366ebb2fb58f08c657f580900dd09ee", "type": "github" }, "original": { @@ -349,11 +378,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1708475490, - "narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", + "lastModified": 1716948383, + "narHash": "sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs=", "owner": "nixos", "repo": "nixpkgs", - "rev": "0e74ca98a74bc7270d28838369593635a5db3260", + "rev": "ad57eef4ef0659193044870c731987a6df5cf56b", "type": "github" }, "original": { @@ -377,20 +406,14 @@ }, "nixpkgs-lib_2": { "locked": { - "dir": "lib", - "lastModified": 1706550542, - "narHash": "sha256-UcsnCG6wx++23yeER4Hg18CXWbgNpqNXcHIo5/1Y+hc=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "97b17f32362e475016f942bbdfda4a4a72a8a652", - "type": "github" + "lastModified": 1714640452, + "narHash": "sha256-QBx10+k6JWz6u7VsohfSw8g8hjdBZEf8CFzXH1/1Z94=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" }, "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" } }, "nixpkgs-stable": { @@ -427,27 +450,27 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1716451822, - "narHash": "sha256-0lT5RVelqN+dgXWWneXvV5ufSksW0r0TDQi8O6U2+o8=", + "lastModified": 1716588411, + "narHash": "sha256-CdAZ3o459+1mAgILcdJfMBQAwUXupVe2cVTknvxs5kQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3305b2b25e4ae4baee872346eae133cf6f611783", + "rev": "1a9df4f74273f90d04e621e8516777efcec2802a", "type": "github" }, "original": { "owner": "NixOS", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", - "rev": "3305b2b25e4ae4baee872346eae133cf6f611783", "type": "github" } }, "nixpkgs_3": { "locked": { - "lastModified": 1716451822, - "narHash": "sha256-0lT5RVelqN+dgXWWneXvV5ufSksW0r0TDQi8O6U2+o8=", + "lastModified": 1716941088, + "narHash": "sha256-GKSAGfLNocNTux33YT9GbEXwEewxepwFL+ViX1CrMCQ=", "owner": "nixos", "repo": "nixpkgs", - "rev": "3305b2b25e4ae4baee872346eae133cf6f611783", + "rev": "6c25325ec30a566f5c0446ceee61ada081903872", "type": "github" }, "original": { @@ -459,11 +482,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1716686066, - "narHash": "sha256-EN7sacEgNZGdxF1lQz+yO0ZIwGfxQFYtvy+9EJTs7k0=", + "lastModified": 1717105481, + "narHash": "sha256-4NiEGLfhd0V+YSNhYrXcljkWIUrE38IEjS4wcrMNXHo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "a457dae31b5567a094cb24abf2aa50b81c34956b", + "rev": "4c9c9a8004d7d6d82a2f5555766d772b84df7a7b", "type": "github" }, "original": { @@ -473,35 +496,6 @@ } }, "pre-commit-hooks": { - "inputs": { - "flake-compat": "flake-compat_3", - "gitignore": "gitignore", - "nixpkgs": [ - "neorocks", - "neovim-nightly", - "nixpkgs" - ], - "nixpkgs-stable": [ - "neorocks", - "neovim-nightly", - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1716213921, - "narHash": "sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA=", - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "rev": "0e8fcc54b842ad8428c9e705cb5994eaf05c26a0", - "type": "github" - }, - "original": { - "owner": "cachix", - "repo": "pre-commit-hooks.nix", - "type": "github" - } - }, - "pre-commit-hooks_2": { "inputs": { "flake-compat": "flake-compat_4", "gitignore": "gitignore_2", @@ -525,7 +519,7 @@ "type": "github" } }, - "pre-commit-hooks_3": { + "pre-commit-hooks_2": { "inputs": { "flake-compat": "flake-compat_5", "gitignore": "gitignore_3", @@ -554,7 +548,7 @@ "gen-luarc": "gen-luarc", "neorocks": "neorocks", "nixpkgs": "nixpkgs_4", - "pre-commit-hooks": "pre-commit-hooks_3" + "pre-commit-hooks": "pre-commit-hooks_2" } }, "systems": { diff --git a/installer.lua b/installer.lua index 1c696897..22cab0a5 100644 --- a/installer.lua +++ b/installer.lua @@ -349,15 +349,18 @@ local function install() if line == "< OK >" then local install_path = input_fields.install_path.content local setup_luarocks = input_fields.setup_luarocks.content == "true" + local temp_luarocks_path = + ---@diagnostic disable-next-line: param-type-mismatch + vim.fs.joinpath(vim.fn.stdpath("run"), ("luarocks-%X"):format(math.random(256 ^ 7))) local luarocks_binary = "luarocks" if setup_luarocks then - local success = set_up_luarocks(install_path) + local success = set_up_luarocks(temp_luarocks_path) if not success then return end - luarocks_binary = vim.fs.joinpath(install_path, "bin", "luarocks") + luarocks_binary = vim.fs.joinpath(temp_luarocks_path, "bin", "luarocks") elseif vim.fn.executable(luarocks_binary) ~= 1 then vim.notify( luarocks_binary @@ -389,7 +392,6 @@ local function install() acquire_buffer_lock(buffer, function() local install_path_rel = install_path:gsub(vim.env.HOME, "") - local luarocks_binary_rel = luarocks_binary:gsub(vim.env.HOME, "") vim.api.nvim_buf_set_lines(buffer, 0, -1, true, { "INSTALLATION COMPLETE", @@ -399,7 +401,6 @@ local function install() ">lua", " local rocks_config = {", ' rocks_path = vim.env.HOME .. "' .. install_path_rel .. '",', - ' luarocks_binary = vim.env.HOME .. "' .. luarocks_binary_rel .. '",', " }", " ", " vim.g.rocks_nvim = rocks_config", @@ -437,7 +438,6 @@ local function install() vim.fn.setreg('"', { "local rocks_config = {", ' rocks_path = vim.env.HOME .. "' .. install_path_rel .. '",', - ' luarocks_binary = vim.env.HOME .. "' .. luarocks_binary_rel .. '",', "}", "", "vim.g.rocks_nvim = rocks_config", diff --git a/lua/rocks/config/init.lua b/lua/rocks/config/init.lua index 87fd10a7..46ffc626 100644 --- a/lua/rocks/config/init.lua +++ b/lua/rocks/config/init.lua @@ -16,7 +16,7 @@ local config = {} ---@class RocksOpts ---@field rocks_path? string Local path in your filesystem to install rocks. Defaults to a `rocks` directory in `vim.fn.stdpath("data")`. ---@field config_path? string Rocks declaration file path. Defaults to `rocks.toml` in `vim.fn.stdpath("config")`. ----@field luarocks_binary? string Luarocks binary path. Defaults to `luarocks`. +---@field luarocks_binary? string Luarocks binary path. Defaults to `{rocks_path}/bin/luarocks`. ---@field lazy? boolean Whether to query luarocks.org lazily. Defaults to `false`. Setting this to `true` may improve startup time, but features like auto-completion will lag initially. ---@field dynamic_rtp? boolean Whether to automatically add freshly installed plugins to the 'runtimepath'. Defaults to `true` for the best default experience. ---@field generate_help_pages? boolean Whether to re-generate plugins help pages after installation/upgrade. diff --git a/lua/rocks/config/internal.lua b/lua/rocks/config/internal.lua index 6e4eacfc..bd4d42dc 100644 --- a/lua/rocks/config/internal.lua +++ b/lua/rocks/config/internal.lua @@ -20,17 +20,19 @@ local config = {} local constants = require("rocks.constants") local fs = require("rocks.fs") +---@diagnostic disable-next-line: param-type-mismatch +local default_rocks_path = vim.fs.joinpath(vim.fn.stdpath("data"), "rocks") + --- rocks.nvim default configuration ---@class RocksConfig local default_config = { ---@type string Local path in your filesystem to install rocks - ---@diagnostic disable-next-line: param-type-mismatch - rocks_path = vim.fs.joinpath(vim.fn.stdpath("data"), "rocks"), + rocks_path = default_rocks_path, ---@type string Rocks declaration file path ---@diagnostic disable-next-line: param-type-mismatch config_path = vim.fs.joinpath(vim.fn.stdpath("config"), "rocks.toml"), ---@type string Luarocks binary path - luarocks_binary = "luarocks", + luarocks_binary = vim.fs.joinpath(default_rocks_path, "bin", "luarocks"), ---@type boolean Whether to query luarocks.org lazily lazy = false, ---@type boolean Whether to automatically add freshly installed plugins to the 'runtimepath' @@ -90,6 +92,12 @@ config = vim.tbl_deep_extend("force", { }, default_config, opts) ---@cast config RocksConfig +if not opts.luarocks_binary then + --- luarocks_binary has not been overridden. Set it in case rocks_path has. + ---@diagnostic disable-next-line: inject-field + config.luarocks_binary = vim.fs.joinpath(config.rocks_path, "bin", "luarocks") +end + local ok, err = check.validate(config) if not ok then vim.notify("Rocks: " .. err, vim.log.levels.ERROR) diff --git a/nix/plugin-overlay.nix b/nix/plugin-overlay.nix index 3e991df8..c17e4974 100644 --- a/nix/plugin-overlay.nix +++ b/nix/plugin-overlay.nix @@ -4,6 +4,34 @@ }: final: prev: let lib = final.lib; rocks-nvim-luaPackage-override = luaself: luaprev: { + # Workaround for https://github.com/NixOS/nixpkgs/issues/316009 + luarocks-rock = luaself.callPackage ({ + buildLuarocksPackage, + fetchFromGitHub, + fetchurl, + }: + buildLuarocksPackage { + pname = "luarocks"; + version = "3.11.0-1"; + knownRockspec = + (fetchurl { + url = "mirror://luarocks/luarocks-3.11.0-1.rockspec"; + sha256 = "0pi55445dskpw6nhrq52589h4v39fsf23c0kp8d4zg2qaf6y2n38"; + }) + .outPath; + src = fetchFromGitHub { + owner = "luarocks"; + repo = "luarocks"; + rev = "v3.11.0"; + hash = "sha256-mSwwBuLWoMT38iYaV/BTdDmmBz4heTRJzxBHC0Vrvc4="; + }; + meta = { + homepage = "http://www.luarocks.org"; + description = "A package manager for Lua modules."; + license.fullName = "MIT"; + }; + }) {}; + toml-edit = (luaself.callPackage ({ buildLuarocksPackage, @@ -133,7 +161,7 @@ luaOlder, buildLuarocksPackage, lua, - luarocks, + luarocks-rock, toml-edit, fidget-nvim, nvim-nio, @@ -147,7 +175,7 @@ src = self; disabled = luaOlder "5.1"; propagatedBuildInputs = [ - luarocks + luarocks-rock toml-edit fidget-nvim nvim-nio @@ -200,7 +228,7 @@ in { -- Copied from installer.lua local rocks_config = { rocks_path = vim.fn.stdpath("data") .. "/rocks", - luarocks_binary = "${final.lua51Packages.luarocks}/bin/luarocks", + luarocks_binary = "${final.lua51Packages.luarocks-rock}/bin/luarocks", } vim.g.rocks_nvim = rocks_config diff --git a/nix/test-overlay.nix b/nix/test-overlay.nix index cd0a27c7..743655d8 100644 --- a/nix/test-overlay.nix +++ b/nix/test-overlay.nix @@ -8,6 +8,7 @@ neovim = nvim; luaPackages = ps: with ps; [ + luarocks-rock toml-edit toml fidget-nvim diff --git a/rocks.nvim-scm-1.rockspec b/rocks.nvim-scm-1.rockspec index 4bcaad11..ee557131 100644 --- a/rocks.nvim-scm-1.rockspec +++ b/rocks.nvim-scm-1.rockspec @@ -8,6 +8,7 @@ version = _MODREV .. _SPECREV dependencies = { "lua >= 5.1", + "luarocks >= 3.11.0, < 4.0.0", "toml-edit >= 0.3.6", "fidget.nvim >= 1.1.0", "fzy", @@ -17,6 +18,7 @@ dependencies = { test_dependencies = { "lua >= 5.1", + "luarocks >= 3.11.0, < 4.0.0", "toml-edit >= 0.3.6", "fidget.nvim >= 1.1.0", "fzy",