From 4dd2211721b7a68e3a412744626af2c010aaa74d Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Tue, 3 Dec 2024 18:17:33 -0300 Subject: [PATCH] feat: initial commit New neovim configuration, a continuation from https://forge.capytal.company/dot013/environment/commit/a1a9da1ddca5b3560dbc435f37b5e7095493f486, but based on Nix as the plugin/package manager. With a wrapped neovim instance, for better portability. --- .gitignore | 1 + flake.lock | 228 ++++++++++++++++++++++++++++++++++++ flake.nix | 38 ++++++ lua/dot013/init.lua | 10 ++ lua/dot013/options.lua | 58 +++++++++ lua/dot013/plugins/init.lua | 41 +++++++ neovim.nix | 79 +++++++++++++ plugin/init.lua | 1 + 8 files changed, 456 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 lua/dot013/init.lua create mode 100644 lua/dot013/options.lua create mode 100644 lua/dot013/plugins/init.lua create mode 100644 neovim.nix create mode 100644 plugin/init.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e438d40 --- /dev/null +++ b/flake.lock @@ -0,0 +1,228 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1732722421, + "narHash": "sha256-HRJ/18p+WoXpWJkcdsk9St5ZiukCqSDgbOGFa8Okehg=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "9ed2ac151eada2306ca8c418ebd97807bb08f6ac", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "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": [ + "neovim-nightly-overlay", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1730504689, + "narHash": "sha256-hgmguH29K2fvs9szpq2r3pz2/8cJd2LPS+b4tfNFCwE=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "506278e768c2a08bec68eb62932193e341f55c90", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-parts_2": { + "inputs": { + "nixpkgs-lib": [ + "neovim-nightly-overlay", + "hercules-ci-effects", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1712014858, + "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "type": "github" + }, + "original": { + "id": "flake-parts", + "type": "indirect" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "gitignore": "gitignore", + "nixpkgs": [ + "neovim-nightly-overlay", + "nixpkgs" + ], + "nixpkgs-stable": [ + "neovim-nightly-overlay", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1732021966, + "narHash": "sha256-mnTbjpdqF0luOkou8ZFi2asa1N3AA2CchR/RqCNmsGE=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "3308484d1a443fc5bc92012435d79e80458fe43c", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "neovim-nightly-overlay", + "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" + } + }, + "hercules-ci-effects": { + "inputs": { + "flake-parts": "flake-parts_2", + "nixpkgs": [ + "neovim-nightly-overlay", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1730903510, + "narHash": "sha256-mnynlrPeiW0nUQ8KGZHb3WyxAxA3Ye/BH8gMjdoKP6E=", + "owner": "hercules-ci", + "repo": "hercules-ci-effects", + "rev": "b89ac4d66d618b915b1f0a408e2775fe3821d141", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "hercules-ci-effects", + "type": "github" + } + }, + "neovim-nightly-overlay": { + "inputs": { + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "git-hooks": "git-hooks", + "hercules-ci-effects": "hercules-ci-effects", + "neovim-src": "neovim-src", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1733211153, + "narHash": "sha256-Ml7GGmUsaDldssIVE189Sf+PMPRgkkGpj66EvZvy8MI=", + "owner": "nix-community", + "repo": "neovim-nightly-overlay", + "rev": "90426479f3220aadcc01832db56ee8cfa3886671", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "neovim-nightly-overlay", + "type": "github" + } + }, + "neovim-src": { + "flake": false, + "locked": { + "lastModified": 1733163189, + "narHash": "sha256-0NlEbJgUYghWNgp2Iiak8N989Cvjoq87xkeRCagfCeU=", + "owner": "neovim", + "repo": "neovim", + "rev": "49d6cd1da86cab49c7a5a8c79e59d48d016975fa", + "type": "github" + }, + "original": { + "owner": "neovim", + "repo": "neovim", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1733064805, + "narHash": "sha256-7NbtSLfZO0q7MXPl5hzA0sbVJt6pWxxtGWbaVUDDmjs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "31d66ae40417bb13765b0ad75dd200400e98de84", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1733015953, + "narHash": "sha256-t4BBVpwG9B4hLgc6GUBuj3cjU7lP/PJfpTHuSqE+crk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ac35b104800bff9028425fec3b6e8a41de2bbfff", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "neovim-nightly-overlay": "neovim-nightly-overlay", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..9598f64 --- /dev/null +++ b/flake.nix @@ -0,0 +1,38 @@ +{ + description = "My development environment"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay"; + }; + outputs = { + self, + nixpkgs, + ... + }@inputs: let + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + overlays = [ + inputs.neovim-nightly-overlay.overlays.default + ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: let + pkgs = import nixpkgs {inherit system overlays;}; + in + f system pkgs); + in { + packages = forAllSystems (system: pkgs: { + neovim = self.packages.${system}.default; + default = (pkgs.callPackage ./neovim.nix {}); + }); + devShells = forAllSystems (system: pkgs: { + default = pkgs.mkShell { + buildInputs = with pkgs; [ + stylua + ]; + }; + }); + }; +} diff --git a/lua/dot013/init.lua b/lua/dot013/init.lua new file mode 100644 index 0000000..fa9b6d2 --- /dev/null +++ b/lua/dot013/init.lua @@ -0,0 +1,10 @@ +require("dot013.options") + +vim.g.lze = { + --@type fun(name: string) + load = vim.cmd.packadd, + --@type boolean + verbose = true, +} + +require("lze").load("dot013.plugins") diff --git a/lua/dot013/options.lua b/lua/dot013/options.lua new file mode 100644 index 0000000..9844f29 --- /dev/null +++ b/lua/dot013/options.lua @@ -0,0 +1,58 @@ + +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- vim.g.loaded_netrw = 1; +-- vim.g.loaded_netrwPlugin = 1; + +vim.wo.number = true +vim.o.mouse = "a" + +-- True colors +vim.o.termguicolors = true + +-- Enable filetype plugins +vim.o.filetype = "on" + +-- Enable spell checking by default +vim.o.spell = true + +-- Set relative line numbers +vim.o.number = true +vim.o.relativenumber = true +vim.o.signcolumn = "number" + +-- Set indentation +vim.o.expandtab = false +vim.o.tabstop = 4 +vim.o.softtabstop = 4 +vim.o.shiftwidth = 4 +-- vim.o.expandtab = 4; +vim.o.breakindent = true + +-- Scroll off +vim.o.scrolloff = 10 + +-- Line length column +vim.o.colorcolumn = "80" + +-- Sync NeoVim and OS clipboards +vim.o.clipboard = "unnamedplus" + +-- Highlight search +vim.o.hlsearch = false +vim.o.incsearch = true + +-- Save undo history +vim.o.undofile = true + +-- Case-insensitive search, unless \C or capital in search +vim.o.ignorecase = true +vim.o.smartcase = true + +vim.wo.signcolumn = "yes" + +vim.o.updatetime = 250 +vim.o.timeoutlen = 300 + +vim.o.completeopt = "menuone,noselect" diff --git a/lua/dot013/plugins/init.lua b/lua/dot013/plugins/init.lua new file mode 100644 index 0000000..3374c99 --- /dev/null +++ b/lua/dot013/plugins/init.lua @@ -0,0 +1,41 @@ +return { + { + "plenary.nvim", + dep_of = { + "telescope.nvim", + }, + }, + { + "telescope-fzf-native.nvim", + dep_of = { + "telescope.nvim" + }, + }, + { + "telescope.nvim", + cmd = { + "Telescope", + }, + keys = { + { "", function() return require("telescope.builtin").buffers end, "Find existing buffers" }, + { + "/", + function() return require("telescope.builtin").current_buffer_fuzzy_find(require("telescope.themes").get_dropdown({ + windblend = 10, + previewer = false, + })) end, + "Find in current buffer" + }, + { "fr", ":lua require('telescope.builtin').oldfiles()", "Find recent files" }, + { "ff", "Telescope find_files", "Find files" }, + { "fw", ":lua require('telescope.builtin').grep_string()", "Find word" }, + { "fw", "Telescope live_grep","Find word in all files" }, + { "gf", ":lua require('telescope.builtin').git_files()", "Git files" }, + { "fs", ":lua require('telescope.builtin').resume()", "Resume search" }, + }, + after = function () + require("telescope").setup() + require("telescope").load_extension("fzf") + end, + } +} diff --git a/neovim.nix b/neovim.nix new file mode 100644 index 0000000..99b8645 --- /dev/null +++ b/neovim.nix @@ -0,0 +1,79 @@ +{ + symlinkJoin, +makeWrapper, +runCommandLocal, +pkgs, +lib, +}: let + nvimPkg = pkgs.neovim-unwrapped; + + startPlugins = with pkgs; with vimPlugins; [ + lze + (vimUtils.buildVimPlugin { + name = "dot013.nvim"; + src = ./.; + }) + ]; + + optPlugins = with pkgs; with pkgs.vimPlugins; [ + telescope-nvim + telescope-fzf-native-nvim + nvim-treesitter.withAllGrammars + ]; + + foldPlugins = builtins.foldl' (acc: next: acc ++ [ next ] ++ (foldPlugins (next.dependencies or []))) []; + + startPluginsWithDeps = lib.unique (foldPlugins startPlugins); + optPluginsWithDeps = lib.unique (foldPlugins optPlugins); + + packpath = let + packageName = "dot013"; + in runCommandLocal "packpath" {} '' + mkdir -p $out/pack/${packageName}/{start,opt} + + ${lib.concatMapStringsSep "\n" + (plugin: "ln -vsfT ${plugin} $out/pack/${packageName}/start/${lib.getName plugin}") + startPluginsWithDeps} + + ${lib.concatMapStringsSep "\n" + (plugin: "ln -vsfT ${plugin} $out/pack/${packageName}/opt/${lib.getName plugin}") + optPluginsWithDeps} + ''; + + initLua = let + luaPackages = lp: []; + luaEnv = nvimPkg.lua.withPackages luaPackages; + inherit (nvimPkg.lua.pkgs.luaLib) genLuaPathAbsStr genLuaCPathAbsStr; + in pkgs.writeText "init.lua" '' + -- Don't use LUA_PATH and LUA_CPATH, since they leak into the LSP + package.path = "${genLuaPathAbsStr luaEnv};" .. package.path + package.cpath = "${genLuaCPathAbsStr luaEnv};" .. package.cpath + + -- No remote plugins + vim.g.loaded_node_provider = 0 + vim.g.loaded_perl_provider = 0 + vim.g.loaded_python_provider = 0 + vim.g.loaded_python3_provider = 0 + vim.g.loaded_ruby_provider = 0 + + require("dot013") + ''; +in symlinkJoin { + name = "neovim-custom"; + pname = "nvim"; + + paths = [nvimPkg]; + nativeBuildInputs = [makeWrapper]; + postBuild = '' + wrapProgram $out/bin/nvim \ + --add-flags '-u' \ + --add-flags '${initLua}' \ + --add-flags '--cmd' \ + --add-flags "'set packpath^=${packpath} | set runtimepath^=${packpath}'" \ + --set-default NVIM_APPNAME nvim-custom + ''; + + passthru = { + inherit packpath; + }; +} diff --git a/plugin/init.lua b/plugin/init.lua new file mode 100644 index 0000000..cbd6fe4 --- /dev/null +++ b/plugin/init.lua @@ -0,0 +1 @@ +require("dot013")