From f1991245fe984ea4157dfadcc7b379970dd32713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jalil=20David=20Salam=C3=A9=20Messina?= Date: Sun, 3 Mar 2024 15:20:42 +0100 Subject: [PATCH] feat(nvim): Provide an nixvim standalone config This allows me to test the neovim configuration much easier and also adds neovim checks to the flake. --- README.md | 5 ++ docs/src/configuration-overview.md | 23 +++++++- flake.nix | 20 +++++-- nvim/default.nix | 87 +-------------------------- nvim/nixvim.nix | 95 ++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 92 deletions(-) create mode 100644 nvim/nixvim.nix diff --git a/README.md b/README.md index e75134b..75ee6b2 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ This is only intended for my use, but you can see how I overengineer stuff by looking at it :p (maybe you can also learn some stuff on the way). +This README only has a small amount of information, if you want to see the full +documentation then go to . I +also overengineerd this c: (if you want to copy this for your own project, then +take a look at [the docs folder](./docs/default.nix). + ## Try out in a VM If you already have nix you can run the following commands: diff --git a/docs/src/configuration-overview.md b/docs/src/configuration-overview.md index 932f63a..8141368 100644 --- a/docs/src/configuration-overview.md +++ b/docs/src/configuration-overview.md @@ -20,7 +20,9 @@ inspiration from what I have done c:. First you want to see what your environment is; if you are using NixOS then you want to look at the [NixOS Module Setup](#nixos-module-setup), if you are just using home-manager, then you should look at the [homa-manager Module -Setup](#home-manager-module-setup). +Setup](#home-manager-module-setup). Or if you just want to use my NeoVIM +configuration then look at the [NeoVIM standalone +setup](#neovim-standalone-setup). ### NixOS Module Setup @@ -140,3 +142,22 @@ for more information): }; } ``` + +### NeoVIM Standalone setup + +My NeoVIM configuration is managed by +[NixVIM](https://github.com/nix-community/nixvim), so check that project out if +you want to understand how it works. You can use [this +tutorial](https://nix-community.github.io/nixvim/user-guide/extending-config.html) +to extend my configuration without forking this repo or copying its files. + +If you want to test out my configuration then you can run this handy nix +command: + +```console +$ nix run github:jalil-salame/configuration.nix#nvim +``` + +It will download and build my NeoVIM configuration and run NeoVIM. Alternatively +you can replace `nix run` with `nix shell` which will temporarily add my NeoVIM +configuration to your shell and when you run `nvim` it will launch it. diff --git a/flake.nix b/flake.nix index 37f862c..f556c99 100644 --- a/flake.nix +++ b/flake.nix @@ -55,11 +55,14 @@ inherit system; pkgs = import nixpkgs { inherit system; }; }); - # Module documentation - doc = forEachSupportedSystem ({ pkgs, system }: import ./docs { inherit pkgs lib; }); + overlays = builtins.attrValues self.overlays; in { checks = forEachSupportedSystem ({ pkgs, system }: { + nvim = nixvim.lib.${system}.check.mkTestDerivationFromNixvimModule { + pkgs = import nixpkgs { inherit system overlays; }; + module = ./nvim/nixvim.nix; + }; pre-commit-check = pre-commit-hooks.lib.${system}.run { src = builtins.path { path = ./.; name = "configuration.nix"; }; hooks.typos.enable = true; @@ -67,7 +70,14 @@ }; }); - packages = doc; + packages = forEachSupportedSystem ({ pkgs, system }: { + inherit (import ./docs { inherit pkgs lib; }) docs nixos-markdown nvim-markdown home-markdown; + # Nvim standalone module + nvim = nixvim.legacyPackages.${system}.makeNixvimWithModule { + pkgs = import nixpkgs { inherit system overlays; }; + module = ./nvim/nixvim.nix; + }; + }); # Provide necessary overlays overlays = { @@ -84,11 +94,9 @@ nixosConfigurations.vm = let system = "x86_64-linux"; - overlays = builtins.attrValues self.overlays; config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "steam-original" ]; - # config.allowUnfree = true; pkgs = import nixpkgs { inherit system overlays config; }; in lib.nixosSystem @@ -163,7 +171,7 @@ devShells = forEachSupportedSystem ({ pkgs, system }: { default = pkgs.mkShell { inherit (self.checks.${system}.pre-commit-check) shellHook; - buildInputs = with pkgs; [ just ]; + buildInputs = with pkgs; [ just self.packages.${system}.nvim ]; }; }); }; diff --git a/nvim/default.nix b/nvim/default.nix index 15b31f3..7016339 100644 --- a/nvim/default.nix +++ b/nvim/default.nix @@ -1,90 +1,7 @@ -{ pkgs, config, lib, ... }: -let - cfg = config.jhome.nvim; -in -{ +{ pkgs, ... } @ opts: { imports = [ ./options.nix ]; - config = lib.mkIf cfg.enable { - programs.nixvim = { - enable = true; - package = pkgs.neovim-nightly; - defaultEditor = true; - globals.mapleader = " "; - # Appearance - colorschemes.gruvbox.enable = true; - colorschemes.gruvbox.settings.bold = true; - colorschemes.gruvbox.settings.transparent_mode = true; - colorschemes.gruvbox.settings.terminal_colors = true; - options.number = true; - options.relativenumber = true; - options.colorcolumn = "+1"; - options.cursorline = true; - options.wrap = false; - options.splitright = true; - # Tabs & indentation - options.smarttab = true; - options.autoindent = true; - options.smartindent = true; - # Search path - options.path = ".,/usr/include,**"; - options.wildmenu = true; - options.hlsearch = true; - options.incsearch = true; - options.ignorecase = true; # Search ignores cases - options.smartcase = true; # Unless it has a capital letter - # Enable local configuration :h 'exrc' - options.exrc = true; # safe since nvim 0.9 - plugins = import ./plugins.nix { inherit lib; }; - keymaps = import ./mappings.nix; - inherit (import ./augroups.nix) autoGroups autoCmd; - extraPlugins = with pkgs.vimPlugins; [ - lualine-lsp-progress - nvim-web-devicons - FTerm-nvim - cmp-cmdline - ]; - # Formatting - extraPackages = with pkgs; [ - stylua - shfmt - taplo - yamlfmt - nixpkgs-fmt - rust-analyzer - ]; - extraConfigLuaPre = '' - -- Lua Pre Config - if vim.fn.has 'termguicolors' then - -- Enable RGB colors - vim.g.termguicolors = true - end - - -- Useful function - local has_words_before = function() - -- unpack = unpack or table.unpack - local line, col = unpack(vim.api.nvim_win_get_cursor(0)) - return col ~= 0 - and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil - end - -- END: Lua Pre Config - ''; - extraConfigLuaPost = '' - -- Lua Post Config - do -- Setup cmp-cmdline - local cmp = require "cmp" - cmp.setup.cmdline("/", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources { {name = "rg" }, { name = "buffer" } }, - }) - cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } }) - }) - end - ''; - }; - }; + config.programs.nixvim = (import ./nixvim.nix opts).config; } diff --git a/nvim/nixvim.nix b/nvim/nixvim.nix new file mode 100644 index 0000000..cbe75f7 --- /dev/null +++ b/nvim/nixvim.nix @@ -0,0 +1,95 @@ +{ pkgs, lib, config, ... } @ args: +let + cfg = config.jhome.nvim; + hmAvailable = args ? hmConfig; + nixosAvailable = args ? nixosConfig; + darwinAvailable = args ? darwinConfig; + canSetAsDefault = hmAvailable || nixosAvailable; + notStandalone = hmAvailable || nixosAvailable || darwinAvailable; +in +{ + imports = [ + ./options.nix + ]; + + config = lib.mkMerge [ + (lib.optionalAttrs canSetAsDefault { defaultEditor = lib.mkDefault true; }) + (lib.optionalAttrs notStandalone { enable = lib.mkDefault true; }) + (lib.mkIf cfg.enable { + package = pkgs.neovim-nightly; + globals.mapleader = " "; + # Appearance + colorschemes.gruvbox.enable = true; + colorschemes.gruvbox.settings.bold = true; + colorschemes.gruvbox.settings.transparent_mode = true; + colorschemes.gruvbox.settings.terminal_colors = true; + options.number = true; + options.relativenumber = true; + options.colorcolumn = "+1"; + options.cursorline = true; + options.wrap = false; + options.splitright = true; + # Tabs & indentation + options.smarttab = true; + options.autoindent = true; + options.smartindent = true; + # Search path + options.path = ".,/usr/include,**"; + options.wildmenu = true; + options.hlsearch = true; + options.incsearch = true; + options.ignorecase = true; # Search ignores cases + options.smartcase = true; # Unless it has a capital letter + # Enable local configuration :h 'exrc' + options.exrc = true; # safe since nvim 0.9 + plugins = import ./plugins.nix { inherit lib; }; + keymaps = import ./mappings.nix; + inherit (import ./augroups.nix) autoGroups autoCmd; + extraPlugins = with pkgs.vimPlugins; [ + lualine-lsp-progress + nvim-web-devicons + FTerm-nvim + cmp-cmdline + ]; + # Formatting + extraPackages = with pkgs; [ + stylua + shfmt + taplo + yamlfmt + nixpkgs-fmt + rust-analyzer + ]; + extraConfigLuaPre = '' + -- Lua Pre Config + if vim.fn.has 'termguicolors' then + -- Enable RGB colors + vim.g.termguicolors = true + end + + -- Useful function + local has_words_before = function() + -- unpack = unpack or table.unpack + local line, col = unpack(vim.api.nvim_win_get_cursor(0)) + return col ~= 0 + and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match '%s' == nil + end + -- END: Lua Pre Config + ''; + extraConfigLuaPost = '' + -- Lua Post Config + do -- Setup cmp-cmdline + local cmp = require "cmp" + cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources { {name = "rg" }, { name = "buffer" } }, + }) + cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ { name = "path" } }, { { name = "cmdline" } }) + }) + end + ''; + }) + ]; +}