1
Fork 0
satellite/home/features/neovim/default.nix

666 lines
18 KiB
Nix
Raw Normal View History

# TODO(imperanence): handle persistence of things like harpoon, lazy, etc
{ pkgs, lib, config, inputs, ... }:
2023-01-10 02:38:06 +01:00
let
2023-03-16 22:22:06 +01:00
# {{{ extraPackages
2023-01-10 02:38:06 +01:00
extraPackages = with pkgs; [
# Language servers
nodePackages.typescript-language-server # typescript
nodePackages_latest.purescript-language-server # purescript
lua-language-server # lua
2023-01-10 02:38:06 +01:00
rnix-lsp # nix
nil # nix
2023-06-15 20:08:20 +02:00
inputs.nixd.packages.${system}.nixd # nix
2023-12-10 12:55:54 +01:00
# haskell-language-server # haskell
# REASON: marked as broken
# dhall-lsp-server # dhall
2023-12-10 12:55:54 +01:00
# tectonic # something related to latex (?)
2023-01-10 02:38:06 +01:00
texlab # latex
nodePackages_latest.vscode-langservers-extracted # web stuff
2023-12-10 12:55:54 +01:00
# python310Packages.python-lsp-server # python
# pyright # python
rust-analyzer # rust
typst-lsp # typst
2023-01-10 02:38:06 +01:00
# Formatters
2023-12-10 12:55:54 +01:00
# luaformatter # Lua
2023-01-10 02:38:06 +01:00
stylua # Lua
2023-12-10 12:55:54 +01:00
# black # Python
# yapf # Python
# isort # Reorder python imports
2023-01-10 02:38:06 +01:00
nodePackages_latest.purs-tidy # Purescript
nodePackages_latest.prettier # Js & friends
2023-01-10 02:38:06 +01:00
nodePackages_latest.prettier_d_slim # Js & friends
typst-fmt # Typst
2023-01-10 02:38:06 +01:00
2023-03-30 02:54:57 +02:00
# Linters
ruff # Python linter
2023-12-10 12:55:54 +01:00
# mypy # Python typechecking
2023-03-30 02:54:57 +02:00
# Languages
2023-01-10 02:38:06 +01:00
nodePackages.typescript # typescript
2023-03-30 02:54:57 +02:00
lua # For repls and whatnot
2023-01-10 02:38:06 +01:00
wakatime # time tracking
rustfmt
2023-03-30 02:54:57 +02:00
# Others
2023-01-10 02:38:06 +01:00
fd # file finder
ripgrep # Grep rewrite
update-nix-fetchgit # Useful for nix stuff
tree-sitter # Syntax highlighting
libstdcxx5 # Required by treesitter aparently
2023-12-10 12:55:54 +01:00
# python310Packages.jupytext # Convert between jupyter notebooks and python files
# graphviz # For rust crate graph
2023-09-22 20:08:11 +02:00
haskellPackages.hoogle # For haskell search
2023-03-30 02:54:57 +02:00
# Preview
2023-12-10 12:55:54 +01:00
# zathura # Pdf reader
# xdotool # For zathura reverse search or whatever it's called
# glow # Md preview in terminal
# pandoc # Md processing
# libsForQt5.falkon # Needed for one of the md preview plugins I tried
2023-01-10 02:38:06 +01:00
# Latex setup
2023-12-10 12:55:54 +01:00
# texlive.combined.scheme-full # Latex stuff
# python38Packages.pygments # required for latex syntax highlighting
2023-12-07 22:35:57 +01:00
# sage
# sagetex # sage in latex
2023-03-30 02:54:57 +02:00
# required for the telescope fzf extension
gnumake
cmake
gcc
# Required by magma-nvim:
# python310Packages.pynvim
# python310Packages.jupyter
2023-12-04 06:25:00 +01:00
] ++ config.satellite.neovim.generated.dependencies;
2023-03-16 22:22:06 +01:00
# }}}
# {{{ extraRuntime
2023-12-02 06:04:57 +01:00
extraRuntimePaths = env: [
2023-01-22 01:22:38 +01:00
# Base16 theme
(pkgs.writeTextDir
"lua/nix/theme.lua"
config.satellite.colorscheme.lua
)
2023-01-22 01:22:38 +01:00
# Provide hints as to what app we are in
# (Useful because neovide does not provide the info itself right away)
(pkgs.writeTextDir
"lua/nix/env.lua"
"return '${env}'"
)
2023-12-02 06:04:57 +01:00
# Experimental nix module generation
config.satellite.neovim.generated.all
2023-01-10 02:38:06 +01:00
];
2023-12-02 06:04:57 +01:00
extraRuntime = env:
let
generated = pkgs.symlinkJoin {
name = "nixified-neovim-lua-modules";
paths = extraRuntimePaths env;
};
snippets = config.satellite.dev.path "home/features/neovim/snippets";
in
lib.concatStringsSep "," [ generated snippets ];
2023-03-16 22:22:06 +01:00
# }}}
# {{{ Client wrapper
2023-01-10 02:38:06 +01:00
# Wraps a neovim client, providing the dependencies
# and setting some flags:
#
# - NVIM_EXTRA_RUNTIME provides extra directories to add to the runtimepath.
# I cannot just install those dirs using the builtin package support because
# my package manager (lazy.nvim) disables those.
2023-03-16 22:22:06 +01:00
wrapClient = { base, name, binName ? name, extraArgs ? "" }:
2023-01-10 02:38:06 +01:00
pkgs.symlinkJoin {
inherit (base) name meta;
paths = [ base ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
2023-03-16 22:22:06 +01:00
wrapProgram $out/bin/${binName} \
2023-01-10 02:38:06 +01:00
--prefix PATH : ${lib.makeBinPath extraPackages} \
2023-12-02 06:04:57 +01:00
--set NVIM_EXTRA_RUNTIME ${extraRuntime name} \
${extraArgs}
2023-01-10 02:38:06 +01:00
'';
};
2023-03-16 22:22:06 +01:00
# }}}
# {{{ Clients
neovim = wrapClient {
2023-09-05 19:59:37 +02:00
base = pkgs.neovim;
name = "nvim";
};
2023-03-16 22:22:06 +01:00
neovide = wrapClient {
2023-09-05 19:59:37 +02:00
base = pkgs.neovide;
name = "neovide";
extraArgs = "--set NEOVIDE_MULTIGRID true";
};
2023-03-16 22:22:06 +01:00
firenvim = wrapClient {
base = pkgs.neovim;
2023-03-16 22:22:06 +01:00
name = "firenvim";
binName = "nvim";
extraArgs = "--set GIT_DISCOVERY_ACROSS_FILESYSTEM 1";
};
# }}}
2023-12-02 12:16:33 +01:00
nlib = config.satellite.neovim.lib;
2023-12-10 12:55:54 +01:00
lazy = config.satellite.neovim.lazy;
2023-01-10 02:38:06 +01:00
in
{
2023-03-16 22:22:06 +01:00
# {{{ Basic config
# We still want other modules to know that we are using neovim!
satellite.toggles.neovim.enable = true;
2023-12-02 00:59:18 +01:00
xdg.configFile.nvim.source = config.satellite.dev.path "home/features/neovim/config";
home.sessionVariables.EDITOR = "nvim";
2023-01-10 02:38:06 +01:00
home.packages = [
neovim
neovide
pkgs.vimclip
2023-01-10 02:38:06 +01:00
];
2023-03-16 22:22:06 +01:00
# }}}
# {{{ Firenvim
home.file.".mozilla/native-messaging-hosts/firenvim.json" =
lib.mkIf config.programs.firefox.enable {
text =
let
# God knows what this does
# https://github.com/glacambre/firenvim/blob/87c9f70d3e6aa2790982aafef3c696dbe962d35b/autoload/firenvim.vim#L592
2023-12-04 09:06:02 +01:00
firenvim_init = pkgs.writeText "firenvim_init.vim" /* vim */ ''
let g:firenvim_i=[]
let g:firenvim_o=[]
let g:Firenvim_oi={i,d,e->add(g:firenvim_i,d)}
let g:Firenvim_oo={t->[chansend(2,t)]+add(g:firenvim_o,t)}
let g:firenvim_c=stdioopen({'on_stdin':{i,d,e->g:Firenvim_oi(i,d,e)},'on_print':{t->g:Firenvim_oo(t)}})
let g:started_by_firenvim = v:true
'';
2023-12-04 09:06:02 +01:00
firenvim_file_loaded = pkgs.writeText "firenvim_file_loaded.vim" /* vim */ ''
try
call firenvim#run()
catch /Unknown function/
call chansend(g:firenvim_c,["f\n\n\n"..json_encode({"messages":["Your plugin manager did not load the Firenvim plugin for neovim."],"version":"0.0.0"})])
call chansend(2,["Firenvim not in runtime path. &rtp="..&rtp])
qall!
catch
call chansend(g:firenvim_c,["l\n\n\n"..json_encode({"messages": ["Something went wrong when running firenvim. See troubleshooting guide."],"version":"0.0.0"})])
call chansend(2,[v:exception])
qall!
endtry
'';
in
builtins.toJSON {
name = "firenvim";
description = "Turn your browser into a Neovim GUI.";
type = "stdio";
allowed_extensions = [ "firenvim@lacamb.re" ];
path = pkgs.writeShellScript "firenvim.sh" ''
mkdir -p /run/user/$UID/firenvim
chmod 700 /run/user/$UID/firenvim
cd /run/user/$UID/firenvim
exec '${firenvim}/bin/nvim' --headless \
--cmd 'source "${firenvim_init}"' \
-S '${firenvim_file_loaded}'
'';
};
};
2023-03-16 22:22:06 +01:00
# }}}
2023-12-07 22:35:57 +01:00
# {{{ Plugins
2023-12-02 06:04:57 +01:00
satellite.neovim.styluaConfig = ../../../stylua.toml;
2023-12-07 22:35:57 +01:00
satellite.neovim.runtime = {
env = "my.helpers.env";
languageServerOnAttach = "my.plugins.lspconfig";
tempest = "my.runtime";
};
2023-12-02 12:16:33 +01:00
2023-12-10 12:55:54 +01:00
# {{{ libraries
# {{{ plenary
satellite.neovim.lazy.plenary = {
package = "nvim-lua/plenary.nvim";
# Autoload when running tests
cmd = [ "PlenaryBustedDirectory" "PlenaryBustedFile" ];
};
# }}}
# {{{ nui
satellite.neovim.lazy.nui.package = "MunifTanjim/nui.nvim";
# }}}
# {{{ web-devicons
satellite.neovim.lazy.web-devicons.package = "nvim-tree/nvim-web-devicons";
# }}}
# }}}
2023-12-07 22:35:57 +01:00
# {{{ ui
# {{{ nvim-tree
2023-12-02 06:04:57 +01:00
satellite.neovim.lazy.nvim-tree = {
package = "kyazdani42/nvim-tree.lua";
2023-12-04 09:06:02 +01:00
2023-12-07 22:35:57 +01:00
env.blacklist = [ "vscode" "firenvim" ];
2023-12-02 12:16:33 +01:00
setup = true;
2023-12-04 09:06:02 +01:00
2023-12-02 06:04:57 +01:00
keys.mapping = "<C-n>";
keys.desc = "Toggle [n]vim-tree";
keys.action = "<cmd>NvimTreeToggle<cr>";
};
# }}}
2023-12-07 22:35:57 +01:00
# {{{ lualine
2023-12-02 12:16:33 +01:00
satellite.neovim.lazy.lualine = {
package = "nvim-lualine/lualine.nvim";
2023-12-10 12:55:54 +01:00
dependencies.lua = [ lazy.web-devicons.package ];
2023-12-02 12:16:33 +01:00
2023-12-07 22:35:57 +01:00
env.blacklist = [ "vscode" "firenvim" ];
2023-12-02 12:16:33 +01:00
event = "VeryLazy";
opts = {
options = {
component_separators = { left = ""; right = ""; };
section_separators = { left = ""; right = ""; };
theme = "auto";
disabled_filetypes = [ "undotree" ];
};
sections = {
lualine_a = [ "branch" ];
lualine_b = [ "filename" ];
lualine_c = [ "filetype" ];
lualine_x = [ "diagnostics" "diff" ];
lualine_y = [ ];
lualine_z = [ ];
};
# Integration with other plugins
extensions = [ "nvim-tree" ];
};
};
# }}}
2023-12-07 22:35:57 +01:00
# {{{ winbar
2023-12-02 12:16:33 +01:00
satellite.neovim.lazy.winbar = {
package = "fgheng/winbar.nvim";
2023-12-07 22:35:57 +01:00
env.blacklist = [ "vscode" "firenvim" ];
2023-12-02 12:16:33 +01:00
event = "VeryLazy";
opts.enabled = true;
};
# }}}
2023-12-07 22:35:57 +01:00
# {{{ harpoon
satellite.neovim.lazy.harpoon = {
package = "ThePrimeagen/harpoon";
keys =
let goto = key: index: {
desc = "Goto harpoon file ${toString index}";
mapping = "<c-s>${key}";
action = nlib.thunk
/* lua */ ''require("harpoon.ui").nav_file(${toString index})'';
};
in
[
{
desc = "Add file to [h]arpoon";
mapping = "<leader>H";
action = nlib.thunk
/* lua */ ''require("harpoon.mark").add_file()'';
}
{
desc = "Toggle harpoon quickmenu";
mapping = "<c-a>";
action = nlib.thunk
/* lua */ ''require("harpoon.ui").toggle_quick_menu()'';
}
(goto "q" 1)
(goto "w" 2)
(goto "e" 3)
(goto "r" 4)
(goto "a" 5)
(goto "s" 6)
(goto "d" 7)
(goto "f" 8)
(goto "z" 9)
];
};
# }}}
# }}}
2023-12-10 12:55:54 +01:00
# {{{ visual
# The line between `ui` and `visual is a bit rought. I currenlty mostly judge
# it by vibe.
# {{{ indent-blankline
satellite.neovim.lazy.indent-blankline = {
package = "lukas-reineke/indent-blankline.nvim";
main = "ibl";
setup = true;
env.blacklist = [ "vscode" ];
event = "BufReadPost";
};
# }}}
# }}}
# {{{ editing
# {{{ text navigation
2023-12-07 22:35:57 +01:00
# {{{ flash
2023-12-02 12:16:33 +01:00
satellite.neovim.lazy.flash = {
package = "folke/flash.nvim";
2023-12-07 22:35:57 +01:00
env.blacklist = [ "vscode" ];
2023-12-02 12:16:33 +01:00
keys =
let keybind = mode: mapping: action: desc: {
inherit mapping desc mode;
2023-12-04 09:06:02 +01:00
action = nlib.thunk /* lua */ ''require("flash").${action}()'';
2023-12-02 12:16:33 +01:00
};
in
[
(keybind "nxo" "s" "jump" "Flash")
(keybind "nxo" "S" "treesitter" "Flash Treesitter")
(keybind "o" "r" "remote" "Remote Flash")
(keybind "ox" "R" "treesitter_search" "Treesitter Search")
(keybind "c" "<C-S>" "toggle" "Toggle Flash Search")
];
# Disable stuff like f/t/F/T
opts.modes.char.enabled = false;
};
# }}}
2023-12-10 12:55:54 +01:00
# {{{ ftft (quickscope but written in lua)
satellite.neovim.lazy.ftft = {
package = "gukz/ftFT.nvim";
env.blacklist = [ "vscode" ];
keys = [ "f" "F" "t" "T" ];
setup = true;
};
# }}}
# }}}
2023-12-07 22:35:57 +01:00
# {{{ clipboard-image
satellite.neovim.lazy.clipboard-image = {
package = "postfen/clipboard-image.nvim";
env.blacklist = [ "firenvim" ];
cmd = "PasteImg";
keys = {
mapping = "<leader>p";
action = "<cmd>PasteImg<cr>";
desc = "[P]aste image from clipboard";
};
opts.default.img_name = nlib.import ./plugins/clipboard-image.lua "img_name";
opts.tex = {
img_dir = [ "%:p:h" "img" ];
affix = "\\includegraphics[width=\\textwidth]{%s}";
};
opts.typst = {
img_dir = [ "%:p:h" "img" ];
affix = ''#image("%s", width: 100)'';
};
};
# }}}
2023-12-10 12:55:54 +01:00
# {{{ lastplace
satellite.neovim.lazy.lastplace = {
package = "ethanholz/nvim-lastplace";
env.blacklist = [ "vscode" ];
event = "BufReadPre";
opts.lastplace_ignore_buftype = [ "quickfix" "nofile" "help" ];
};
# }}}
# {{{ undotree
satellite.neovim.lazy.undotree = {
package = "mbbill/undotree";
env.blacklist = [ "vscode" ];
cmd = "UndotreeToggle";
keys = {
mapping = "<leader>u";
action = "<cmd>UndoTreeToggle<cr>";
desc = "[U]ndo tree";
};
};
# }}}
# {{{ ssr (structured search & replace)
satellite.neovim.lazy.ssr = {
package = "cshuaimin/ssr.nvim";
env.blacklist = [ "vscode" ];
keys = {
mode = "nx";
mapping = "<leader>rt";
action = nlib.thunk /* lua */ ''require("ssr").open()'';
desc = "[r]eplace [t]emplate";
};
opts.keymaps.replace_all = "<s-cr>";
};
# }}}
# {{{ edit-code-block (edit injections in separate buffers)
satellite.neovim.lazy.edit-code-block = {
package = "dawsers/edit-code-block.nvim";
dependencies.lua = [ "nvim-treesitter/nvim-treesitter" ];
main = "ecb";
env.blacklist = [ "vscode" ];
setup = true;
keys = {
mapping = "<leader>e";
action = "<cmd>EditCodeBlock<cr>";
desc = "[e]dit injection";
};
};
# }}}
# {{{ mini.comment
satellite.neovim.lazy.mini-comment = {
package = "echasnovski/mini.comment";
name = "mini.comment";
setup = true;
keys = [
{ mapping = "gc"; mode = "nxv"; }
{ mapping = "gcc"; }
];
};
# }}}
2023-12-07 22:35:57 +01:00
# }}}
# {{{ ide
# {{{ conform
2023-12-04 06:25:00 +01:00
satellite.neovim.lazy.conform = {
package = "stevearc/conform.nvim";
2023-12-07 22:35:57 +01:00
env.blacklist = [ "vscode" ];
2023-12-04 06:25:00 +01:00
event = "BufReadPost";
opts.format_on_save.lsp_fallback = true;
2023-12-07 22:35:57 +01:00
opts.formatters_by_ft = let prettier = [ [ "prettierd" "prettier" ] ]; in
{
lua = [ "stylua" ];
python = [ "ruff_format" ];
javascript = prettier;
typescript = prettier;
javascriptreact = prettier;
typescriptreact = prettier;
html = prettier;
css = prettier;
markdown = prettier;
};
2023-12-04 06:25:00 +01:00
};
# }}}
2023-12-07 22:35:57 +01:00
# {{{ neoconf
2023-12-04 09:06:02 +01:00
satellite.neovim.lazy.neoconf = {
package = "folke/neoconf.nvim";
cmd = "Neoconf";
2023-12-07 22:35:57 +01:00
2023-12-04 09:06:02 +01:00
opts.import = {
vscode = true; # local .vscode/settings.json
coc = false; # global/local coc-settings.json
nlsp = false; # global/local nlsp-settings.nvim json settings
};
};
# }}}
2023-12-07 22:35:57 +01:00
# }}}
# {{{ language support
# {{{ haskell
satellite.neovim.lazy.haskell-tools = {
package = "mrcjkb/haskell-tools.nvim";
2023-12-10 12:55:54 +01:00
dependencies.lua = [ lazy.plenary.package ];
2023-12-07 22:35:57 +01:00
version = "^2";
env.blacklist = [ "vscode" ];
ft = [ "haskell" "lhaskell" "cabal" "cabalproject" ];
setup.vim.g.haskell_tools = {
hls = {
on_attach = nlib.lua /* lua */ ''require("my.plugins.lspconfig").on_attach'';
settings.haskell = {
formattingProvider = "fourmolu";
# This seems to work better with custom preludes
# See this issue https://github.com/fourmolu/fourmolu/issues/357
plugin.fourmolu.config.external = true;
};
2023-12-04 09:06:02 +01:00
};
2023-12-07 22:35:57 +01:00
# I think this wasn't showing certain docs as I expected (?)
tools.hover.enable = false;
};
};
# }}}
# {{{ rust
# {{{ rust-tools
satellite.neovim.lazy.rust-tools = {
package = "simrat39/rust-tools.nvim";
env.blacklist = [ "vscode" ];
ft = "rust";
opts.server.on_attach = nlib.languageServerOnAttach {
keys = {
mapping = "<leader>lc";
action = "<cmd>RustOpenCargo<cr>";
desc = "Open [c]argo.toml";
};
};
2023-12-04 09:06:02 +01:00
};
# }}}
2023-12-07 22:35:57 +01:00
# {{{ crates
satellite.neovim.lazy.crates = {
package = "saecki/crates.nvim";
2023-12-10 12:55:54 +01:00
dependencies.lua = [ lazy.plenary.package ];
2023-12-07 22:35:57 +01:00
env.blacklist = [ "vscode" ];
event = "BufReadPost Cargo.toml";
# {{{ Set up null_ls source
opts.null_ls = {
enabled = true;
name = "crates";
};
# }}}
setup.autocmds = [
# {{{ Load cmp source on insert
{
event = "InsertEnter";
group = "CargoCmpSource";
pattern = "Cargo.toml";
callback = nlib.thunkString /* lua */ ''
require("cmp").setup.buffer({ sources = { { name = "crates" } } })
'';
}
# }}}
# {{{ Load keybinds on attach
{
event = "BufReadPost";
group = "CargoKeybinds";
pattern = "Cargo.toml";
# {{{ Register which-key info
callback.callback = nlib.contextThunk /* lua */ ''
require("which-key").register({
["<leader>lc"] = {
name = "[l]ocal [c]rates",
bufnr = context.bufnr
},
})
'';
# }}}
callback.keys =
let
# {{{ Keymap helpers
keymap = mapping: action: desc: {
inherit mapping desc;
2023-12-10 12:55:54 +01:00
action = nlib.lua /* lua */ ''require("crates").${action}'';
2023-12-07 22:35:57 +01:00
};
keyroot = "<leader>lc";
# }}}
in
# {{{ Keybinds
[
(keymap "${keyroot}t" "toggle" "[c]rates [t]oggle")
(keymap "${keyroot}r" "reload" "[c]rates [r]efresh")
(keymap "${keyroot}H" "open_homepage" "[c]rate [H]omephage")
(keymap "${keyroot}R" "open_repository" "[c]rate [R]epository")
(keymap "${keyroot}D" "open_documentation" "[c]rate [D]ocumentation")
(keymap "${keyroot}C" "open_crates_io" "[c]rate [C]rates.io")
(keymap "${keyroot}v" "show_versions_popup" "[c]rate [v]ersions")
(keymap "${keyroot}f" "show_features_popup" "[c]rate [f]eatures")
(keymap "${keyroot}d" "show_dependencies_popup" "[c]rate [d]eps")
(keymap "K" "show_popup" "[c]rate popup")
];
# }}}
}
# }}}
];
};
# }}}
# }}}
# }}}
2023-12-10 12:55:54 +01:00
# {{{ external
# These plugins integrate neovim with external services
# {{{ wakatime
satellite.neovim.lazy.wakatime = {
package = "wakatime/vim-wakatime";
env.blacklist = [ "vscode" "firenvim" ];
event = "VeryLazy";
};
# }}}
# {{{ discord rich presence
satellite.neovim.lazy.discord-rich-presence = {
package = "andweeb/presence.nvim";
main = "presence";
env.blacklist = [ "vscode" "firenvim" ];
event = "VeryLazy";
setup = true;
};
# }}}
# {{{ gitlinker
# generate permalinks for code
satellite.neovim.lazy.gitlinker =
let mapping = "<leader>yg";
in
{
package = "ruifm/gitlinker.nvim";
dependencies.lua = [ lazy.plenary.package ];
env.blacklist = [ "vscode" "firenvim" ];
opts.mappings = mapping;
keys = mapping;
};
# }}}
# {{{ paperplanes
# export to pastebin like services
satellite.neovim.lazy.paperlanes = {
package = "rktjmp/paperplanes.nvim";
cmd = "PP";
opts.provider = "paste.rs";
};
# }}}
# }}}
2023-12-02 12:16:33 +01:00
# }}}
2023-01-10 02:38:06 +01:00
}