mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib: provide an "extended lib" to our modules
lib/extend-lib.nix returns a nixpkg's lib extended with our own helpers. This is exposed as `helpers.extendedLib`, but when evaluating our modules it should be assigned to `specialArgs.lib`. Outside of our modules you must still access our helpers via `config.lib.nixvim` or `config.lib.nixvim.extendedLib`. Within helpers' sub-sections, `lib` is the extended lib.
This commit is contained in:
parent
7c39d77b9f
commit
491ca5cf51
7 changed files with 49 additions and 2 deletions
11
lib/extend-lib.nix
Normal file
11
lib/extend-lib.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Extends nixpkg's lib with our functions, as expected by our modules
|
||||||
|
{ lib, helpers }:
|
||||||
|
lib.extend (
|
||||||
|
final: prev: {
|
||||||
|
# Include our custom lib
|
||||||
|
nixvim = helpers;
|
||||||
|
|
||||||
|
# Merge in our maintainers
|
||||||
|
maintainers = prev.maintainers // import ./maintainers.nix;
|
||||||
|
}
|
||||||
|
)
|
|
@ -6,16 +6,20 @@
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
# Used when importing parts of helpers
|
# Used when importing parts of helpers
|
||||||
call = lib.callPackageWith { inherit pkgs lib helpers; };
|
call = lib.callPackageWith {
|
||||||
|
# TODO: deprecate/remove using `helpers` in the subsections
|
||||||
|
inherit pkgs helpers;
|
||||||
|
lib = helpers.extendedLib;
|
||||||
|
};
|
||||||
|
|
||||||
# Build helpers recursively
|
# Build helpers recursively
|
||||||
helpers = {
|
helpers = {
|
||||||
autocmd = call ./autocmd-helpers.nix { };
|
autocmd = call ./autocmd-helpers.nix { };
|
||||||
builders = call ./builders.nix { };
|
builders = call ./builders.nix { };
|
||||||
deprecation = call ./deprecation.nix { };
|
deprecation = call ./deprecation.nix { };
|
||||||
|
extendedLib = call ./extend-lib.nix { inherit lib; };
|
||||||
keymaps = call ./keymap-helpers.nix { };
|
keymaps = call ./keymap-helpers.nix { };
|
||||||
lua = call ./to-lua.nix { };
|
lua = call ./to-lua.nix { };
|
||||||
maintainers = import ./maintainers.nix;
|
|
||||||
neovim-plugin = call ./neovim-plugin.nix { };
|
neovim-plugin = call ./neovim-plugin.nix { };
|
||||||
nixvimTypes = call ./types.nix { };
|
nixvimTypes = call ./types.nix { };
|
||||||
options = call ./options.nix { };
|
options = call ./options.nix { };
|
||||||
|
@ -78,6 +82,9 @@ let
|
||||||
wrapVimscriptForLua
|
wrapVimscriptForLua
|
||||||
;
|
;
|
||||||
|
|
||||||
|
# TODO: Deprecate this `maintainers` alias
|
||||||
|
inherit (helpers.extendedLib) maintainers;
|
||||||
|
|
||||||
toLuaObject = helpers.lua.toLua;
|
toLuaObject = helpers.lua.toLua;
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
|
|
25
tests/test-sources/extended-lib.nix
Normal file
25
tests/test-sources/extended-lib.nix
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
let
|
||||||
|
module =
|
||||||
|
{ lib, helpers, ... }:
|
||||||
|
{
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = lib ? nixvim;
|
||||||
|
message = "lib.nixvim should be defined";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion = lib.nixvim == helpers;
|
||||||
|
message = "lib.nixvim and helpers should be aliases";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
top-level = {
|
||||||
|
inherit module;
|
||||||
|
};
|
||||||
|
|
||||||
|
files-module = {
|
||||||
|
files."libtest.lua" = module;
|
||||||
|
};
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ in
|
||||||
darwinConfig = config;
|
darwinConfig = config;
|
||||||
defaultPkgs = pkgs;
|
defaultPkgs = pkgs;
|
||||||
helpers = config.lib.nixvim;
|
helpers = config.lib.nixvim;
|
||||||
|
lib = config.lib.nixvim.extendedLib;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
./modules/darwin.nix
|
./modules/darwin.nix
|
||||||
|
|
|
@ -26,6 +26,7 @@ in
|
||||||
hmConfig = config;
|
hmConfig = config;
|
||||||
defaultPkgs = pkgs;
|
defaultPkgs = pkgs;
|
||||||
helpers = config.lib.nixvim;
|
helpers = config.lib.nixvim;
|
||||||
|
lib = config.lib.nixvim.extendedLib;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
./modules/hm.nix
|
./modules/hm.nix
|
||||||
|
|
|
@ -27,6 +27,7 @@ in
|
||||||
nixosConfig = config;
|
nixosConfig = config;
|
||||||
defaultPkgs = pkgs;
|
defaultPkgs = pkgs;
|
||||||
helpers = config.lib.nixvim;
|
helpers = config.lib.nixvim;
|
||||||
|
lib = config.lib.nixvim.extendedLib;
|
||||||
};
|
};
|
||||||
modules = [
|
modules = [
|
||||||
./modules/nixos.nix
|
./modules/nixos.nix
|
||||||
|
|
|
@ -31,6 +31,7 @@ let
|
||||||
];
|
];
|
||||||
specialArgs = {
|
specialArgs = {
|
||||||
inherit helpers;
|
inherit helpers;
|
||||||
|
lib = helpers.extendedLib;
|
||||||
defaultPkgs = pkgs;
|
defaultPkgs = pkgs;
|
||||||
} // extraSpecialArgs;
|
} // extraSpecialArgs;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue