initial config

This commit is contained in:
jdonszelmann 2024-06-24 09:18:36 +02:00
commit cf0052547d
No known key found for this signature in database
GPG key ID: E0C1EA36407B2FF2
4 changed files with 856 additions and 0 deletions

4
README.md Normal file
View file

@ -0,0 +1,4 @@
```
nix run .#home-manager -- switch --flake .#<configuration>
```

328
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
}

44
flake.nix Normal file
View file

@ -0,0 +1,44 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nixvim = {
url = "github:nix-community/nixvim";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, home-manager, nixpkgs, flake-utils, nixvim }:
let
pkgsForSystem = system:
import nixpkgs {
inherit system;
config.allowUnfree = true;
};
mkHomeConfiguration = args:
home-manager.lib.homeManagerConfiguration (rec {
modules = [ (import ./home.nix) nixvim.homeManagerModules.nixvim ]
++ (args.modules or [ ]);
pkgs = pkgsForSystem (args.system or "x86_64-linux");
} // {
inherit (args) extraSpecialArgs;
});
in flake-utils.lib.eachDefaultSystem (system: rec {
formatter = legacyPackages.nixfmt;
legacyPackages = pkgsForSystem system;
}) // {
# non-system suffixed items should go here
nixosModules.home = import ./home.nix; # attr set or list
homeConfigurations.kili = mkHomeConfiguration { extraSpecialArgs = { }; };
inherit home-manager;
inherit (home-manager) packages;
};
}

480
home.nix Normal file
View file

@ -0,0 +1,480 @@
{ config, lib, pkgs, specialArgs, ... }: {
home.stateVersion = "24.05";
home.username = "jonathan";
home.homeDirectory = "/home/jonathan";
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 = "al";
};
surround.enable = true;
cmp-nvim-lsp.enable = true;
lsp-format.enable = true;
fugitive.enable = true;
gitsigns = {
enable = true;
settings = {
current_line_blame = true;
current_line_blame_opts = {
virt_text = true;
virt_text_pos = "eol";
};
};
};
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 = {
cssls.enable = true;
rnix-lsp.enable = true;
nil-ls = {
enable = true;
extraOptions = {
nix = {
maxMemoryMB = 0;
flake = {
autoArchive = true;
autoEvalInputs = true;
nixpkgsInputName = "nixpkgs";
};
};
};
};
clangd = {
enable = false;
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" ];
};
yamlls = {
enable = true;
filetypes = [ "yaml" ];
};
};
inlayHints = true;
keymaps = {
lspBuf = {
"ga" = "code_action";
"<leader>fmt" = "format";
"<leader>h" = "hover";
"<F2>" = "rename";
};
};
};
fidget.enable = true;
comment.enable = true;
floaterm.enable = true;
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
nvim-web-devicons
telescope-ui-select-nvim
telescope-fzf-native-nvim
];
extraConfigLua = ''
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 = 'vsnip' },
}, {
{ name = 'buffer' },
})
}
-- key mapping
local keymap = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
local builtin = require('telescope.builtin')
-- 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, {})
-- vim.keymap.set('n', 'gr', builtin.lsp_references, {})
-- vim.keymap.set('n', 'gd', builtin.lsp_definitions, {})
-- vim.keymap.set('n', 'gi', builtin.lsp_implementations, {})
-- ============ 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)
'';
opts = {
lazyredraw = false;
startofline = true;
showmatch = true;
};
};
# programs.neovim = {
# plugins = with pkgs.vimPlugins; [
# # figure out lsp capabilities (initialized in lspconfig)
# }
# {
# plugin = nvim-lspconfig;
# type = "lua";
# config = let inlay-hint = ''
# on_attach = function(client, bufnr)
# vim.lsp.inlay_hint.enable(true, { bufnr = bufnr })
#
# vim.keymap.set("n", "<leader>h", rt.hover_actions.hover_actions, { buffer = bufnr })
# vim.keymap.set("n", "<leader>g", generate, { buffer = bufnr })
# vim.keymap.set("n", "<leader>em", rt.expand_macro.expand_macro, { buffer = bufnr })
# vim.keymap.set("n", "<F2>", rt.ssr.ssr, { buffer = bufnr })
# end,
# capabilities = capabilities
# ''; in ''
# y
#
# local lsp = require('lspconfig')
# lsp.nil_ls.setup {
# ${inlay-hint},
# cmd = { "${pkgs.nil}/bin/nil" }
# }
# lsp.rust_analyzer.setup {
# cmd = { "${pkgs.rust-analyzer}/bin/rust-analyzer" },
# ${inlay-hint},
# settings = {
# ["rust-analyzer"] = {
# cargo = {
# allFeatures = true,
# loadOutDirsFromCheck = true,
# runBuildScripts = true,
# buildScripts = {
# enable = true,
# },
# },
# -- Add clippy lints for Rust.
# checkOnSave = {
# allFeatures = true,
# command = "clippy",
# extraArgs = { "--no-deps" },
# },
# procMacro = {
# enable = true
# },
# imports = {
# granularity = {
# group = "module",
# },
# prefix = "self",
# },
# },
# },
# }
# lsp.clangd.setup {
# ${inlay-hint},
# cmd = { "${pkgs.llvmPackages_18.clang-unwrapped}/bin/clangd" },
# }
# lsp.lua_ls.setup {
# ${inlay-hint},
# settings = {
# cmd = {"${pkgs.lua-language-server}/bin/lua-language-server"},
# Lua = {
# runtime = {
# -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
# version = 'LuaJIT',
# },
# diagnostics = {
# -- Get the language server to recognize the `vim` global
# globals = { 'vim' },
# },
# workspace = {
# -- Make the server aware of Neovim runtime files
# library = vim.api.nvim_get_runtime_file("", true),
# },
# -- Do not send telemetry data containing a randomized but unique identifier
# telemetry = {
# enable = false,
# },
# },
# },
#
# '';
# };
}