upgrade to more programs and hosts

This commit is contained in:
jdonszelmann 2024-07-06 02:39:24 +02:00
parent 224e199020
commit 1da9036f7b
No known key found for this signature in database
GPG key ID: E0C1EA36407B2FF2
7 changed files with 377 additions and 38 deletions

6
programs/nvim/README.md Normal file
View file

@ -0,0 +1,6 @@
```
nix run .#home-manager -- switch --flake .#<configuration>
```
(even on non-nixos systems. I use this config on archlinux)

523
programs/nvim/default.nix Normal file
View file

@ -0,0 +1,523 @@
{ pkgs, ... }:
let
render-markdown = pkgs.vimUtils.buildVimPlugin {
name = "render-markdown";
src = pkgs.fetchFromGitHub {
owner = "MeanderingProgrammer";
repo = "markdown.nvim";
rev = "78ef39530266b3a0736c48b46c3f5d1ab022c7db";
hash = "sha256-mddnBvIrekHh60Ix6qIYAnv10Mu40LamGI47EXk9wSo=";
};
};
# for lsp/cmp inside markdown code blocks
otter = pkgs.vimUtils.buildVimPlugin {
name = "otter";
src = pkgs.fetchFromGitHub {
owner = "jmbuhr";
repo = "otter.nvim";
rev = "cbb1be0586eae18cbea38ada46af428d2bebf81a";
hash = "sha256-eya/8rG3O8UFeeBRDa5U8v3qay+q3iFwPnYtdX7ptCA=";
};
};
in
{
home = { sessionVariables = { EDITOR = "nvim"; }; };
programs.nixvim = {
enable = true;
globals.mapleader = " ";
globals.maplocalleader = " ";
viAlias = true;
vimAlias = true;
# Highlight and remove extra white spaces
highlight.ExtraWhitespace.bg = "red";
match.ExtraWhitespace = "\\s\\+$";
package = pkgs.neovim-unwrapped;
plugins = {
treesitter = {
enable = true;
indent = true;
nixGrammars = true;
ensureInstalled = "all";
};
surround.enable = true;
cmp-nvim-lsp.enable = true;
lsp-format.enable = true;
fugitive.enable = true;
auto-session = {
enable = true;
extraOptions = {
auto_save_enabled = true;
auto_restore_enabled = true;
# auto_session_use_git_branch = true;
# auto_session_suppress_dirs = [
# "~/"
# "~/Documents"
# "~/Documents/projects"
# "~/src"
# "~/Downloads"
# "/"
# ];
auto_session_pre_save_cmds = [
"Neotree close"
];
};
};
comment = {
enable = true;
settings = {
sticky = true;
toggler = {
line = "gcc";
block = "gbc";
};
opleader = {
line = "gc";
block = "gb";
};
};
};
neo-tree = {
enable = true;
closeIfLastWindow = true;
window = {
position = "right";
width = 30;
mappings = {
"<bs>" = "navigate_up";
"." = "set_root";
"f" = "fuzzy_finder";
"/" = "filter_on_submit";
"h" = "show_help";
};
};
filesystem = {
followCurrentFile.enabled = true;
filteredItems = {
hideHidden = false;
hideDotfiles = false;
forceVisibleInEmptyFolder = true;
hideGitignored = false;
};
};
};
gitsigns = {
enable = true;
settings = {
current_line_blame = true;
current_line_blame_opts = {
virt_text = true;
virt_text_pos = "eol";
};
};
};
typst-vim = {
enable = true;
settings = {
cmd = "${pkgs.typst}/bin/typst";
conceal_math = true;
auto_close_toc = true;
};
};
lualine = {
enable = true;
theme = "onedark";
};
rustaceanvim = {
enable = true;
rustAnalyzerPackage = pkgs.rust-analyzer;
settings = {
auto_attach = true;
server = {
standalone = false;
cmd = [ "rustup" "run" "nightly" "rust-analyzer" ];
settings = {
rust-analyzer = {
inlayHints = { lifetimeElisionHints = { enable = "always"; }; };
check = { command = "clippy"; };
};
cargo = {
buildScripts.enable = true;
features = "all";
runBuildScripts = true;
loadOutDirsFromCheck = true;
};
checkOnSave = {
allFeatures = true;
command = "clippy";
extraArgs = [ "--no-deps" ];
};
procMacro = { enable = true; };
imports = {
granularity = { group = "module"; };
prefix = "self";
};
files = {
excludeDirs =
[ ".cargo" ".direnv" ".git" "node_modules" "target" ];
};
inlayHints = {
bindingModeHints.enable = true;
closureStyle = "rust_analyzer";
closureReturnTypeHints.enable = "always";
discriminantHints.enable = "always";
expressionAdjustmentHints.enable = "always";
implicitDrops.enable = true;
lifetimeElisionHints.enable = "always";
rangeExclusiveHints.enable = true;
};
rustc.source = "discover";
};
diagnostics = {
enable = true;
styleLints.enable = true;
};
};
};
};
# Cargo.toml dependency completion
crates-nvim = {
enable = true;
};
lsp = {
enable = true;
servers = {
astro.enable = true;
cssls.enable = true;
rnix-lsp.enable = true;
nil-ls = {
enable = true;
extraOptions = {
nix = {
maxMemoryMB = 0;
flake = {
autoArchive = true;
autoEvalInputs = true;
nixpkgsInputName = "nixpkgs";
};
};
};
};
clangd = {
enable = true;
filetypes = [ "c" "cpp" "objc" "objcpp" ];
};
eslint = {
enable = true;
filetypes =
[ "javascript" "javascriptreact" "typescript" "typescriptreact" ];
};
html = {
enable = true;
filetypes = [ "html" ];
};
jsonls = {
enable = true;
filetypes = [ "json" "jsonc" ];
};
pyright = {
enable = true;
filetypes = [ "python" ];
};
taplo = {
enable = true;
filetypes = [ "toml" ];
};
bashls = {
enable = true;
filetypes = [ "sh" "bash" ];
};
tsserver = {
enable = true;
filetypes =
[ "javascript" "javascriptreact" "typescript" "typescriptreact" ];
};
marksman.enable = true;
yamlls = {
enable = true;
filetypes = [ "yaml" ];
};
};
inlayHints = true;
keymaps = {
lspBuf = {
"ga" = "code_action";
"<leader>fmt" = "format";
"<leader>h" = "hover";
"<F2>" = "rename";
};
};
};
fidget.enable = true;
floaterm = {
enable = true;
opener = "edit";
width = 0.8;
height = 0.8;
};
telescope = {
enable = true;
extensions.ui-select.enable = true;
extensions.fzf-native.enable = true;
};
cmp.enable = true;
nvim-autopairs.enable = true;
bufferline = {
enable = true;
diagnostics = "nvim_lsp";
};
};
extraPlugins = with pkgs.vimPlugins; [
onedark-nvim
vim-vsnip
cmp-vsnip
cmp-path
nvim-web-devicons
telescope-ui-select-nvim
telescope-fzf-native-nvim
vim-suda
render-markdown
otter
vim-astro
];
extraConfigLua = ''
vim.o.sessionoptions="blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal,localoptions"
vim.cmd([[
let g:astro_typescript = 'enable'
]])
require("render-markdown").setup {
latex_converter = '${pkgs.python312Packages.pylatexenc}/bin/latex2text',
}
local otter = require'otter'
otter.setup{}
vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern = {"*.md"},
callback = function() otter.activate({'python', 'rust', 'c', 'lua', 'bash' }, true, true, nil) end,
})
require("onedark").setup {
style = "deep",
highlights = {
["@comment"] = {fg = '#77B767'}
}
}
require("onedark").load()
local cmp = require("cmp")
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
-- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'path' },
{ name = 'vsnip' },
{ name = "otter" },
}, {
{ name = 'buffer' },
})
}
-- key mapping
local keymap = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
local builtin = require('telescope.builtin')
-- comment
vim.keymap.set("n", "<C-_>", ":lua require('Comment.api').toggle.linewise.current()<CR> j", opts)
-- indent and dedent using tab/shift-tab
vim.keymap.set("n", "<tab>", ">>_")
vim.keymap.set("n", "<s-tab>", "<<_")
vim.keymap.set("i", "<s-tab>", "<c-d>")
vim.keymap.set("v", "<Tab>", ">gv")
vim.keymap.set("v", "<S-Tab>", "<gv")
vim.keymap.set('n', 'gr', builtin.lsp_references, {})
vim.keymap.set('n', 'gd', builtin.lsp_definitions, {})
vim.keymap.set('n', '<leader>d', builtin.diagnostics, {})
vim.keymap.set('n', 'gi', builtin.lsp_implementations, {})
vim.keymap.set('n', 'gt', builtin.lsp_type_definitions, {})
-- format on wq and x and replace X, W and Q with x, w and q
vim.cmd [[cabbrev wq execute "Format sync" <bar> wq]]
vim.cmd [[cabbrev x execute "Format sync" <bar> x]]
vim.cmd [[cnoreabbrev W w]]
vim.cmd [[cnoreabbrev X execute "Format sync" <bar> x]]
vim.cmd [[cnoreabbrev Q q]]
vim.cmd [[nnoremap ; :]]
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader><leader>', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fh', builtin.search_history, {})
local gitsigns = require('gitsigns')
vim.keymap.set('n', '<leader>gr', gitsigns.reset_hunk)
vim.keymap.set('n', '<leader>gd', gitsigns.diffthis)
vim.keymap.set({'o', 'x'}, 'ig', ':<C-U>Gitsigns select_hunk<CR>')
vim.keymap.set('n', '<leader>t', ':Neotree toggle<CR>')
-- ============ files and directories ==============
-- don't change the directory when a file is opened
-- to work more like an IDE
vim.opt.autochdir = false
-- ============ tabs and indentation ==============
-- automatically indent the next line to the same depth as the current line
vim.opt.autoindent = true
vim.opt.smartindent = true
vim.opt.smarttab = true
-- backspace across lines
vim.opt.backspace = { "indent", "eol", "start" }
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
-- ============ line numbers ==============
-- set number,relativenumber
vim.opt.number = true
vim.opt.relativenumber = true
-- ============ history ==============
vim.cmd([[
set undodir=~/.vimdid
set undofile
]])
vim.opt.undofile = true
-- ============ miscelaneous ==============
vim.opt.belloff = "all"
-- show (usually) hidden characters
vim.opt.list = true
vim.opt.listchars = {
nbsp = "¬",
extends = "»",
precedes = "«",
trail = "·",
tab = ">-",
}
-- paste and yank use global system clipboard
vim.opt.clipboard = "unnamedplus"
-- show partial commands entered in the status line
-- (like show "da" when typing "daw")
vim.opt.showcmd = true
vim.opt.mouse = "a"
vim.opt.modeline = true
-- highlight the line with the cursor on it
vim.opt.cursorline = true
-- enable spell checking (todo: plugin?)
vim.opt.spell = false
vim.opt.wrap = false
-- better search
vim.cmd([[
" Better search
set incsearch
set ignorecase
set smartcase
set gdefault
nnoremap <silent> n n:call BlinkNextMatch()<CR>
nnoremap <silent> N N:call BlinkNextMatch()<CR>
function! BlinkNextMatch() abort
highlight JustMatched ctermfg=white ctermbg=magenta cterm=bold
let pat = '\c\%#' . @/
let id = matchadd('JustMatched', pat)
redraw
exec 'sleep 150m'
call matchdelete(id)
redraw
endfunction
nnoremap <silent> <Space> :silent noh<Bar>echo<CR>
nnoremap <silent> <Esc> :silent noh<Bar>echo<CR>
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
" very magic by default
nnoremap ? ?\v
nnoremap / /\v
cnoremap %s/ %sm/
]])
keymap('n', "t", ":FloatermToggle myfloat<CR>", opts)
keymap('t', "<Esc>", "<C-\\><C-n>:q<CR>", opts)
vim.cmd([[
let g:suda_smart_edit = 1
filetype plugin indent on
]])
'';
opts = {
lazyredraw = false;
startofline = true;
showmatch = true;
};
};
}

328
programs/nvim/flake.lock generated Normal file
View file

@ -0,0 +1,328 @@
{
"nodes": {
"devshell": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1717408969,
"narHash": "sha256-Q0OEFqe35fZbbRPPRdrjTUUChKVhhWXz3T9ZSKmaoVY=",
"owner": "numtide",
"repo": "devshell",
"rev": "1ebbe68d57457c8cae98145410b164b5477761f4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "devshell",
"type": "github"
}
},
"flake-compat": {
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"revCount": 57,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
}
},
"flake-compat_2": {
"flake": false,
"locked": {
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1717285511,
"narHash": "sha256-iKzJcpdXih14qYVcZ9QC9XuZYnPc6T8YImb6dX166kw=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "2a55567fcf15b1b1c7ed712a2c6fadaec7412ea8",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1701680307,
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"git-hooks": {
"inputs": {
"flake-compat": "flake-compat_2",
"gitignore": "gitignore",
"nixpkgs": [
"nixvim",
"nixpkgs"
],
"nixpkgs-stable": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1718879355,
"narHash": "sha256-RTyqP4fBX2MdhNuMP+fnR3lIwbdtXhyj7w7fwtvgspc=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "8cd35b9496d21a6c55164d8547d9d5280162b07a",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"nixvim",
"git-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"home-manager": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1719037157,
"narHash": "sha256-aOKd8+mhBsLQChCu1mn/W5ww79ta5cXVE59aJFrifM8=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "cd886711998fe5d9ff7979fdd4b4cbd17b1f1511",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"home-manager_2": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1718788307,
"narHash": "sha256-SqiOz0sljM0GjyQEVinPXQxaGcbOXw5OgpCWGPgh/vo=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "d7830d05421d0ced83a0f007900898bdcaf2a2ca",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"nix-darwin": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1718662658,
"narHash": "sha256-AKG7BsqtVWDlefgzyKz7vjaKTLi4+bmTSBhowbQoZtM=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "29b3096a6e283d7e6779187244cb2a3942239fdf",
"type": "github"
},
"original": {
"owner": "lnl7",
"repo": "nix-darwin",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1719075281,
"narHash": "sha256-CyyxvOwFf12I91PBWz43iGT1kjsf5oi6ax7CrvaMyAo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "a71e967ef3694799d0c418c98332f7ff4cc5f6af",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixvim": {
"inputs": {
"devshell": "devshell",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts",
"git-hooks": "git-hooks",
"home-manager": "home-manager_2",
"nix-darwin": "nix-darwin",
"nixpkgs": [
"nixpkgs"
],
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1719042662,
"narHash": "sha256-xwj8hxu02myIPkNsch/v2NbxuRmuvlcphrbYPECE49c=",
"owner": "nix-community",
"repo": "nixvim",
"rev": "49452662b7b4dd2467cbac19e0f9820d570d8976",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixvim",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"home-manager": "home-manager",
"nixpkgs": "nixpkgs",
"nixvim": "nixvim"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1718522839,
"narHash": "sha256-ULzoKzEaBOiLRtjeY3YoGFJMwWSKRYOic6VNw2UyTls=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "68eb1dc333ce82d0ab0c0357363ea17c31ea1f81",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}