Migrate configuration to nixvim

This commit is contained in:
♥ Minnie ♥ 2024-08-04 21:19:37 +08:00
parent be9fe07ba1
commit 8772a4ca32
Signed by: jasmine
GPG key ID: 8563E358D4E8040E
18 changed files with 759 additions and 0 deletions

39
config/default.nix Normal file
View file

@ -0,0 +1,39 @@
{ ... }:
{
imports = [
# General configuration.
./keymaps.nix
./options.nix
# Themes
./plugins/themes/default.nix
# Completion
./plugins/cmp/cmp.nix
# Snippets
./plugins/snippets/luasnip.nix
# Editor plugins and configurations
./plugins/editor/bufdelete.nix
./plugins/editor/comment.nix
./plugins/editor/neo-tree.nix
./plugins/editor/treesitter.nix
# UI plugins
./plugins/ui/lualine.nix
# LSP and formatting
./plugins/lsp/lsp.nix
# Git
./plugins/git/gitsigns.nix
./plugins/git/lazygit.nix
# Utils
./plugins/utils/telescope.nix
./plugins/utils/whichkey.nix
];
}

6
config/keymaps.nix Normal file
View file

@ -0,0 +1,6 @@
{ ... }:
{
globals.mapleader = " ";
}

18
config/options.nix Normal file
View file

@ -0,0 +1,18 @@
{ ... }:
{
config.opts = {
# General
number = true; # Display line numbers.
showmode = false; # Do not show the mode we're editing in.
swapfile = false; # Disable vim swapfile.
clipboard = "unnamedplus"; # Use the clipboard for all operations.
# Tabs & Spaces
tabstop = 2; # Set the width of a tab character.
softtabstop = 2; # Set the number of columns for a tab.
shiftwidth = 2; # Set the number of spaces for each step of (auto)indent.
expandtab = true; # Convert tabs to spaces.
};
}

View file

@ -0,0 +1,38 @@
{ ... }:
{
# Autocompletion plugin
plugins.cmp = {
enable = true;
# Options provided to the require('cmp').setup function.
settings = {
# The sources to use
sources = [
{ name = "nvim_lsp"; } # LSP source for cmp
{ name = "luasnip"; } # Snippets source for cmp
];
# The snippet expansion function.
snippet.expand = ''
function(args)
require('luasnip').lsp_expand(args.body)
end
'';
# cmp mappings declaration
mapping = {
# Select next/previous item.
"<C-e>" = "cmp.mapping.select_next_item()";
"<C-o>" = "cmp.mapping.select_prev_item()";
# Scroll through documentation.
"<C-s>" = "cmp.mapping.scroll_docs(-4)";
"<C-t>" = "cmp.mapping.scroll_docs(4)";
# Confirm selection.
"<C-CR>" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })";
# Exit completion.
"<C-Esc>" = "cmp.mapping.abort()";
};
};
# Scans the sources array and enable the corresponding plugins if they are known to nixvim.
autoEnableSources = true;
};
}

View file

@ -0,0 +1,23 @@
{ ... }:
{
plugins.bufdelete = {
enable = true;
};
keymaps = [
{
mode = "n";
key = "<leader>bd";
action = "<cmd>Bdelete<cr>";
options.desc = "Buffer Delete";
}
{
mode = "n";
key = "<leader>bw";
action = "<cmd>Bwipeout<cr>";
options.desc = "Buffer Wipeout";
}
];
}

View file

@ -0,0 +1,8 @@
{ ... }:
{
plugins.comment = {
enable = true;
};
}

View file

@ -0,0 +1,17 @@
{ ... }:
{
plugins.neo-tree = {
enable = true;
};
keymaps = [
{
mode = "n";
key = "\\";
action = "<cmd>Neotree toggle<cr>";
options.desc = "Toggle Neotree";
}
];
}

View file

@ -0,0 +1,24 @@
{ pkgs, ... }:
{
# Tree-sitter is a parser generator tool and an incremental parsing library.
plugins.treesitter = {
enable = true;
# Options provided to the require('nvim-treesitter.configs').setup function.
settings = {
highlight = {
enable = true; # Enable syntax highlighing.
};
indent = {
enable = true; # Enable auto indentation.
};
};
# Highlight `extraConfigLua` as lua.
nixvimInjections = true;
# Install all grammar packages.
grammarPackages = pkgs.vimPlugins.nvim-treesitter.allGrammars;
};
}

View file

@ -0,0 +1,8 @@
{ ... }:
{
plugins.gitsigns = {
enable = true;
};
}

View file

@ -0,0 +1,17 @@
{ ... }:
{
plugins.lazygit = {
enable = true;
};
keymaps = [
{
mode = "n";
key = "<leader>lg";
action = "<cmd>LazyGit<cr>";
options.desc = "LazyGit";
}
];
}

View file

@ -0,0 +1,57 @@
{ ... }:
{
plugins.lsp = {
enable = true; # Enable neovim's built-in LSP.
# Configure our language servers
servers = {
# C/C++
clangd = {
enable = true;
};
# Clojure
clojure-lsp = {
enable = true;
};
# Haskell
hls = {
enable = true;
};
# Lua
lua-ls = {
enable = true;
};
# Nix
nil-ls = {
enable = true;
};
# YAML
yamlls = {
enable = true;
};
};
keymaps = {
# nvim-lsp keymaps should be silent
silent = true;
# Configure keymaps for our diagnostics.
diagnostic = {
"<leader>n" = "open_float"; # Show diagnostics in floating window.
"<leader>o" = "goto_prev"; # Jump to previous diagnostic.
"<leader>e" = "goto_next"; # Jump to next diagnostic.
};
# Configure keymaps for our lspbuf.
lspBuf = {
K = "hover"; # Displays hover information¹
gr = "references"; # Lists all the references¹
gd = "definition"; # Jumps to the definition¹
gD = "declaration"; # Jumps to the declaration¹
gi = "implementation"; # Lists all the implementations¹
gt = "type_definition"; # Jumps to the definition of the type¹
# ¹ for the symbol under the cursor
};
};
};
}

View file

@ -0,0 +1,12 @@
{ ... }:
{
plugins.luasnip = {
enable = true;
extraConfig = {
enable_autosnippets = true;
store_selection_keys = "<Tab>";
};
};
}

View file

@ -0,0 +1,15 @@
{ pkgs, ... }:
{
extraPlugins = with pkgs.vimPlugins; [
gruvbox-material
];
extraConfigLua = ''
vim.o.termguicolors = true
vim.g.gruvbox_material_background = 'hard'
vim.g.gruvbox_material_enable_italic = 1
vim.cmd.colorscheme('gruvbox-material')
'';
}

View file

@ -0,0 +1,75 @@
{ ... }:
{
plugins.lualine = {
enable = true;
globalstatus = true;
theme = "gruvbox-material";
# Load our extensions
extensions = [
"nvim-tree"
];
# Icons for our separators
componentSeparators = { left = ""; right = ""; };
sectionSeparators = { left = ""; right = ""; };
# Display components in tabline
tabline.lualine_a = [ { name = "buffers"; } ];
# Lualine has sections as shown below
# +-------------------------------------------------+
# | A | B | C X | Y | Z |
# +-------------------------------------------------+
sections = {
# Section A
lualine_a = [ { name = "mode"; icon = ""; } ];
# Section B
lualine_b = [
# Git branch
{ name = "branch"; icon = ""; }
# Git diff status
{ name = "diff";
extraConfig.symbols = {
added = " ";
modified = " ";
removed = " ";
};
}
# Diagnostic count from nvim_lsp
{ name = "diagnostics";
extraConfig = {
sources = [ "nvim_lsp" ];
symbols = {
error = " ";
warn = " ";
info = " ";
hint = "󰝶 ";
};
};
}
];
# Section C
lualine_c = [ { name = "filename"; extraConfig = { path = 1; }; } ];
# Section X
lualine_x = [
{ name = "encoding"; }
{ name = "fileformat"; }
{ name = "filetype"; }
];
# Section Y
lualine_y = [ { name = "progress"; } ];
# Section Z
lualine_z = [ { name = "location"; } ];
};
};
}

View file

@ -0,0 +1,19 @@
{ ... }:
{
plugins.telescope = {
enable = true;
keymaps = {
"<leader>ff" = {
action = "find_files";
options.desc = "Find Files";
};
"<leader>fb" = {
action = "buffers";
options.desc = "Buffers";
};
};
};
}

View file

@ -0,0 +1,8 @@
{ ... }:
{
plugins.which-key = {
enable = true;
};
}

327
flake.lock Normal file
View file

@ -0,0 +1,327 @@
{
"nodes": {
"devshell": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722113426,
"narHash": "sha256-Yo/3loq572A8Su6aY5GP56knpuKYRvM2a1meP9oJZCw=",
"owner": "numtide",
"repo": "devshell",
"rev": "67cce7359e4cd3c45296fb4aaf6a19e2a9c757ae",
"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-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1722555600,
"narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "8471fe90ad337a8074e957b69ca4d0089218391d",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1719994518,
"narHash": "sha256-pQMhCCHyQGRzdfAkdJ4cIWiw+JNuWsTX7f0ZYSyz0VY=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "9227223f6d922fee3c7b190b2cc238a99527bbb7",
"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"
}
},
"git-hooks": {
"inputs": {
"flake-compat": [
"nixvim",
"flake-compat"
],
"gitignore": "gitignore",
"nixpkgs": [
"nixvim",
"nixpkgs"
],
"nixpkgs-stable": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1721042469,
"narHash": "sha256-6FPUl7HVtvRHCCBQne7Ylp4p+dpP3P/OYuzjztZ4s70=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "f451c19376071a90d8c58ab1a953c6e9840527fd",
"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": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722407237,
"narHash": "sha256-wcpVHUc2nBSSgOM7UJSpcRbyus4duREF31xlzHV5T+A=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "58cef3796271aaeabaed98884d4abaab5d9d162d",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "home-manager",
"type": "github"
}
},
"nix-darwin": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722082646,
"narHash": "sha256-od8dBWVP/ngg0cuoyEl/w9D+TCNDj6Kh4tr151Aax7w=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "0413754b3cdb879ba14f6e96915e5fdf06c6aab6",
"type": "github"
},
"original": {
"owner": "lnl7",
"repo": "nix-darwin",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1722421184,
"narHash": "sha256-/DJBI6trCeVnasdjUo9pbnodCLZcFqnVZiLUfqLH4jA=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "9f918d616c5321ad374ae6cb5ea89c9e04bf3e58",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1722555339,
"narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1722185531,
"narHash": "sha256-veKR07psFoJjINLC8RK4DiLniGGMgF3QMlS4tb74S6k=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "52ec9ac3b12395ad677e8b62106f0b98c1f8569d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixvim": {
"inputs": {
"devshell": "devshell",
"flake-compat": "flake-compat",
"flake-parts": "flake-parts_2",
"git-hooks": "git-hooks",
"home-manager": "home-manager",
"nix-darwin": "nix-darwin",
"nixpkgs": "nixpkgs_2",
"nuschtosSearch": "nuschtosSearch",
"treefmt-nix": "treefmt-nix"
},
"locked": {
"lastModified": 1722531900,
"narHash": "sha256-COtoy+Y/j2QLX818mRI7BweRJOltf0bndxbps/eoH0s=",
"owner": "nix-community",
"repo": "nixvim",
"rev": "7c39d77b9f1fbcbd8f2a575c4f2948dd54efc5c1",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixvim",
"type": "github"
}
},
"nuschtosSearch": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722144272,
"narHash": "sha256-olZbfaEdd+zNPuuyYcYGaRzymA9rOmth8yXOlVm+LUs=",
"owner": "NuschtOS",
"repo": "search",
"rev": "16565307c267ec219c2b5d3494ba66df08e7d403",
"type": "github"
},
"original": {
"owner": "NuschtOS",
"repo": "search",
"type": "github"
}
},
"root": {
"inputs": {
"flake-parts": "flake-parts",
"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"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixvim",
"nixpkgs"
]
},
"locked": {
"lastModified": 1722330636,
"narHash": "sha256-uru7JzOa33YlSRwf9sfXpJG+UAV+bnBEYMjrzKrQZFw=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "768acdb06968e53aa1ee8de207fd955335c754b7",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

48
flake.nix Normal file
View file

@ -0,0 +1,48 @@
{
description = "My personal neovim configuration";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixvim.url = "github:nix-community/nixvim";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs =
{ nixvim, flake-parts, ... }@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
perSystem =
{ pkgs, system, ... }:
let
nixvimLib = nixvim.lib.${system};
nixvim' = nixvim.legacyPackages.${system};
nixvimModule = {
inherit pkgs;
module = import ./config; # import the module directly
# You can use `extraSpecialArgs` to pass additional arguments to your module files
extraSpecialArgs = {
# inherit (inputs) foo;
};
};
nvim = nixvim'.makeNixvimWithModule nixvimModule;
in
{
checks = {
# Run `nix flake check .` to verify that your config is not broken
default = nixvimLib.check.mkTestDerivationFromNixvimModule nixvimModule;
};
packages = {
# Lets you run `nix run .` to start nixvim
default = nvim;
};
};
};
}