From 511a328aa307032775710db5993d3b8bc83e1113 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 2 Aug 2024 02:03:07 +0100 Subject: [PATCH] wrappers: add our lib to the host's `_module.args` Make our "extended" lib available to host modules as `_module.args.nixvimLib`. We didn't do this before because `helpers` was too generic of a name, but `nixvimLib` should be ok. { nixvimLib, ... }: { programs.nixvim.someOption = nixvimLib.nixvim.mkRaw "print('Hi')"; } --- docs/user-guide/helpers.md | 12 ++++++++++++ wrappers/_shared.nix | 12 +++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/user-guide/helpers.md b/docs/user-guide/helpers.md index e3e34d4b..1573ccbd 100644 --- a/docs/user-guide/helpers.md +++ b/docs/user-guide/helpers.md @@ -23,6 +23,18 @@ in } ``` +Or you can access the extended `lib` used in standalone builds via the `nixvimLib` module arg: + +```nix +{ nixvimLib, ... }: +{ + # You can use nixvimLib.nixvim in your config + fooOption = nixvimLib.nixvim.mkRaw "print('hello')"; +} +``` + +This "extended" lib, includes everything normally in `lib`, along with some additions from nixvim. + **Note:** the `lib` argument passed to modules is entirely unrelated to the `lib` _option_ accessed as `config.lib`! A certain number of helpers are defined that can be useful: diff --git a/wrappers/_shared.nix b/wrappers/_shared.nix index a707e3ee..b31702ff 100644 --- a/wrappers/_shared.nix +++ b/wrappers/_shared.nix @@ -44,9 +44,15 @@ in ]; config = mkMerge [ - # Make our lib available to the host modules - # TODO: import top-level ../lib - { lib.nixvim = lib.mkDefault (import ../lib/helpers.nix { inherit pkgs lib; }); } + { + # Make our lib available to the host modules + # TODO: import top-level ../lib + lib.nixvim = lib.mkDefault (import ../lib/helpers.nix { inherit pkgs lib; }); + + # Make nixvim's "extended" lib available to the host's module args + _module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib; + } + # Propagate extraFiles to the host modules (optionalAttrs (filesOpt != null) ( mkIf (!cfg.wrapRc) (