lib: remove dependency on pkgs

This commit is contained in:
Matt Sturgeon 2024-12-15 05:23:06 +00:00
parent 9e6b207401
commit 32027965d8
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
6 changed files with 28 additions and 35 deletions

View file

@ -14,8 +14,8 @@
{
# NOTE: this is the publicly documented flake output we've had for a while
check = import ../lib/tests.nix { inherit lib pkgs; };
# NOTE: user-facing so we must include the legacy `pkgs` argument
helpers = import ../lib { inherit lib pkgs; };
# TODO: no longer needs to be per-system
helpers = import ../lib { inherit lib; };
}
)
);

View file

@ -158,3 +158,18 @@ lib.fix (builders: {
}
);
})
# Removed because it depended on `pkgs`
# Deprecated 2024-09-13; Removed 2024-12-15
//
lib.genAttrs
[
"byteCompileLuaDrv"
"byteCompileLuaFile"
"byteCompileLuaHook"
"writeByteCompiledLua"
"writeLua"
]
(
name:
throw "`${name}` is no longer available directly. You can access it via `withPkgs` or use `${name}With`."
)

View file

@ -1,37 +1,19 @@
{
pkgs ? null,
lib ? pkgs.lib,
lib,
_nixvimTests ? false,
...
}:
lib.fix (
self:
let
# Used when importing parts of our lib
call = lib.callPackageWith {
inherit call pkgs self;
inherit call self;
lib = self.extendedLib;
};
# Define this outside of the attrs to avoid infinite recursion,
# since the final value will have been merged from two places
builders = call ./builders.nix { };
# 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
{
autocmd = call ./autocmd-helpers.nix { };
builders = call ./builders.nix { };
deprecation = call ./deprecation.nix { };
extendedLib = call ./extend-lib.nix { inherit lib; };
keymaps = call ./keymap-helpers.nix { };
@ -42,8 +24,9 @@ lib.fix (
utils = call ./utils.nix { inherit _nixvimTests; };
vim-plugin = call ./vim-plugin.nix { };
# Handle builders, which has some deprecated stuff that depends on `pkgs`
builders = builders // deprecatedBuilders;
# Top-level helper aliases:
# TODO: deprecate some aliases
inherit (self.builders)
writeLua
writeByteCompiledLua
@ -52,9 +35,6 @@ lib.fix (
byteCompileLuaDrv
;
# Top-level helper aliases:
# TODO: deprecate some aliases
inherit (self.deprecation)
getOptionRecursive
mkDeprecatedSubOptionModule

View file

@ -44,9 +44,9 @@ let
dontRun ? false,
}@args:
let
# NOTE: we are importing this just for evalNixvim
helpers = import ../lib {
# NOTE: must match the user-facing functions, so we still include the `pkgs` argument
inherit pkgs lib;
inherit lib;
# TODO: deprecate helpers.enableExceptInTests,
# add a context option e.g. `config.isTest`?
_nixvimTests = true;

View file

@ -57,8 +57,7 @@ in
config = mkMerge [
{
# Make our lib available to the host modules
# NOTE: user-facing so we must include the legacy `pkgs` argument
lib.nixvim = lib.mkDefault (import ../lib { inherit pkgs lib; });
lib.nixvim = lib.mkDefault (import ../lib { inherit lib; });
# Make nixvim's "extended" lib available to the host's module args
_module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib;

View file

@ -8,9 +8,8 @@ default_pkgs: self:
module,
}:
let
# NOTE: user-facing so we must include the legacy `pkgs` argument
helpers = import ../lib { inherit pkgs lib _nixvimTests; };
# NOTE: we are importing this just for evalNixvim
helpers = import ../lib { inherit lib _nixvimTests; };
inherit (helpers.modules) evalNixvim;
mkNvim =