mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +02:00
lib: throw when deprecated builders are used on a lib without pkgs
Previously the deprecated builders would warn when used on a lib _with_ `pkgs`, but were simply not present on a lib _without_ `pkgs`. Now, they are always present, but will throw when evaluated on a lib _without_ `pkgs`.
This commit is contained in:
parent
1116ae6332
commit
81ae3febd2
1 changed files with 36 additions and 37 deletions
|
@ -19,53 +19,52 @@ lib.fix (
|
|||
# since the final value will have been merged from two places
|
||||
builders = call ./builders.nix { };
|
||||
|
||||
# Merge in deprecated functions that require a nixpkgs instance
|
||||
# Does shallow recursion, only one level deeper than normal
|
||||
# Does nothing when `pkgs` is null
|
||||
withOptionalFns =
|
||||
if pkgs == null then
|
||||
lib.id
|
||||
else
|
||||
lib.recursiveUpdateUntil
|
||||
(
|
||||
path: lhs: rhs:
|
||||
builtins.length path > 1
|
||||
)
|
||||
{
|
||||
# Minimal specialArgs required to evaluate nixvim modules
|
||||
# FIXME: our minimal specialArgs should not need `pkgs`
|
||||
modules.specialArgs = self.modules.specialArgsWith {
|
||||
defaultPkgs = pkgs;
|
||||
};
|
||||
|
||||
# We used to provide top-level access to the "builder" functions, with `pkgs` already baked in
|
||||
# TODO: deprecated 2024-09-13; remove after 24.11
|
||||
builders = lib.mapAttrs (
|
||||
name:
|
||||
lib.warn "`${name}` is deprecated. You should either use `${name}With` or access `${name}` via `builders.withPkgs`."
|
||||
) (builders.withPkgs pkgs);
|
||||
|
||||
inherit (self.builders)
|
||||
writeLua
|
||||
writeByteCompiledLua
|
||||
byteCompileLuaFile
|
||||
byteCompileLuaHook
|
||||
byteCompileLuaDrv
|
||||
;
|
||||
};
|
||||
# We used to provide top-level access to the "builder" functions, with `pkgs` already baked in
|
||||
# TODO: deprecated 2024-09-13; after 24.11 this can be simplified to always throw
|
||||
deprecatedBuilders = lib.mapAttrs (
|
||||
name: value:
|
||||
let
|
||||
notice = "`${name}` is deprecated";
|
||||
opt = lib.optionalString (pkgs == null) " and not available in this instance of nixvim's lib";
|
||||
advice = "You should either use `${name}With` or access `${name}` via `builders.withPkgs`";
|
||||
msg = "${notice}${opt}. ${advice}.";
|
||||
in
|
||||
if pkgs == null then throw msg else lib.warn msg value
|
||||
) (builders.withPkgs pkgs);
|
||||
in
|
||||
withOptionalFns {
|
||||
{
|
||||
autocmd = call ./autocmd-helpers.nix { };
|
||||
deprecation = call ./deprecation.nix { };
|
||||
extendedLib = call ./extend-lib.nix { inherit lib; };
|
||||
keymaps = call ./keymap-helpers.nix { };
|
||||
lua = call ./to-lua.nix { };
|
||||
modules = call ./modules.nix { };
|
||||
neovim-plugin = call ./neovim-plugin.nix { };
|
||||
options = call ./options.nix { };
|
||||
utils = call ./utils.nix { inherit _nixvimTests; };
|
||||
vim-plugin = call ./vim-plugin.nix { };
|
||||
inherit builders;
|
||||
|
||||
# Handle modules, which currently requires a `defaultPkgs` specialArg
|
||||
# FIXME: our minimal specialArgs should not need `pkgs`
|
||||
modules = call ./modules.nix { } // {
|
||||
# Minimal specialArgs required to evaluate nixvim modules
|
||||
specialArgs = self.modules.specialArgsWith {
|
||||
defaultPkgs =
|
||||
if pkgs == null then
|
||||
throw "`modules.specialArgs` cannot currently be used when nixvim's lib is built without a `pkgs` instance. This will be resolved in the future."
|
||||
else
|
||||
pkgs;
|
||||
};
|
||||
};
|
||||
|
||||
# Handle builders, which has some deprecated stuff that depends on `pkgs`
|
||||
builders = builders // deprecatedBuilders;
|
||||
inherit (self.builders)
|
||||
writeLua
|
||||
writeByteCompiledLua
|
||||
byteCompileLuaFile
|
||||
byteCompileLuaHook
|
||||
byteCompileLuaDrv
|
||||
;
|
||||
|
||||
# Top-level helper aliases:
|
||||
# TODO: deprecate some aliases
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue