I added stylua
to my configuration using Mason and wired it into Conform (conventional w/o nixvim) like
local mason = require("mason")
local mason_lspconfig = require("mason-lspconfig")
local mason_tool_installer = require("mason-tool-installer")
-- enable mason and configure icons
mason.setup({
ui = {
icons = {
package_installed = "✓",
package_pending = "➜",
package_uninstalled = "✗",
},
},
})
local servers = {
"lua_ls",
"marksman",
"omnisharp",
"bashls",
"pyright",
"rust_analyzer",
"tsserver",
}
local stylers = {
"prettier",
"stylua",
"eslint_d",
}
mason_lspconfig.setup({
-- list of servers for mason to install
ensure_installed = servers,
-- auto-install configured servers (with lspconfig)
automatic_installation = true, -- not the same as ensure_installed
})
mason_tool_installer.setup({
-- list of formatters & linters for mason to install
ensure_installed = stylers,
-- auto-install configured servers (with lspconfig)
automatic_installation = true,
})
local conform = require("conform")
conform.setup({
formatters_by_ft = {
javascript = { "prettier" },
typescript = { "prettier" },
javascriptreact = { "prettier" },
typescriptreact = { "prettier" },
css = { "prettier" },
html = { "prettier" },
json = { "prettier" },
yaml = { "prettier" },
markdown = { "prettier" },
lua = { "stylua" },
nix = { "nixfmt" },
python = { "autopep8" },
},
format_on_save = {
lsp_fallback = true,
async = false,
timeout_ms = 1000,
},
})
when conducting an actual formatting of a LUA file, I get:
14:48:16[ERROR] Formatter 'stylua' error: Could not start dynamically linked executable: /home/{username}/.local/share/nvim/mason/bin/stylua
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box. For more information, see:
https://nix.dev/permalink/stub-ld
when trying the same configuration but with luaformatter
instead of stylua
Mason already shows an error during installation:
[ERROR Fri 16 Aug 2024 03:02:16 PM CEST] ...kages/start/mason.nvim/lua/mason-core/installer/init.lua:249: Installation failed for Package(name=luaformatter) error=spawn: luarocks failed with exit code - and signal -. luarocks is not executable
I would appreciate to get some hints or even a working sample to achieve getting a LUA formatter work in NeoVim on NixOS + Home Manager.