fix(utils): discover nix submitEnv dynamically in dev checkout
Problem: In a dev checkout, `_nix_submit_cmd` is nil (only baked in by
the nix derivation). The uv fallback fails with code 127 on NixOS because
`uv` is not a bare system binary — it's only available via the FHS-wrapped
`cp-nvim-submit` script produced by `mkSubmitEnv`.
Solution: Add `discover_nix_submit_cmd` mirroring `discover_nix_python`:
runs `nix build #submitEnv --no-link --print-out-paths`, caches the result
in `stdpath('cache')/cp-nvim/nix-submit`, and sets `_nix_submit_cmd`.
`run_scraper` calls `setup_nix_submit_env()` before spawning submit.
This commit is contained in:
parent
128ff04621
commit
690469bd99
2 changed files with 69 additions and 0 deletions
|
|
@ -123,6 +123,71 @@ function M.get_python_submit_cmd(module, plugin_path)
|
|||
end
|
||||
|
||||
local python_env_setup = false
|
||||
local _nix_submit_attempted = false
|
||||
|
||||
---@return boolean
|
||||
local function discover_nix_submit_cmd()
|
||||
local cache_dir = vim.fn.stdpath('cache') .. '/cp-nvim'
|
||||
local cache_file = cache_dir .. '/nix-submit'
|
||||
|
||||
local f = io.open(cache_file, 'r')
|
||||
if f then
|
||||
local cached = f:read('*l')
|
||||
f:close()
|
||||
if cached and vim.fn.executable(cached) == 1 then
|
||||
_nix_submit_cmd = cached
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
local plugin_path = M.get_plugin_path()
|
||||
vim.notify('[cp.nvim] Building submit environment with nix...', vim.log.levels.INFO)
|
||||
vim.cmd.redraw()
|
||||
local result = vim
|
||||
.system(
|
||||
{ 'nix', 'build', plugin_path .. '#submitEnv', '--no-link', '--print-out-paths' },
|
||||
{ text = true }
|
||||
)
|
||||
:wait()
|
||||
|
||||
if result.code ~= 0 then
|
||||
logger.log('nix build #submitEnv failed: ' .. (result.stderr or ''), vim.log.levels.WARN)
|
||||
return false
|
||||
end
|
||||
|
||||
local store_path = result.stdout:gsub('%s+$', '')
|
||||
local submit_cmd = store_path .. '/bin/cp-nvim-submit'
|
||||
|
||||
if vim.fn.executable(submit_cmd) ~= 1 then
|
||||
logger.log('nix submit cmd not executable at ' .. submit_cmd, vim.log.levels.WARN)
|
||||
return false
|
||||
end
|
||||
|
||||
vim.fn.mkdir(cache_dir, 'p')
|
||||
f = io.open(cache_file, 'w')
|
||||
if f then
|
||||
f:write(submit_cmd)
|
||||
f:close()
|
||||
end
|
||||
|
||||
_nix_submit_cmd = submit_cmd
|
||||
return true
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
function M.setup_nix_submit_env()
|
||||
if _nix_submit_cmd then
|
||||
return true
|
||||
end
|
||||
if _nix_submit_attempted then
|
||||
return false
|
||||
end
|
||||
_nix_submit_attempted = true
|
||||
if vim.fn.executable('nix') == 1 then
|
||||
return discover_nix_submit_cmd()
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---@return boolean
|
||||
local function discover_nix_python()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue