Charlotte 🦝 Delenk 2022-08-09 16:30:56 +01:00
parent 7ebb8e948b
commit acc534126e
Signed by: darkkirb
GPG key ID: AB2BD8DAF2E37122
31 changed files with 924 additions and 66 deletions

View file

@ -0,0 +1 @@
Heavily based on https://github.com/syberant/nix-config/tree/master/configuration/home-manager/modules/neovim

View file

@ -0,0 +1,41 @@
{ pkgs, lib, ... }:
with lib;
with builtins;
let
getNixFiles = dir:
let
recu = n: k:
if k == "directory" then
getNixFiles "${dir}/${n}"
else if hasSuffix "nix" n then
[ "${dir}/${n}" ]
else
[ ];
in flatten (mapAttrsToList recu (readDir dir));
in {
imports = getNixFiles ./modules;
treesitter.enable = true;
vim.opt = {
wrap = true;
lbr = true;
timeoutlen = 400;
};
output.path.style = "impure";
output.makeWrapper = "--set LUA_PATH '${./modules/lua}/?.lua;;'";
output.path.path = with pkgs; [ xclip ];
output.extraConfig = ''
" Keybindings
:lua require'keybindings'
" TODO: Set clipboard tool with g:clipboard
'';
}
# TODO:
# https://idie.ru/posts/vim-modern-cpp

View file

@ -1 +1,20 @@
_: {}
{
pkgs,
nix-neovim,
...
}: let
myNeovim = nix-neovim.buildNeovim {
configuration = ./configuration.nix;
inherit pkgs;
};
in {
home.packages = [
myNeovim
# Override necessary here
# Commented for now to try out neovide
# (pkgs.neovim-qt.override { neovim = myNeovim; })
pkgs.neovide
];
}

View file

@ -0,0 +1,43 @@
{
vim.opt = {
# Use 4 spaces and expand tabs
expandtab = true;
tabstop = 4;
softtabstop = 4;
shiftwidth = 4;
cursorline = true; # Highlight line of cursor
number = true; # Line numbering
numberwidth = 3;
undofile = true;
# Searching
ignorecase = true;
smartcase = true;
# Wildmode
wildmenu = true;
wildignorecase = true;
wildignore = [ "*.o" "*~" "*.out" ];
wildmode = [ "longest" "list" "full" ];
};
vim.keybindings.keybindings-shortened = {
j = { command = "gj"; };
k = { command = "gk"; };
"0" = { command = "g0"; };
"$" = { command = "g$"; };
"Y" = {
command = "yy";
mode = "n";
};
};
output.config_file = ''
" Enable 24-bit colours if available
if has('termguicolors')
set termguicolors
endif
'';
}

View file

@ -0,0 +1,11 @@
{ pkgs, lib, config, ... }:
{
vim.keybindings.keybindings-shortened."<leader>gg" = {
command = ":LazyGit<CR>";
label = "lazygit";
};
output.plugins = with pkgs.vimPlugins; [ lazygit-nvim ];
output.path.path = with pkgs; [ lazygit git ];
}

View file

@ -0,0 +1,11 @@
{ pkgs, ... }:
{
vim.g = {
NERDCreateDefaultMappings = 0;
NERDSpaceDelims = 1;
NERDTrimTrailingWhitespace = 1;
};
output.plugins = with pkgs.vimPlugins; [ nerdcommenter ];
}

View file

@ -0,0 +1,25 @@
{ pkgs, ... }:
{
# TODO: Don't let the runner inherit nix-neovim's PATH
vim.g = {
VimuxUseNearest = 0;
VimuxHeight = "30";
VimuxCloseOnExit = true;
};
vim.keybindings.keybindings."<leader>" = {
# It's possible to also use vim-tmux-navigator's :TmuxNavigatePrevious
# Not too keen on it yet though
rr = { command = "<cmd>VimuxRunLastCommand<cr>"; label = "Rerun Command"; };
rp = { command = "<cmd>VimuxPromptCommand<cr>"; label = "Prompt Command"; };
ro = { command = "<cmd>VimuxOpenRunner<cr>"; label = "Open Runner"; };
rq = { command = "<cmd>VimuxCloseRunner<cr>"; label = "Close Runner"; };
ry = { command = "<cmd>VimuxInspectRunner<cr>"; label = "Copy Mode"; };
};
output.plugins = with pkgs.vimPlugins; [ vimux ];
}

View file

@ -0,0 +1,90 @@
{
vim.keybindings = {
leader = " ";
which-key-nvim = true;
# Documented keybindings accessible via SPC
keybindings."<leader>" = {
### LaTeX commands
l = {
# name = "LaTeX";
l = {
command = "<cmd>VimtexCompile<cr>";
label = "Compile";
};
c = {
command = "<cmd>VimtexCountWords<cr>";
label = "Count Words";
};
e = {
command = "<cmd>VimtexErrors<cr>";
label = "Open Errors";
};
v = {
command = "<cmd>VimtexView<cr>";
label = "View";
};
p = {
command = "<cmd>lua require'mdpreview'.open_preview()<cr>";
label = "Pandoc View";
};
};
### Git commands
v = {
# name = "git";
v = {
command = "<cmd>Telescope git_bcommits<cr>";
label = "Buffer Commits";
};
h = {
command = "<cmd>Telescope git_commits<cr>";
label = "Commits";
};
b = {
command = "<cmd>Telescope git_branches<cr>";
label = "Branches";
};
s = {
command = "<cmd>Telescope git_status<cr>";
label = "Status";
};
};
### Documentation commands
d = {
# name = "docs";
v = {
command = "<cmd>Telescope help_tags<cr>";
label = "Vim";
};
m = {
command = "<cmd>Telescope man_pages<cr>";
label = "Man";
};
};
### Miscellaneous
";" = {
mode = "";
command = "<Plug>NERDCommenterToggle";
label = "Toggle Comment";
};
};
# Quick and dirty general keybindings
keybindings-shortened = {
k = { command = "gk"; };
j = { command = "gj"; };
"0" = { command = "g0"; };
"$" = { command = "g$"; };
};
};
}

View file

@ -0,0 +1,48 @@
# Copied from https://github.com/splintah/configuration/blob/7c7bfc2065b1bda84222e8adc9d238eca4ada0e0/vim/plugin/vimtex.vim
{
pkgs,
lib,
config,
...
}:
with lib; {
vim.g = {
vimtex_quickfix_open_on_warning = 0;
vimtex_compiler_latexmk = {
backend = "nvim";
background = 1;
build_dir = "";
callback = 1;
continuous = 1;
executable = "latexmk";
options = [
"-xelatex"
"-verbose"
"-file-line-error"
"-synctex=1"
"-interaction=nonstopmode"
];
};
vimtex_compiler_latexmk_engines = {
"_" = "-xelatex";
"pdflatex" = "-pdf";
"lualatex" = "-lualatex";
"xelatex" = "-xelatex";
"context (pdftex)" = "-pdf -pdflatex=texexec";
"context (luatex)" = "-pdf -pdflatex=context";
"context (xetex)" = ''-pdf -pdflatex="texexec --xtx"'';
};
tex_flavor = "latex";
vimtex_view_general_viewer = "zathura";
};
output.plugins = with pkgs.vimPlugins; [vimtex];
output.path.path = with pkgs; [
pkgs.texlive.combined.scheme-full
procps
zathura
];
}

View file

@ -0,0 +1,5 @@
{ pkgs, ... }:
{
output.plugins = with pkgs.vimPlugins; [ vim-nix ];
}

View file

@ -0,0 +1,123 @@
# Largely copied from a great blog post:
# https://sharksforarms.dev/posts/neovim-rust/
{
pkgs,
lib,
config,
...
}:
with lib; {
vim.opt = {
completeopt = "menuone,noinsert,noselect";
# Set updatetime for CursorHold
# 300ms of no cursor movement to trigger CursorHold
updatetime = 300;
# have a fixed column for the diagnostics to appear in
# this removes the jitter when warnings/errors flow in
signcolumn = "yes";
};
vim.keybindings.keybindings-shortened = {
"K" = {command = "<cmd>lua vim.lsp.buf.hover()<cr>";};
};
vim.g.lightline.component_expand.lsp_status = "LspStatus";
vim.g.lightline.active.right = mkAfter [["lsp_status"]];
# https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/2
output.makeWrapper = "--set RUST_SRC_PATH ${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
output.config_file = ''
set shortmess+=c
lua <<EOF
-- lsp_status
local lsp_status = require('lsp-status')
lsp_status.config({
status_symbol = "",
current_function = false,
-- indicator_errors = 'E',
-- indicator_warnings = 'W',
-- indicator_info = 'i',
-- indicator_hint = '?',
-- indicator_ok = '',
})
lsp_status.register_progress()
function on_attach(client)
lsp_status.on_attach(client)
-- Disable formatting for all LS, let null-ls handle this
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false
end
-- Setup all LSPs
local nvim_lsp = require'lspconfig'
local servers = {'rust_analyzer', 'rnix', 'clangd', 'pyright'}
for _, s in ipairs(servers) do
nvim_lsp[s].setup({
on_attach = on_attach,
capabilities = lsp_status.capabilities,
})
end
-- handle diagnostics
-- https://github.com/nvim-lua/diagnostic-nvim/issues/73
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = true,
signs = true,
update_in_insert = false,
}
)
EOF
" Statusline
function! LspStatus() abort
if luaeval('#vim.lsp.buf_get_clients() > 0')
return luaeval("require('lsp-status').status()")
endif
return ""
endfunction
autocmd InsertLeave,BufEnter,BufWritePost * call lightline#update()
autocmd User LspDiagnosticsChanged call lightline#update()
" Show diagnostic popup on cursor hold
autocmd CursorHold * lua vim.diagnostic.open_float()
" Enable type inlay hints
" FIXME: https://github.com/nvim-lua/lsp_extensions.nvim/issues/30
" autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
" \ lua require'lsp_extensions'.inlay_hints{ prefix = "", highlight = "Comment" }
'';
output.plugins = with pkgs.vimPlugins; [
nvim-lspconfig
lsp_extensions-nvim
lsp-status-nvim
];
output.path.path = with pkgs; [
# Rust
cargo
rustc
rust-analyzer
# Nix
rnix-lsp
# C++
clang-tools
# Python
(writeScriptBin "pyright-langserver" ''
# pyright has a symlinked `./bin` which breaks Nix's `symlinkJoin`
# This wrapper script fixes that.
${pyright}/bin/pyright-langserver $@
'')
];
}

View file

@ -0,0 +1,39 @@
{
pkgs,
lib,
config,
...
}:
with lib; {
output.plugins = with pkgs.vimPlugins; [null-ls-nvim plenary-nvim];
output.config_file = ''
lua << EOF
local n = require'null-ls'
local h = require("null-ls.helpers")
local methods = require("null-ls.methods")
local FORMATTING = methods.internal.FORMATTING
n.setup({
sources = {
n.builtins.formatting.stylua,
n.builtins.formatting.rustfmt,
n.builtins.formatting.nixfmt,
-- https://github.com/jose-elias-alvarez/null-ls.nvim/issues/640
n.builtins.formatting.black.with({ args = { "--quiet", "-" }, }),
},
})
EOF
'';
output.path.path = with pkgs; [
# Formatters
stylua
nixfmt
rustfmt
black
# Linters
];
}

View file

@ -0,0 +1,34 @@
{ pkgs, ... }:
{
output.plugins = with pkgs.vimPlugins; [
nvim-cmp
# Various sources
cmp-path
cmp-buffer
cmp-calc
cmp-nvim-lua
cmp-nvim-lsp
cmp-latex-symbols
cmp-tmux
];
plugin.setup.cmp = {
# TODO: maybe do non-default keybindings?
# See :help cmp-mapping
sources = [
{ name = "path"; }
{ name = "calc"; }
{ name = "nvim_lsp"; }
{ name = "nvim_lua"; }
{ name = "latex_symbols"; }
{ name = "buffer"; }
{
name = "tmux";
option.all_panes = true;
}
];
};
}

View file

@ -0,0 +1,19 @@
{ pkgs, lib, config, ... }:
with lib;
let
cfg = config.treesitter;
grammars = pkgs.tree-sitter.builtGrammars;
in {
options.treesitter.enable = mkEnableOption "tree-sitter";
config = mkIf cfg.enable {
plugin.setup."nvim-treesitter.configs" = {
highlight.enable = true;
};
output.plugins = with pkgs.vimPlugins;
[ (nvim-treesitter.withPlugins (_: pkgs.tree-sitter.allGrammars)) ];
};
}

View file

@ -0,0 +1,17 @@
local wk = require("which-key")
wk.register({
-- File commands
f = {
name = "file",
f = { vim.lsp.buf.formatting, "Format file" },
n = { "<cmd>new", "New File" },
o = { require'telescope-config'.project_files, "Find File" },
l = { require'telescope.builtin'.find_files, "Find Local File" },
h = { require'telescope-config'.home_files, "Find Global File" },
b = { require'telescope-config'.all_buffers, "Switch Buffer" },
["/"] = { "<cmd>Telescope live_grep<cr>", "Grep Project" },
},
}, { prefix = "<leader>" })

View file

@ -0,0 +1,58 @@
-- small script to automatically compile my markdown documents
-- to use put `lua require'mdpreview'.open_preview()` somewhere in your keymappings
-- TODO: Make use of vim.schedule
local M = {}
local Job = require'plenary.job'
local zathura_open = function()
local filename = vim.fn.expand("%:r") .. ".pdf"
Job:new({
command = 'zathura',
args = {filename},
on_exit = function(j, ret_val)
if ret_val ~= 0 then
error("Error while viewing `" .. filename .. "`: " .. ret_val)
end
end,
}):start()
end
M.markdown_compile = function()
local filename = vim.fn.expand("%")
local output = vim.fn.expand("%:r") .. ".pdf"
-- local filename_with_lua = vim.api.nvim_buf_get_name(0)
-- TODO: put non-blocking timeout on these jobs
-- TODO: report errors (from stderr)
Job:new({
command = 'pandoc',
args = {filename, "-o", output},
on_exit = function(j, ret_val)
if ret_val == 0 then
print("Successfully compiled " .. filename)
else
print("Error while compiling " .. filename)
end
end,
-- Timeout of 30 seconds
-- }):sync(30 * 1000)
}):start()
end
M.open_preview = function()
vim.api.nvim_exec([[
augroup mdpreview
autocmd!
au BufWritePost *.md lua require'mdpreview'.markdown_compile()
augroup END
]], false)
M.markdown_compile()
zathura_open()
end
return M

View file

@ -0,0 +1,23 @@
local M = {}
M.project_files = function()
local opts = {} -- define here if you want to define something
local ok = pcall(require'telescope.builtin'.git_files, opts)
if not ok then require'telescope.builtin'.find_files(opts) end
end
M.home_files = function()
require'telescope.builtin'.find_files({
search_dirs = { "~/Literatuur", "~/Documents", "/etc/nixos", "~/.config" },
})
end
M.all_buffers = function()
require'telescope.builtin'.buffers({
show_all_buffers = true,
only_cwd = false,
sort_lastused = true,
})
end
return M

View file

@ -0,0 +1,45 @@
{
pkgs,
lib,
config,
...
}: {
vim.keybindings.keybindings-shortened."<leader>fk" = {
command = ":lua require'telescope'.extensions.file_browser.file_browser(require'telescope.themes'.get_ivy({ initial_mode = 'normal', default_selection_index = 2, }))<CR>";
label = "Browse Files";
};
output.extraConfig = ''
lua << EOF
local tele = require'telescope'
local fba = tele.extensions.file_browser.actions
local tla = require'telescope.actions'
tele.setup {
extensions = {
file_browser = {
mappings = {
["n"] = {
["h"] = fba.goto_parent_dir,
["l"] = tla.select_default,
["e"] = tla.select_default,
-- Misc
["zh"] = fba.toggle_hidden,
["~"] = fba.goto_home_dir,
["`"] = fba.goto_cwd,
["="] = fba.change_cwd,
},
}
}
}
}
tele.load_extension("file_browser")
EOF
'';
output.plugins = [
pkgs.telescope-file-browser-nvim
];
}

View file

@ -0,0 +1,23 @@
{ pkgs, ... }:
{
output.extraConfig = ''
lua <<EOF
local actions = require('telescope.actions')
require('telescope').setup{
defaults = {
mappings = {
i = {
["<esc>"] = actions.close
},
},
}
}
EOF
'';
output.path.path = with pkgs; [ fd ripgrep ];
output.plugins = with pkgs.vimPlugins; [ telescope-nvim ];
}

View file

@ -0,0 +1,11 @@
{ pkgs, ... }:
{
vim.keybindings.which-key-nvim = true;
plugin.setup.which-key = {
# Only start which-key.nvim for these keys
# I was getting sick and tired of it opening on random operators...
triggers = [ "<leader>" "g" "z" "<C-w>" "\"" ];
};
}

View file

@ -0,0 +1,5 @@
{ pkgs, ... }:
{
output.plugins = with pkgs.vimPlugins; [ vim-repeat ];
}

View file

@ -0,0 +1,5 @@
{ pkgs, ... }:
{
output.plugins = with pkgs.vimPlugins; [ vim-surround ];
}

View file

@ -0,0 +1,11 @@
{ pkgs, ... }:
let scheme = "gruvbox";
in {
output.config_file = "colo ${scheme}";
vim.g.lightline.colorscheme = scheme;
vim.g.tokyonight_style = "storm";
output.plugins = with pkgs.vimPlugins; [ gruvbox tokyonight-nvim ];
}

View file

@ -0,0 +1,55 @@
{ pkgs, ... }:
{
vim.g = {
dashboard_custom_footer = [
"It's pretty hard to tell what does bring happiness; poverty and wealth"
"have both failed."
" -- Kim Hubbard"
];
dashboard_custom_header = [
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
];
dashboard_enable_session = false;
dashboard_default_executive = "telescope";
dashboard_custom_section = {
"1_oldfiles" = {
description = [ " Open History -" ];
command = "Telescope oldfiles";
};
"2_find_files" = {
description = [ " Find File SPC f o" ];
command = "Telescope find_files";
};
"3_new_file" = {
description = [ " New File -" ];
command = "enew";
};
"4_lazygit" = {
description = [ " lazygit SPC g g" ];
command = "LazyGit";
};
"5_live_grep" = {
description = [ " Live Grep SPC f /" ];
command = "Telescope live_grep";
};
};
};
output.plugins = with pkgs.vimPlugins; [ dashboard-nvim ];
}

View file

@ -0,0 +1,11 @@
{ pkgs, ... }:
{
plugin.setup.gitsigns = {
# Disable default keybindings
keymaps = {};
};
output.plugins = with pkgs.vimPlugins; [ gitsigns-nvim ];
output.path.path = with pkgs; [ git ];
}

View file

@ -0,0 +1,18 @@
{ pkgs, ... }:
{
vim.opt.showmode = false;
vim.g.lightline = {
active = {
left = [ [ "mode" "paste" ] [ "readonly" "filename" "modified" ] ];
right = [
[ "lineinfo" ]
[ "percent" ]
[ "fileformat" "fileencoding" "filetype" ]
];
};
};
output.plugins = with pkgs.vimPlugins; [ lightline-vim ];
}

View file

@ -0,0 +1,11 @@
{ pkgs, ... }:
{
vim.keybindings.keybindings-shortened = {
"<leader>gt" = { command = "<cmd>TodoTelescope<cr>"; };
};
plugin.setup.todo-comments = {};
output.plugins = with pkgs.vimPlugins; [ todo-comments-nvim ];
}

View file

@ -0,0 +1,12 @@
{
output.extraConfig = ''
" Highlight trailing whitespace
" https://idie.ru/posts/vim-modern-cpp
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
au BufWinEnter * match ExtraWhitespace /\s\+$/
au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
au InsertLeave * match ExtraWhitespace /\s\+$/
au BufWinLeave * call clearmatches()
'';
}

View file

@ -10,7 +10,8 @@ with pkgs; let
noto-variable = import nixpkgs-noto-variable {inherit system;};
in {
nixpkgs.overlays = [
(self: prev: {
(self: prev:
{
hydra-unstable = nix-packages.packages.${system}.hydra;
mosh = prev.mosh.overrideAttrs (old: {
patches = [
@ -33,7 +34,6 @@ in {
};
});
inherit (noto-variable) noto-fonts-cjk;
inherit (nix-packages.packages.${system}) plover plover-plugins-manager plover-emoji plover-tapey-tape plover-yaml-dictionary lotte-art plover-machine-hid mautrix-telegram mautrix-signal;
kitty = prev.kitty.overrideAttrs (old: {
patches =
old.patches
@ -75,6 +75,7 @@ in {
checkPhase = "true";
installCheckPhase = "true";
});
})
}
// nix-packages.packages.${system})
];
}

View file

@ -784,6 +784,26 @@
"type": "github"
}
},
"nix-neovim": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1650651888,
"narHash": "sha256-2lC6oeQMTke7/bx8VxLNJr54A/WGkdAv2H0iebTmACY=",
"owner": "syberant",
"repo": "nix-neovim",
"rev": "6f03a1c206ff2c5bea209c73f861ebd8088de53b",
"type": "github"
},
"original": {
"owner": "syberant",
"repo": "nix-neovim",
"type": "github"
}
},
"nix-packages": {
"inputs": {
"cargo2nix": "cargo2nix_2",
@ -810,16 +830,17 @@
],
"nixpkgs-go116": "nixpkgs-go116",
"nixpkgs-stable": "nixpkgs-stable",
"nvim-telescope-file-browser": "nvim-telescope-file-browser",
"plover": "plover",
"plover-machine-hid": "plover-machine-hid",
"steno-dictionaries": "steno-dictionaries"
},
"locked": {
"lastModified": 1660031673,
"narHash": "sha256-6k6xQf2VQqjdSvuJHrXqcpxi/dgbbZm/dov8f/GC6lg=",
"lastModified": 1660058797,
"narHash": "sha256-uaN4uNBJDPuae4e0P+y6EZye8/p3KxrP7Qw1yyOUobU=",
"ref": "main",
"rev": "3920fadc24af61decb3a07511c8eb3e206b7db8f",
"revCount": 187,
"rev": "69f22bd867480bc9c1eb39a22240e68317c220ea",
"revCount": 188,
"type": "git",
"url": "https://git.chir.rs/DarkKirb/nix-packages"
},
@ -1145,6 +1166,22 @@
"type": "github"
}
},
"nvim-telescope-file-browser": {
"flake": false,
"locked": {
"lastModified": 1659376895,
"narHash": "sha256-LYkyvjv6LO39c49s5fjzfdzRVRHrtTI1dweaZMFPLVc=",
"owner": "nvim-telescope",
"repo": "telescope-file-browser.nvim",
"rev": "4272c52078cc457dfaabce6fa3545e7495651d04",
"type": "github"
},
"original": {
"owner": "nvim-telescope",
"repo": "telescope-file-browser.nvim",
"type": "github"
}
},
"plover": {
"flake": false,
"locked": {
@ -1208,6 +1245,7 @@
"flake-utils": "flake-utils_4",
"home-manager": "home-manager",
"hosts-list": "hosts-list",
"nix-neovim": "nix-neovim",
"nix-packages": "nix-packages",
"nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs_9",

View file

@ -20,6 +20,11 @@ rec {
nixpkgs-noto-variable.url = "github:NixOS/nixpkgs/1988f9a17fc1c2ab11f5817adf34a4eb8d06454d";
emanote.url = "github:EmaApps/emanote";
nix-neovim = {
url = "github:syberant/nix-neovim";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-packages.url = "git+https://git.chir.rs/DarkKirb/nix-packages?ref=main";
nix-packages.inputs.nixpkgs.follows = "nixpkgs";
};