From a4cc5d9b9cbfb78a5d22e22706d1803e906e1379 Mon Sep 17 00:00:00 2001 From: LeMarsu Date: Tue, 18 Jun 2024 00:19:38 +0200 Subject: [PATCH] feat: can declare extra lua packages --- README.md | 24 +++++++++++++----------- lib/mkNeovimPkg.nix | 15 +++++++++++++-- lib/types.nix | 6 ++++++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index efbd008..dfeff47 100644 --- a/README.md +++ b/README.md @@ -189,6 +189,7 @@ Here's a list of all accepted arguments | `runtime` | `{}` | Your Runtime configuration (see below) | | `dependencies` | `[]` | A list of your dependencies (see below) | | `dependenciesExtraArgs` | `{}` | Extra arguments to load your dependencies in other files | +| `extraLuaPackages` | `null` | Extra lua packages needed for the plugin | | `viAlias` | `false` | Wether to create a `vi` alias to run neovim | | `vimAlias` | `false` | Wether to create a `vim` alias to run neovim | | `vimdiffAlias` | `false` | Wether to create a `vimdiff` alias to run neovim in diff mode | @@ -218,17 +219,18 @@ The dependencies is a list of element of either: The Plugin configuration object accepts the following properties: -| name | default | description | -|----------------|---------|----------------------------------------------------------------| -| `plugin` | N/A | The plugin to load² **REQUIRED** | -| `init` | `null` | Lua code (as string of path) to call before loading the plugin | -| `config` | `null` | Lua code (as string of path) to call after loading the plugin | -| `dependencies` | `[]` | The plugin dependencies³ | -| `lazy` | `false` | Should the plugin be loaded lazily | -| `cmd` | `[]` | Command to put as place_holder to load the lazy plugin⁴ | -| `ft` | `[]` | Filetype to watch to load the lazy plugin⁴ | -| `events` | `[]` | Events to watch to load the lazy plugin⁴⁵ | -| `keymaps` | `[]` | Keymaps that when press will load the lazy plugin⁴⁶ | +| name | default | description | +|--------------------|---------|----------------------------------------------------------------| +| `plugin` | N/A | The plugin to load² **REQUIRED** | +| `init` | `null` | Lua code (as string of path) to call before loading the plugin | +| `config` | `null` | Lua code (as string of path) to call after loading the plugin | +| `dependencies` | `[]` | The plugin dependencies³ | +| `extraLuaPackages` | `null` | Extra lua packages needed for the plugin | +| `lazy` | `false` | Should the plugin be loaded lazily | +| `cmd` | `[]` | Command to put as place_holder to load the lazy plugin⁴ | +| `ft` | `[]` | Filetype to watch to load the lazy plugin⁴ | +| `events` | `[]` | Events to watch to load the lazy plugin⁴⁵ | +| `keymaps` | `[]` | Keymaps that when press will load the lazy plugin⁴⁶ | > ² The plugin can be either a nix package or an object with only `name` and > `src` as properties. The latter will be used to create a nix package of your diff --git a/lib/mkNeovimPkg.nix b/lib/mkNeovimPkg.nix index ac1a3c3..c1366f8 100644 --- a/lib/mkNeovimPkg.nix +++ b/lib/mkNeovimPkg.nix @@ -6,6 +6,7 @@ package ? pkgs.neovim-unwrapped, dependencies ? [], dependenciesExtraArgs ? {}, + extraLuaPackages ? (_: []), runtime ? null, init ? null, viAlias ? false, @@ -14,10 +15,10 @@ nvimdiffAlias ? false, ... } @ config: let - inherit (builtins) map isString isPath; + inherit (builtins) isString isPath map; inherit (pkgs) callPackage bash lib; inherit (lib.strings) optionalString; - inherit (lib.lists) optional; + inherit (lib.lists) concatMap optional; inherit (lib.trivial) flip; inherit (lib.attrsets) optionalAttrs; @@ -36,6 +37,14 @@ extractPlugin = p: {inherit (p) optional plugin;}; extractPlugins = map extractPlugin; + extractLuaPackageFn = plugin: + optional (plugin ? extraLuaPackages) plugin.extraLuaPackages; + extractLuaPackagesFn = plugins: let + fnList = concatMap extractLuaPackageFn plugins; + concatPackages = ps: fn: fn ps; + in + ps: concatMap (concatPackages ps) fnList; + buildInit = { init ? null, postInit ? null, @@ -81,6 +90,8 @@ pkgs.neovimUtils.makeNeovimConfig { inherit customRC; plugins = extractPlugins plugins; + extraLuaPackages = ps: + (extractLuaPackagesFn plugins ps) ++ (extraLuaPackages ps); } // {luaRcContent = customRC;}; params = diff --git a/lib/types.nix b/lib/types.nix index 98a37c6..58e90f6 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -72,6 +72,9 @@ in rec { # Ensure thoses plugins are loaded before the current one dependencies = option (list drv); + # Ensure those packages are available + extraLuaPackages = option function; + # Should this plugin be load lazily ? lazy = option bool; @@ -114,6 +117,9 @@ in rec { # Extra argument to pass to dependencies files dependenciesExtraArgs = option (attrs any); + # Ensure those packages are available + extraLuaPackages = option function; + # Runtime configuration runtime = option runtimeType;