From 32027965d8ca7da03ac6215be588cc4884f4b129 Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sun, 15 Dec 2024 05:23:06 +0000 Subject: [PATCH] lib: remove dependency on `pkgs` --- flake-modules/lib.nix | 4 ++-- lib/builders.nix | 15 +++++++++++++++ lib/default.nix | 32 ++++++-------------------------- lib/tests.nix | 4 ++-- wrappers/_shared.nix | 3 +-- wrappers/standalone.nix | 5 ++--- 6 files changed, 28 insertions(+), 35 deletions(-) diff --git a/flake-modules/lib.nix b/flake-modules/lib.nix index cc7cc695..5359199a 100644 --- a/flake-modules/lib.nix +++ b/flake-modules/lib.nix @@ -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; }; } ) ); diff --git a/lib/builders.nix b/lib/builders.nix index 5eaceefb..e5bc605a 100644 --- a/lib/builders.nix +++ b/lib/builders.nix @@ -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`." + ) diff --git a/lib/default.nix b/lib/default.nix index d7534078..3727a6bc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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 diff --git a/lib/tests.nix b/lib/tests.nix index ea9fa32d..6066800c 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -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; diff --git a/wrappers/_shared.nix b/wrappers/_shared.nix index 9bf144b4..b9d4faaa 100644 --- a/wrappers/_shared.nix +++ b/wrappers/_shared.nix @@ -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; diff --git a/wrappers/standalone.nix b/wrappers/standalone.nix index decb53bb..f2862a48 100644 --- a/wrappers/standalone.nix +++ b/wrappers/standalone.nix @@ -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 =