dotfiles.nix/home/neovim.nix

107 lines
3.3 KiB
Nix

{ config, pkgs, lib, ... }:
let
inherit (lib) getName mkIf optional;
# inherit (config.lib.file) mkOutOfStoreSymlink;
nixConfigDir = "${config.home.homeDirectory}/dotfiles.nix";
# nvr = "${pkgs.neovim-remote}/bin/nvr";
pluginWithDeps = plugin: deps: plugin.overrideAttrs (_: { dependencies = deps; });
nonVSCodePlugin = plugin: {
plugin = plugin;
optional = true;
config = ''if !exists('g:vscode') | packadd ${plugin.pname} | endif'';
};
in
{
# Neovim
# https://rycee.gitlab.io/home-manager/options.html#opt-programs.neovim.enable
programs.neovim = {
enable = true;
viAlias = true;
vimAlias = true;
vimdiffAlias = true;
};
# Config and plugins ------------------------------------------------------------------------- {{{
home.sessionVariables = {
EDITOR = "nvim";
};
# TODO: migrate to lua config
# Minimal init.vim config to load Lua config. Nix and Home Manager don't currently support
# `init.lua`.
# xdg.configFile."nvim/lua".source = mkOutOfStoreSymlink "${nixConfigDir}/configs/nvim/lua";
# xdg.configFile."nvim/colors".source = mkOutOfStoreSymlink "${nixConfigDir}/configs/nvim/colors";
# programs.neovim.extraConfig = "lua require('init')";
programs.neovim.extraConfig = builtins.readFile ../configs/init.vim;
programs.neovim.plugins = with pkgs.vimPlugins; [
neovim-sensible
tabular
vim-commentary
vim-surround
tokyonight-nvim
lightline-vim
vim-fish
vim-nix
ctrlp
] ++ map (p: { plugin = p; optional = true; }) [
which-key-nvim
zoomwintab-vim
nvim-treesitter
] ++ map nonVSCodePlugin [
direnv-vim
vim-fugitive
dhall-vim
haskell-vim
];
# }}}
# Shell related ------------------------------------------------------------------------------ {{{
# From personal addon module `./modules/programs/neovim/extras.nix`
programs.neovim.extras.termBufferAutoChangeDir = true;
programs.neovim.extras.nvrAliases.enable = true;
# programs.fish.functions.set-nvim-background = mkIf config.programs.neovim.enable {
# # See `./shells.nix` for more on how this is used.
# body = ''
# # Set `background` of all running Neovim instances base on `$term_background`.
# for server in (${nvr} --serverlist)
# ${nvr} -s --nostart --servername $server -c "set background=$term_background" &
# end
# '';
# onVariable = "term_background";
# };
# programs.fish.interactiveShellInit = mkIf config.programs.neovim.enable ''
# # Run Neovim related functions on init for their effects, and to register them so they are
# # triggered when the relevant event happens or variable changes.
# set-nvim-background
# '';
# }}}
# Required packages -------------------------------------------------------------------------- {{{
programs.neovim.extraPackages = with pkgs; [
# neovim-remote
gcc # needed for nvim-treesitter
tree-sitter # needed for nvim-treesitter
# Language servers
# See `../configs/nvim/lua/init.lua` for configuration.
# ccls
nodePackages.bash-language-server
nodePackages.vim-language-server
nodePackages.vscode-langservers-extracted
nodePackages.yaml-language-server
rnix-lsp
] ++ optional (pkgs.stdenv.system != "x86_64-darwin") sumneko-lua-language-server;
# }}}
}