diff --git a/lib/default.nix b/lib/default.nix index 904d5a0e..6f73231c 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -2,7 +2,6 @@ lib, flake, _isExtended ? false, - _nixvimTests ? false, }: lib.makeExtensible ( self: @@ -25,7 +24,7 @@ lib.makeExtensible ( modules = call ./modules.nix { inherit flake; }; options = call ./options.nix { }; plugins = call ./plugins { }; - utils = call ./utils.nix { inherit _nixvimTests; } // call ./utils.internal.nix { }; + utils = call ./utils.nix { } // call ./utils.internal.nix { }; # Top-level helper aliases: # TODO: deprecate some aliases diff --git a/lib/tests.nix b/lib/tests.nix index b4179631..4bc9b178 100644 --- a/lib/tests.nix +++ b/lib/tests.nix @@ -15,7 +15,6 @@ let ... }: let - # FIXME: this doesn't support helpers.enableExceptInTests, a context option would be better result = nvim.extend { config.test = { inherit name; @@ -35,20 +34,13 @@ let extraSpecialArgs ? { }, }: let - # NOTE: we are importing this just for evalNixvim - helpers = self.lib.nixvim.override { - # TODO: deprecate helpers.enableExceptInTests, - # add a context option e.g. `config.isTest`? - _nixvimTests = true; - }; - systemMod = if pkgs == null then { nixpkgs.hostPlatform = lib.mkDefault { inherit system; }; } else { nixpkgs.pkgs = lib.mkDefault pkgs; }; - result = helpers.modules.evalNixvim { + result = self.lib.evalNixvim { modules = [ module (lib.optionalAttrs (name != null) { test.name = name; }) diff --git a/lib/utils.nix b/lib/utils.nix index d218220b..5df425b0 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -1,7 +1,4 @@ -{ - lib, - _nixvimTests, -}: +{ lib }: rec { /** Transforms a list to an _"unkeyed"_ attribute set. @@ -23,15 +20,14 @@ rec { builtins.listToAttrs (lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list); /** - Usually `true`, except when nixvim is being evaluated by - `mkTestDerivationFromNixvimModule`, where it is `false`. + Usually `true`, except within the `build.test` option, where it is `false`. This can be used to dynamically enable plugins that can't be run in the test environment. */ # TODO: replace and deprecate # We shouldn't need to use another instance of `lib` when building a test drv - enableExceptInTests = !_nixvimTests; + enableExceptInTests = true; /** An empty lua table `{ }` that will be included in the final lua configuration. diff --git a/modules/top-level/test.nix b/modules/top-level/test.nix index f1e4d9b0..c48fd7d6 100644 --- a/modules/top-level/test.nix +++ b/modules/top-level/test.nix @@ -3,6 +3,8 @@ config, options, lib, + helpers, + extendModules, ... }: let @@ -263,9 +265,36 @@ in config = let + # Reevaluate the nixvim configuration in "test mode" + # This allows users to use `lib.nixvim.enableExceptInTests` + testConfiguration = + let + # TODO: replace and deprecate enableExceptInTests + # We shouldn't need to use another instance of `lib` when building a test drv + # Maybe add a context option e.g. `config.isTest`? + nixvimLibOverlay = final: prev: { + utils = prev.utils // { + enableExceptInTests = false; + }; + }; + extendedConfiguration = extendModules { + specialArgs = { + lib = lib.extend ( + final: prev: { + nixvim = prev.nixvim.extend nixvimLibOverlay; + } + ); + helpers = helpers.extend nixvimLibOverlay; + }; + }; + in + if lib.nixvim.enableExceptInTests then extendedConfiguration else { inherit config options; }; + input = { - inherit (config) warnings; - assertions = builtins.concatMap (x: lib.optional (!x.assertion) x.message) config.assertions; + inherit (testConfiguration.config) warnings; + assertions = builtins.concatMap ( + x: lib.optional (!x.assertion) x.message + ) testConfiguration.config.assertions; }; expectationMessages = @@ -323,7 +352,7 @@ in nativeBuildInputs = cfg.extraInputs ++ lib.optionals cfg.buildNixvim [ - config.build.nvimPackage + testConfiguration.config.build.nvimPackage ]; inherit (failedExpectations) warnings assertions; @@ -335,7 +364,8 @@ in # # Yes, three levels of `entries` is cursed. passthru = { - inherit config options; + inherit (testConfiguration) config options; + configuration = testConfiguration; }; } ( diff --git a/tests/enable-except-in-tests.nix b/tests/enable-except-in-tests.nix index b8811894..dfa036cb 100644 --- a/tests/enable-except-in-tests.nix +++ b/tests/enable-except-in-tests.nix @@ -15,9 +15,8 @@ let { assertions = [ { - # FIXME: should be false - assertion = lib.nixvim.enableExceptInTests; - message = "Expected lib.nixvim.enableExceptInTests to be true"; + assertion = !lib.nixvim.enableExceptInTests; + message = "Expected lib.nixvim.enableExceptInTests to be false"; } { # NOTE: evaluating `helpers` here prints an eval warning diff --git a/tests/main.nix b/tests/main.nix index cd2f1d46..ec98b2ba 100644 --- a/tests/main.nix +++ b/tests/main.nix @@ -9,10 +9,24 @@ let fetchTests = callTest ./fetch-tests.nix { }; + # Avoid `build.test` re-evaluating its nixvim configuration by providing a + # "test mode" lib from the start + testLib = lib.extend ( + final: prev: { + nixvim = prev.nixvim.extend ( + final: prev: { + utils = prev.utils // { + enableExceptInTests = false; + }; + } + ); + } + ); + moduleToTest = file: name: module: let - configuration = lib.nixvim.modules.evalNixvim { + configuration = testLib.nixvim.modules.evalNixvim { modules = [ { test.name = lib.mkDefault name; diff --git a/wrappers/standalone.nix b/wrappers/standalone.nix index 694cf6cb..2f3b5473 100644 --- a/wrappers/standalone.nix +++ b/wrappers/standalone.nix @@ -9,14 +9,10 @@ # NOTE: `defaultSystem` is the only reason this function can't go in `.lib` system ? defaultSystem, extraSpecialArgs ? { }, - _nixvimTests ? false, module, }: let # NOTE: we are importing this just for evalNixvim - helpers = self.lib.nixvim.override { inherit _nixvimTests; }; - inherit (helpers.modules) evalNixvim; - systemMod = if pkgs == null then { @@ -33,7 +29,7 @@ let mod: let modules = lib.toList mod; - nixvimConfig = evalNixvim { + nixvimConfig = self.lib.evalNixvim { modules = modules ++ [ systemMod ];