config/modules/home/apps/tools/neovim/default.nix
2024-11-14 23:40:28 -05:00

235 lines
6.8 KiB
Nix

{
inputs,
options,
config,
lib,
pkgs,
...
}:
with lib;
with lib.custom; let
cfg = config.apps.tools.neovim;
lazy-nix-helper-nvim = pkgs.vimUtils.buildVimPlugin {
name = "lazy-nix-helper.nvim";
src = pkgs.fetchFromGitHub {
owner = "b-src";
repo = "lazy-nix-helper.nvim";
rev = "63b20ed071647bb492ed3256fbda709e4bfedc45";
hash = "sha256-TBDZGj0NXkWvJZJ5ngEqbhovf6RPm9N+Rmphz92CS3Q=";
};
};
sanitizePluginName = input: let
name = strings.getName input;
intermediate = strings.removePrefix "vimplugin-" name;
result = strings.removePrefix "lua5.1-" intermediate;
in
result;
pluginList = plugins: strings.concatMapStrings (plugin: " [\"${sanitizePluginName plugin.name}\"] = \"${plugin.outPath}\",\n") plugins;
in {
options.apps.tools.neovim = with types; {
enable = mkBoolOpt false "Enable Neovim";
};
config = mkIf cfg.enable {
programs.neovim = {
catppuccin.enable = false;
enable = true;
defaultEditor = true;
package = inputs.neovim-nightly-overlay.packages.${pkgs.system}.default;
extraLuaPackages = ps: [ps.magick];
extraPackages = with pkgs; [
# Formatters
alejandra # Nix
black # Python
prettierd # Multi-language
shfmt
isort
stylua
rustywind
imagemagick
# LSP
lua-language-server
nixd
(pkgs.rust-bin.selectLatestNightlyWith
(toolchain: toolchain.minimal))
rust-analyzer
vscode-langservers-extracted
nodePackages.vscode-json-languageserver
nodePackages.typescript-language-server
#nodePackages.astro-language-server
nodePackages.bash-language-server
nodePackages.svelte-language-server
tailwindcss-language-server
taplo
docker-compose-language-service
dockerfile-language-server-nodejs
haskellPackages.hadolint
shellcheck
markdownlint-cli2
shfmt
sqlfluff
go
tailwindcss-language-server
clang
# Tools
git
html-tidy
cmake
fzf
charm-freeze
gcc
gnumake
nodejs
fswatch # File watcher utility, replacing libuv.fs_event for neovim 10.0
sqlite
postgresql
mongosh
gerbera
vscode-extensions.vadimcn.vscode-lldb.adapter
];
plugins = with pkgs.vimPlugins; [
lazy-nix-helper-nvim
lazy-nvim
];
extraLuaConfig = ''
local plugins = {
${pluginList config.programs.neovim.plugins}
}
local lazy_nix_helper_path = "${lazy-nix-helper-nvim}"
if not vim.loop.fs_stat(lazy_nix_helper_path) then
lazy_nix_helper_path = vim.fn.stdpath("data") .. "/lazy_nix_helper/lazy_nix_helper.nvim"
if not vim.loop.fs_stat(lazy_nix_helper_path) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/b-src/lazy_nix_helper.nvim.git",
lazy_nix_helper_path,
})
end
end
-- add the Lazy Nix Helper plugin to the vim runtime
vim.opt.rtp:prepend(lazy_nix_helper_path)
-- call the Lazy Nix Helper setup function
local non_nix_lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
local lazy_nix_helper_opts = { lazypath = non_nix_lazypath, input_plugin_table = plugins }
require("lazy-nix-helper").setup(lazy_nix_helper_opts)
-- get the lazypath from Lazy Nix Helper
local lazypath = require("lazy-nix-helper").lazypath()
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require('config.lazy')
local dashboardImage = vim.api.nvim_create_augroup("DashboardImage", { clear = true })
local img = require("image").from_file("${./NeoVim.png}")
local is_visible = false
-- Known image dimensions
local IMG_WIDTH = 50 -- characters
local IMG_HEIGHT = 14 -- lines
-- Debug notification function
local function debug_notify(message)
-- vim.notify(message, vim.log.levels.INFO)
end
-- Function to calculate centered position
local function center_image()
local win_width = vim.o.columns
local win_height = vim.o.lines
local x = math.floor((win_width - IMG_WIDTH) / 2)
local y = math.floor((win_height - IMG_HEIGHT) / 6)
return math.max(0, x), math.max(0, y)
end
-- Function to update image position
local function update_image()
debug_notify("Attempting to update image. is_visible = " .. tostring(is_visible))
if is_visible then
local x, y = center_image()
debug_notify("Positioning image at x=" .. x .. ", y=" .. y)
img:clear()
img:render()
img:move(x, y)
end
end
-- Show image on both VimEnter and when dashboard buffer is created
vim.api.nvim_create_autocmd({ "VimEnter", "BufWinEnter", "BufEnter" }, {
group = dashboardImage,
callback = function(ev)
local filetype = vim.api.nvim_buf_get_option(ev.buf, "filetype")
debug_notify("Event triggered: " .. ev.event .. ", filetype: " .. filetype)
if filetype == "dashboard" then
debug_notify("Dashboard detected, setting visible")
is_visible = true
vim.schedule(update_image)
end
end,
})
-- Handle window resize
vim.api.nvim_create_autocmd("VimResized", {
group = dashboardImage,
callback = function()
debug_notify("Window resized")
update_image()
end,
})
-- Clear image when leaving dashboard
vim.api.nvim_create_autocmd("BufLeave", {
group = dashboardImage,
callback = function()
debug_notify("Leaving buffer")
is_visible = false
img:clear()
end,
})
-- Catch when returning to dashboard
vim.api.nvim_create_autocmd("FileType", {
group = dashboardImage,
pattern = "dashboard",
callback = function()
debug_notify("FileType dashboard detected")
is_visible = true
vim.schedule(update_image)
end,
})
-- Initial debug message
debug_notify("Dashboard image setup loaded")
'';
};
xdg.configFile = {
"nvim" = {
source = ./config;
recursive = true;
};
};
};
}