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 # NOTE: this is the publicly documented flake output we've had for a while
check = import ../lib/tests.nix { inherit lib pkgs; }; check = import ../lib/tests.nix { inherit lib pkgs; };
# NOTE: user-facing so we must include the legacy `pkgs` argument # TODO: no longer needs to be per-system
helpers = import ../lib { inherit lib pkgs; }; 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,
lib ? pkgs.lib,
_nixvimTests ? false, _nixvimTests ? false,
...
}: }:
lib.fix ( lib.fix (
self: self:
let let
# Used when importing parts of our lib # Used when importing parts of our lib
call = lib.callPackageWith { call = lib.callPackageWith {
inherit call pkgs self; inherit call self;
lib = self.extendedLib; 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 in
{ {
autocmd = call ./autocmd-helpers.nix { }; autocmd = call ./autocmd-helpers.nix { };
builders = call ./builders.nix { };
deprecation = call ./deprecation.nix { }; deprecation = call ./deprecation.nix { };
extendedLib = call ./extend-lib.nix { inherit lib; }; extendedLib = call ./extend-lib.nix { inherit lib; };
keymaps = call ./keymap-helpers.nix { }; keymaps = call ./keymap-helpers.nix { };
@ -42,8 +24,9 @@ lib.fix (
utils = call ./utils.nix { inherit _nixvimTests; }; utils = call ./utils.nix { inherit _nixvimTests; };
vim-plugin = call ./vim-plugin.nix { }; vim-plugin = call ./vim-plugin.nix { };
# Handle builders, which has some deprecated stuff that depends on `pkgs` # Top-level helper aliases:
builders = builders // deprecatedBuilders; # TODO: deprecate some aliases
inherit (self.builders) inherit (self.builders)
writeLua writeLua
writeByteCompiledLua writeByteCompiledLua
@ -52,9 +35,6 @@ lib.fix (
byteCompileLuaDrv byteCompileLuaDrv
; ;
# Top-level helper aliases:
# TODO: deprecate some aliases
inherit (self.deprecation) inherit (self.deprecation)
getOptionRecursive getOptionRecursive
mkDeprecatedSubOptionModule mkDeprecatedSubOptionModule

View file

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

View file

@ -57,8 +57,7 @@ in
config = mkMerge [ config = mkMerge [
{ {
# Make our lib available to the host modules # 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 lib; });
lib.nixvim = lib.mkDefault (import ../lib { inherit pkgs lib; });
# Make nixvim's "extended" lib available to the host's module args # Make nixvim's "extended" lib available to the host's module args
_module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib; _module.args.nixvimLib = lib.mkDefault config.lib.nixvim.extendedLib;

View file

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