From c02a6534feea571814aaa74a3b5854b3c426e735 Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Sat, 15 Jul 2023 12:45:54 -0400 Subject: [PATCH] Neovim-in-nix :eyes: --- .../config => cargo/config.toml.nixtemplate | 2 +- flake.nix | 2 +- nix/home-manager/flake.lock | 192 +++++++++++++++++- nix/home-manager/flake.nix | 10 +- nix/home-manager/home.nix | 8 - nix/home-manager/modules/files.nix | 12 +- nix/home-manager/modules/packages/default.nix | 4 +- nix/home-manager/modules/packages/neovim.nix | 113 +++++++++++ .../modules/packages/neovim/core.lua | 34 ++++ .../modules/packages/neovim/pre.lua | 2 + 10 files changed, 357 insertions(+), 22 deletions(-) rename playbooks/roles/rust/files/config => cargo/config.toml.nixtemplate (73%) create mode 100644 nix/home-manager/modules/packages/neovim.nix create mode 100644 nix/home-manager/modules/packages/neovim/core.lua create mode 100644 nix/home-manager/modules/packages/neovim/pre.lua diff --git a/playbooks/roles/rust/files/config b/cargo/config.toml.nixtemplate similarity index 73% rename from playbooks/roles/rust/files/config rename to cargo/config.toml.nixtemplate index 1f4b158..c64626c 100644 --- a/playbooks/roles/rust/files/config +++ b/cargo/config.toml.nixtemplate @@ -7,7 +7,7 @@ opt-level = 3 [target.x86_64-unknown-linux-gnu] linker = "clang" -rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] +rustflags = ["-C", "link-arg=-fuse-ld=@profileDir@/bin/mold"] [registries.crates-io] protocol = "sparse" diff --git a/flake.nix b/flake.nix index f9093bf..10709cf 100644 --- a/flake.nix +++ b/flake.nix @@ -24,7 +24,7 @@ modules = [ { # https://devenv.sh/reference/options/ - packages = [pkgs.hello pkgs.delta pkgs.difftastic pkgs.alejandra]; + packages = [pkgs.hello pkgs.delta pkgs.difftastic pkgs.alejandra pkgs.nodePackages.bash-language-server]; enterShell = '' hello diff --git a/nix/home-manager/flake.lock b/nix/home-manager/flake.lock index 8da9e18..5d01009 100644 --- a/nix/home-manager/flake.lock +++ b/nix/home-manager/flake.lock @@ -38,6 +38,22 @@ "type": "github" } }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1650374568, + "narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "b4a34015c698c7793d592d66adbab377907a2be8", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1667395993, @@ -53,6 +69,24 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1689068808, + "narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "gitignore": { "inputs": { "nixpkgs": [ @@ -82,11 +116,32 @@ ] }, "locked": { - "lastModified": 1689414552, - "narHash": "sha256-FS47yV7VbI2EZ5nDHHuFCH1KFrA8Zh8bnEUUi77VUCU=", + "lastModified": 1689447223, + "narHash": "sha256-A5vQBtWYamvGf3c2IEhAmwIkXBzuzrkpnMYbLvc+lEY=", "owner": "nix-community", "repo": "home-manager", - "rev": "559856748982588a9eda6bfb668450ebcf006ccd", + "rev": "f5b03feb33629cb2b6dd513935637e8cc718a5ba", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "home-manager_2": { + "inputs": { + "nixpkgs": [ + "nixneovim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1689134369, + "narHash": "sha256-0G9dutIvhS/WUr3Awcnqw71g8EVVvvkOhVDnDDbY4Fw=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "e42fb59768f0305085abde0dd27ab5e0cc15420c", "type": "github" }, "original": { @@ -135,6 +190,21 @@ "type": "github" } }, + "nix-flake-tests": { + "locked": { + "lastModified": 1677844186, + "narHash": "sha256-ErJZ/Gs1rxh561CJeWP5bohA2IcTq1rDneu1WT6CVII=", + "owner": "antifuchs", + "repo": "nix-flake-tests", + "rev": "bbd9216bd0f6495bb961a8eb8392b7ef55c67afb", + "type": "github" + }, + "original": { + "owner": "antifuchs", + "repo": "nix-flake-tests", + "type": "github" + } + }, "nix-index-database": { "inputs": { "nixpkgs": [ @@ -155,6 +225,56 @@ "type": "github" } }, + "nixneovim": { + "inputs": { + "flake-utils": "flake-utils_2", + "home-manager": "home-manager_2", + "nix-flake-tests": "nix-flake-tests", + "nixneovimplugins": "nixneovimplugins", + "nixpkgs": "nixpkgs_2", + "nmd": "nmd", + "nmt": "nmt" + }, + "locked": { + "lastModified": 1689258189, + "narHash": "sha256-Ufy02ZXCAzINoD3ued142vQu0BPw3t5wqZNFjkL73Ms=", + "owner": "nixneovim", + "repo": "nixneovim", + "rev": "96ebaeb3e4caae77c227be0f4bac3826a01eeefa", + "type": "github" + }, + "original": { + "owner": "nixneovim", + "repo": "nixneovim", + "type": "github" + } + }, + "nixneovimplugins": { + "inputs": { + "flake-compat": "flake-compat_2", + "flake-utils": [ + "nixneovim", + "flake-utils" + ], + "nixpkgs": [ + "nixneovim", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1688942172, + "narHash": "sha256-LaLr4YrAQNVdgKy/QBSNkb0e/7jWpgrXje/r7gCQy6c=", + "owner": "nixneovim", + "repo": "nixneovimplugins", + "rev": "2120522c517c205dcf1eee9226f86c984c566a7d", + "type": "github" + }, + "original": { + "owner": "nixneovim", + "repo": "nixneovimplugins", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1678875422, @@ -204,6 +324,22 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1689192006, + "narHash": "sha256-QM0f0d8oPphOTYJebsHioR9+FzJcy1QNIzREyubB91U=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2de8efefb6ce7f5e4e75bdf57376a96555986841", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1689282004, "narHash": "sha256-VNhuyb10c9SV+3hZOlxwJwzEGytZ31gN9w4nPCnNvdI=", @@ -219,6 +355,38 @@ "type": "github" } }, + "nmd": { + "flake": false, + "locked": { + "lastModified": 1687627428, + "narHash": "sha256-7zGfXuNS5RHqhpEdz2fwrtqvF86JRo5U1hrxZSYgcm8=", + "owner": "~rycee", + "repo": "nmd", + "rev": "824a380546b5d0d0eb701ff8cd5dbafb360750ff", + "type": "sourcehut" + }, + "original": { + "owner": "~rycee", + "repo": "nmd", + "type": "sourcehut" + } + }, + "nmt": { + "flake": false, + "locked": { + "lastModified": 1683843030, + "narHash": "sha256-2K9tFpypgSORyUTRAL7MFRKCXU4GykmhIDrrIydtPdI=", + "owner": "jooooscha", + "repo": "nmt", + "rev": "f30b96093eb056f1bcc60199545344b4e4a72c5a", + "type": "github" + }, + "original": { + "owner": "jooooscha", + "repo": "nmt", + "type": "github" + } + }, "pre-commit-hooks": { "inputs": { "flake-compat": [ @@ -252,7 +420,23 @@ "devenv": "devenv", "home-manager": "home-manager", "nix-index-database": "nix-index-database", - "nixpkgs": "nixpkgs_2" + "nixneovim": "nixneovim", + "nixpkgs": "nixpkgs_3" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" } } }, diff --git a/nix/home-manager/flake.nix b/nix/home-manager/flake.nix index df25184..d616a34 100644 --- a/nix/home-manager/flake.nix +++ b/nix/home-manager/flake.nix @@ -15,6 +15,9 @@ url = "github:Mic92/nix-index-database"; inputs.nixpkgs.follows = "nixpkgs"; }; + nixneovim = { + url = "github:nixneovim/nixneovim"; + }; }; outputs = { @@ -23,6 +26,7 @@ home-manager, devenv, nix-index-database, + nixneovim, ... }: let inherit (nixpkgs.lib) optionalAttrs singleton optionals; @@ -35,6 +39,7 @@ inherit system; # overlays = overlays; config = {allowUnfree = true;}; + overlays = [nixneovim.overlays.default]; } ); @@ -42,7 +47,10 @@ system: { pkgs = pkgs."${system}"; modules = [ - {home.packages = [devenv.packages."${system}".devenv];} + { + imports = [nixneovim.nixosModules.default]; + home.packages = [devenv.packages."${system}".devenv]; + } nix-index-database.hmModules.nix-index ./home.nix ]; diff --git a/nix/home-manager/home.nix b/nix/home-manager/home.nix index 10d9241..c4917b7 100644 --- a/nix/home-manager/home.nix +++ b/nix/home-manager/home.nix @@ -109,14 +109,6 @@ keyScheme = "vim"; }; - programs.neovim = { - enable = false; - # TODO - # init.lua - # fnl dir - # undodir at ~/.undodir - }; - programs.nix-index-database = { comma.enable = true; }; diff --git a/nix/home-manager/modules/files.nix b/nix/home-manager/modules/files.nix index b969e3f..28a4d3f 100644 --- a/nix/home-manager/modules/files.nix +++ b/nix/home-manager/modules/files.nix @@ -7,9 +7,11 @@ home.file.".ideavimrc".source = ../../../ideavim/ideavimrc; xdg.configFile."erdtree/.erdtreerc".source = ../../../erdtree/erdtreerc; xdg.configFile."ov/config.yaml".source = ../../../ov/ov-less.yaml; - # TODO - # git-sync binary - # kitty.conf - # lsd/config.yaml - # cargo config + home.file."bin/git-sync".source = ../../../git-sync; + xdg.configFile."kitty/kitty.conf".source = ../../../kitty/kitty.conf; + xdg.configFile."lsd/config.yaml".source = ../../../lsd/config.yaml; + home.file.".cargo/config.toml".source = pkgs.substituteAll { + src = ../../../cargo/config.toml.nixtemplate; + profileDir = config.home.profileDirectory; + }; } diff --git a/nix/home-manager/modules/packages/default.nix b/nix/home-manager/modules/packages/default.nix index 4b8fd2d..f9c3f65 100644 --- a/nix/home-manager/modules/packages/default.nix +++ b/nix/home-manager/modules/packages/default.nix @@ -8,12 +8,13 @@ systemSpecificPackages = if "${system}" != "aarch64-darwin" # include gping because of open bug - then [pkgs.zsh pkgs.racket pkgs.gping] + then [pkgs.zsh pkgs.racket pkgs.gping pkgs.mold] else []; in { imports = [ ./emacs.nix ./git.nix + ./neovim.nix ./starship.nix ./zellij.nix ]; @@ -43,7 +44,6 @@ in { litecli magic-wormhole-rs ncdu - neovim ov pdm poetry diff --git a/nix/home-manager/modules/packages/neovim.nix b/nix/home-manager/modules/packages/neovim.nix new file mode 100644 index 0000000..475721d --- /dev/null +++ b/nix/home-manager/modules/packages/neovim.nix @@ -0,0 +1,113 @@ +{ + config, + lib, + pkgs, + ... +}: { + programs.nixneovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + extraLuaPreConfig = builtins.readFile ./neovim/pre.lua; + extraConfigLua = builtins.readFile ./neovim/core.lua; + colorscheme = "onedark"; + colorschemes = { + onedark.enable = true; + }; + plugins = { + lsp = { + enable = true; + servers = { + bashls.enable = true; + gopls.enable = true; + jsonls.enable = true; + pyright.enable = true; + rust-analyzer.enable = true; + }; + }; + treesitter = { + enable = true; + indent = true; + folding = true; + incrementalSelection = { + enable = true; + }; + }; + mini = { + enable = true; + ai.enable = true; + align.enable = true; + animate.enable = true; + comment.enable = true; + jump.enable = true; + surround.enable = true; + }; + fugitive = { + enable = true; + }; + undotree = { + enable = true; + }; + which-key = { + enable = true; + }; + project-nvim = { + enable = true; + }; + }; + extraPlugins = + ( + with pkgs.vimPlugins; [ + vim-ReplaceWithRegister + ctrlp-vim + vim-dispatch-neovim + vim-bbye + editorconfig-nvim + vim-expand-region + vim-signify + vim-terraform + leap-nvim + ] + ) + ++ (with pkgs.vimExtraPlugins; [ + nvim-ts-rainbow + ]); + mappings = { + normal = { + "u" = { + action = "vim.cmd.UndotreeToggle"; + }; + "h" = { + action = "function() vim.api.nvim_command('wincmd h') end"; + }; + "j" = { + action = "function() vim.api.nvim_command('wincmd j') end"; + }; + "k" = { + action = "function() vim.api.nvim_command('wincmd k') end"; + }; + "l" = { + action = "function() vim.api.nvim_command('wincmd l') end"; + }; + "" = { + action = "''"; + }; + "" = { + action = "''"; + }; + "n" = { + action = "function() vim.api.nvim_command('nohl') end"; + }; + }; + visual = { + "" = { + action = "''"; + }; + "" = { + action = "''"; + }; + }; + }; + }; +} diff --git a/nix/home-manager/modules/packages/neovim/core.lua b/nix/home-manager/modules/packages/neovim/core.lua new file mode 100644 index 0000000..e44b3ad --- /dev/null +++ b/nix/home-manager/modules/packages/neovim/core.lua @@ -0,0 +1,34 @@ +vim.o.expandtab = true +vim.o.hidden = true +vim.o.ignorecase = true +vim.o.inccommand = "split" +vim.o.list = true +vim.o.listchars = "tab:→ ,eol:¬,trail:•,extends:❯,precedes:❮,space:‣" +vim.o.mouse = "a" +vim.o.number = true +vim.o.relativenumber = true +vim.o.sessionoptions = "blank,curdir,folds,help,tabpages,winsize" +vim.o.shiftwidth = 4 +vim.o.showbreak = "↪" +vim.o.showtabline = 1 +vim.o.signcolumn = "yes" +vim.o.smartcase = true +vim.o.smarttab = true +vim.o.splitbelow = true +vim.o.splitright = true +vim.o.tabstop = 4 +vim.o.termguicolors = true +vim.o.timeoutlen = 500 +vim.o.title = true +vim.o.updatetime = 500 +vim.o.wildmenu = true +vim.o.wildmode = "list:longest,full" + +vim.api.nvim_create_autocmd('TextYankPost', { + callback = function() vim.highlight.on_yank() end +}) + +-- Ctrlp +vim.g.ctrlp_map = "p" +vim.g.ctrlp_cmd = "CtrlPMixed" +vim.g.ctrlp_user_command = "rg --files %s" diff --git a/nix/home-manager/modules/packages/neovim/pre.lua b/nix/home-manager/modules/packages/neovim/pre.lua new file mode 100644 index 0000000..9e34be5 --- /dev/null +++ b/nix/home-manager/modules/packages/neovim/pre.lua @@ -0,0 +1,2 @@ +vim.g.mapleader = " " +vim.g.maplocalleader = ","