From 4b3b67fb6f618726aecea1f07b35c57e4963ea8c Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Sat, 21 Dec 2024 13:40:16 +0000 Subject: [PATCH] lib: make overrideable & access via flake Add a non-system specific `.lib.nixvim` output, which is equivalent to the existing `.lib..helpers` output. This is now also wrapped with `lib.makeOverridable` to allow overriding the function args used to construct the nixvim-lib. Consistently access nixvim-lib via the new flake output, overriding where necessary. --- docs/default.nix | 2 +- flake-modules/lib.nix | 41 +++++++++++++++++++++----------------- flake-modules/packages.nix | 7 ++++++- lib/tests.nix | 4 +--- wrappers/_shared.nix | 8 +------- wrappers/standalone.nix | 6 +----- 6 files changed, 33 insertions(+), 35 deletions(-) diff --git a/docs/default.nix b/docs/default.nix index cfe77c61..45ae3b86 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,4 +1,5 @@ { + helpers, system, nixpkgs, nuschtosSearch, @@ -7,7 +8,6 @@ let # We overlay a few tweaks into pkgs, for use in the docs pkgs = import ./pkgs.nix { inherit system nixpkgs; }; inherit (pkgs) lib; - helpers = import ../lib { inherit lib; }; nixvimPath = toString ./..; diff --git a/flake-modules/lib.nix b/flake-modules/lib.nix index 2d71177f..8fce9a81 100644 --- a/flake-modules/lib.nix +++ b/flake-modules/lib.nix @@ -6,24 +6,29 @@ ... }: { - _module.args.helpers = import ../lib { - inherit lib; - flake = self; + # Expose lib as a flake-parts module arg + _module.args = { + helpers = self.lib.nixvim; }; - # TODO: output lib without pkgs at the top-level - flake.lib = lib.genAttrs config.systems ( - lib.flip withSystem ( - { pkgs, ... }: - { - # NOTE: this is the publicly documented flake output we've had for a while - check = import ../lib/tests.nix { inherit self lib pkgs; }; - # TODO: no longer needs to be per-system - helpers = import ../lib { - inherit lib; - flake = self; - }; - } - ) - ); + # Public `lib` flake output + flake.lib = + { + nixvim = lib.makeOverridable (import ../lib) { + inherit lib; + flake = self; + }; + } + // lib.genAttrs config.systems ( + lib.flip withSystem ( + { pkgs, ... }: + { + # NOTE: this is the publicly documented flake output we've had for a while + check = pkgs.callPackage ../lib/tests.nix { inherit self; }; + + # NOTE: no longer needs to be per-system + helpers = self.lib.nixvim; + } + ) + ); } diff --git a/flake-modules/packages.nix b/flake-modules/packages.nix index 76e5ca3e..3916b0b1 100644 --- a/flake-modules/packages.nix +++ b/flake-modules/packages.nix @@ -1,4 +1,8 @@ -{ inputs, ... }: +{ + inputs, + helpers, + ... +}: { perSystem = { @@ -9,6 +13,7 @@ }: { packages = import ../docs { + inherit helpers; inherit system; inherit (inputs) nixpkgs; inherit (inputs') nuschtosSearch; diff --git a/lib/tests.nix b/lib/tests.nix index d4b46e95..e77e43d2 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -46,9 +46,7 @@ let }@args: let # NOTE: we are importing this just for evalNixvim - helpers = import ../lib { - inherit lib; - flake = self; + helpers = self.lib.nixvim.override { # 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 9d93f9ea..010cc290 100644 --- a/wrappers/_shared.nix +++ b/wrappers/_shared.nix @@ -59,13 +59,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 lib; - flake = self; - } - ); + lib.nixvim = lib.mkDefault self.lib.nixvim; # 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 61eac95c..241b715c 100644 --- a/wrappers/standalone.nix +++ b/wrappers/standalone.nix @@ -9,11 +9,7 @@ default_pkgs: self: }: let # NOTE: we are importing this just for evalNixvim - helpers = import ../lib { - inherit lib _nixvimTests; - flake = self; - }; - + helpers = self.lib.nixvim.override { inherit _nixvimTests; }; inherit (helpers.modules) evalNixvim; mkNvim =