diff --git a/config/default.nix b/config/default.nix new file mode 100644 index 0000000..582e8ce --- /dev/null +++ b/config/default.nix @@ -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 + ]; +} + diff --git a/config/keymaps.nix b/config/keymaps.nix new file mode 100644 index 0000000..e1848c1 --- /dev/null +++ b/config/keymaps.nix @@ -0,0 +1,6 @@ +{ ... }: + +{ + globals.mapleader = " "; +} + diff --git a/config/options.nix b/config/options.nix new file mode 100644 index 0000000..0003751 --- /dev/null +++ b/config/options.nix @@ -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. + }; +} + diff --git a/config/plugins/cmp/cmp.nix b/config/plugins/cmp/cmp.nix new file mode 100644 index 0000000..d865de2 --- /dev/null +++ b/config/plugins/cmp/cmp.nix @@ -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. + "" = "cmp.mapping.select_next_item()"; + "" = "cmp.mapping.select_prev_item()"; + # Scroll through documentation. + "" = "cmp.mapping.scroll_docs(-4)"; + "" = "cmp.mapping.scroll_docs(4)"; + # Confirm selection. + "" = "cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true })"; + # Exit completion. + "" = "cmp.mapping.abort()"; + }; + }; + # Scans the sources array and enable the corresponding plugins if they are known to nixvim. + autoEnableSources = true; + }; +} + diff --git a/config/plugins/editor/bufdelete.nix b/config/plugins/editor/bufdelete.nix new file mode 100644 index 0000000..75dbcdd --- /dev/null +++ b/config/plugins/editor/bufdelete.nix @@ -0,0 +1,23 @@ +{ ... }: + +{ + plugins.bufdelete = { + enable = true; + }; + + keymaps = [ + { + mode = "n"; + key = "bd"; + action = "Bdelete"; + options.desc = "Buffer Delete"; + } + { + mode = "n"; + key = "bw"; + action = "Bwipeout"; + options.desc = "Buffer Wipeout"; + } + ]; +} + diff --git a/config/plugins/editor/comment.nix b/config/plugins/editor/comment.nix new file mode 100644 index 0000000..55a09e7 --- /dev/null +++ b/config/plugins/editor/comment.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + plugins.comment = { + enable = true; + }; +} + diff --git a/config/plugins/editor/neo-tree.nix b/config/plugins/editor/neo-tree.nix new file mode 100644 index 0000000..922a204 --- /dev/null +++ b/config/plugins/editor/neo-tree.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + plugins.neo-tree = { + enable = true; + }; + + keymaps = [ + { + mode = "n"; + key = "\\"; + action = "Neotree toggle"; + options.desc = "Toggle Neotree"; + } + ]; +} + diff --git a/config/plugins/editor/treesitter.nix b/config/plugins/editor/treesitter.nix new file mode 100644 index 0000000..cb1248c --- /dev/null +++ b/config/plugins/editor/treesitter.nix @@ -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; + }; +} + diff --git a/config/plugins/git/gitsigns.nix b/config/plugins/git/gitsigns.nix new file mode 100644 index 0000000..8b2e57d --- /dev/null +++ b/config/plugins/git/gitsigns.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + plugins.gitsigns = { + enable = true; + }; +} + diff --git a/config/plugins/git/lazygit.nix b/config/plugins/git/lazygit.nix new file mode 100644 index 0000000..d3e31d4 --- /dev/null +++ b/config/plugins/git/lazygit.nix @@ -0,0 +1,17 @@ +{ ... }: + +{ + plugins.lazygit = { + enable = true; + }; + + keymaps = [ + { + mode = "n"; + key = "lg"; + action = "LazyGit"; + options.desc = "LazyGit"; + } + ]; +} + diff --git a/config/plugins/lsp/lsp.nix b/config/plugins/lsp/lsp.nix new file mode 100644 index 0000000..1ebfaff --- /dev/null +++ b/config/plugins/lsp/lsp.nix @@ -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 = { + "n" = "open_float"; # Show diagnostics in floating window. + "o" = "goto_prev"; # Jump to previous diagnostic. + "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 + }; + }; + }; +} + diff --git a/config/plugins/snippets/luasnip.nix b/config/plugins/snippets/luasnip.nix new file mode 100644 index 0000000..5a65a43 --- /dev/null +++ b/config/plugins/snippets/luasnip.nix @@ -0,0 +1,12 @@ +{ ... }: + +{ + plugins.luasnip = { + enable = true; + extraConfig = { + enable_autosnippets = true; + store_selection_keys = ""; + }; + }; +} + diff --git a/config/plugins/themes/default.nix b/config/plugins/themes/default.nix new file mode 100644 index 0000000..7ed7d21 --- /dev/null +++ b/config/plugins/themes/default.nix @@ -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') + ''; +} + diff --git a/config/plugins/ui/lualine.nix b/config/plugins/ui/lualine.nix new file mode 100644 index 0000000..3455382 --- /dev/null +++ b/config/plugins/ui/lualine.nix @@ -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"; } ]; + }; + }; +} + diff --git a/config/plugins/utils/telescope.nix b/config/plugins/utils/telescope.nix new file mode 100644 index 0000000..745263b --- /dev/null +++ b/config/plugins/utils/telescope.nix @@ -0,0 +1,19 @@ +{ ... }: + +{ + plugins.telescope = { + enable = true; + + keymaps = { + "ff" = { + action = "find_files"; + options.desc = "Find Files"; + }; + "fb" = { + action = "buffers"; + options.desc = "Buffers"; + }; + }; + }; +} + diff --git a/config/plugins/utils/whichkey.nix b/config/plugins/utils/whichkey.nix new file mode 100644 index 0000000..f21af21 --- /dev/null +++ b/config/plugins/utils/whichkey.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + plugins.which-key = { + enable = true; + }; +} + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9ab516c --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..00c39ef --- /dev/null +++ b/flake.nix @@ -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; + }; + }; + }; +} +