1
0
Fork 0
mirror of https://github.com/nix-community/nixvim.git synced 2025-11-21 17:59:41 +01:00

lib: move enableExceptInTests impl to build.test option

Simplify the `enableExceptInTests` attribute, removing the
`_nixvimTests` argument.

We now do a full re-eval of the nixvim configuration before building the
test, giving us a central place to implement `enableExceptInTests` and
its eventual replacement(s).

This extends support for `enableExceptInTests` to all methods of getting
a nixvim test derivation. Previously, it only worked when using `mkTestDerivationFromNixvimModule`.

In `tests/main.nix`, we avoid the re-eval by doing the initial eval with
a "test mode" lib from the start.
This commit is contained in:
Matt Sturgeon 2025-11-19 07:07:02 +00:00
parent 7754b4eb1b
commit 8d0ca9abc4
7 changed files with 57 additions and 31 deletions

View file

@ -2,7 +2,6 @@
lib, lib,
flake, flake,
_isExtended ? false, _isExtended ? false,
_nixvimTests ? false,
}: }:
lib.makeExtensible ( lib.makeExtensible (
self: self:
@ -25,7 +24,7 @@ lib.makeExtensible (
modules = call ./modules.nix { inherit flake; }; modules = call ./modules.nix { inherit flake; };
options = call ./options.nix { }; options = call ./options.nix { };
plugins = call ./plugins { }; 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: # Top-level helper aliases:
# TODO: deprecate some aliases # TODO: deprecate some aliases

View file

@ -15,7 +15,6 @@ let
... ...
}: }:
let let
# FIXME: this doesn't support helpers.enableExceptInTests, a context option would be better
result = nvim.extend { result = nvim.extend {
config.test = { config.test = {
inherit name; inherit name;
@ -35,20 +34,13 @@ let
extraSpecialArgs ? { }, extraSpecialArgs ? { },
}: }:
let 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 = systemMod =
if pkgs == null then if pkgs == null then
{ nixpkgs.hostPlatform = lib.mkDefault { inherit system; }; } { nixpkgs.hostPlatform = lib.mkDefault { inherit system; }; }
else else
{ nixpkgs.pkgs = lib.mkDefault pkgs; }; { nixpkgs.pkgs = lib.mkDefault pkgs; };
result = helpers.modules.evalNixvim { result = self.lib.evalNixvim {
modules = [ modules = [
module module
(lib.optionalAttrs (name != null) { test.name = name; }) (lib.optionalAttrs (name != null) { test.name = name; })

View file

@ -1,7 +1,4 @@
{ { lib }:
lib,
_nixvimTests,
}:
rec { rec {
/** /**
Transforms a list to an _"unkeyed"_ attribute set. 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); builtins.listToAttrs (lib.lists.imap0 (idx: lib.nameValuePair "__unkeyed-${toString idx}") list);
/** /**
Usually `true`, except when nixvim is being evaluated by Usually `true`, except within the `build.test` option, where it is `false`.
`mkTestDerivationFromNixvimModule`, where it is `false`.
This can be used to dynamically enable plugins that can't be run in the This can be used to dynamically enable plugins that can't be run in the
test environment. test environment.
*/ */
# TODO: replace and deprecate # TODO: replace and deprecate
# We shouldn't need to use another instance of `lib` when building a test drv # 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. An empty lua table `{ }` that will be included in the final lua configuration.

View file

@ -3,6 +3,8 @@
config, config,
options, options,
lib, lib,
helpers,
extendModules,
... ...
}: }:
let let
@ -263,9 +265,36 @@ in
config = config =
let 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 = { input = {
inherit (config) warnings; inherit (testConfiguration.config) warnings;
assertions = builtins.concatMap (x: lib.optional (!x.assertion) x.message) config.assertions; assertions = builtins.concatMap (
x: lib.optional (!x.assertion) x.message
) testConfiguration.config.assertions;
}; };
expectationMessages = expectationMessages =
@ -323,7 +352,7 @@ in
nativeBuildInputs = nativeBuildInputs =
cfg.extraInputs cfg.extraInputs
++ lib.optionals cfg.buildNixvim [ ++ lib.optionals cfg.buildNixvim [
config.build.nvimPackage testConfiguration.config.build.nvimPackage
]; ];
inherit (failedExpectations) warnings assertions; inherit (failedExpectations) warnings assertions;
@ -335,7 +364,8 @@ in
# #
# Yes, three levels of `entries` is cursed. # Yes, three levels of `entries` is cursed.
passthru = { passthru = {
inherit config options; inherit (testConfiguration) config options;
configuration = testConfiguration;
}; };
} }
( (

View file

@ -15,9 +15,8 @@ let
{ {
assertions = [ assertions = [
{ {
# FIXME: should be false assertion = !lib.nixvim.enableExceptInTests;
assertion = lib.nixvim.enableExceptInTests; message = "Expected lib.nixvim.enableExceptInTests to be false";
message = "Expected lib.nixvim.enableExceptInTests to be true";
} }
{ {
# NOTE: evaluating `helpers` here prints an eval warning # NOTE: evaluating `helpers` here prints an eval warning

View file

@ -9,10 +9,24 @@
let let
fetchTests = callTest ./fetch-tests.nix { }; 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 = moduleToTest =
file: name: module: file: name: module:
let let
configuration = lib.nixvim.modules.evalNixvim { configuration = testLib.nixvim.modules.evalNixvim {
modules = [ modules = [
{ {
test.name = lib.mkDefault name; test.name = lib.mkDefault name;

View file

@ -9,14 +9,10 @@
# NOTE: `defaultSystem` is the only reason this function can't go in `<nixvim>.lib` # NOTE: `defaultSystem` is the only reason this function can't go in `<nixvim>.lib`
system ? defaultSystem, system ? defaultSystem,
extraSpecialArgs ? { }, extraSpecialArgs ? { },
_nixvimTests ? false,
module, module,
}: }:
let let
# NOTE: we are importing this just for evalNixvim # NOTE: we are importing this just for evalNixvim
helpers = self.lib.nixvim.override { inherit _nixvimTests; };
inherit (helpers.modules) evalNixvim;
systemMod = systemMod =
if pkgs == null then if pkgs == null then
{ {
@ -33,7 +29,7 @@ let
mod: mod:
let let
modules = lib.toList mod; modules = lib.toList mod;
nixvimConfig = evalNixvim { nixvimConfig = self.lib.evalNixvim {
modules = modules ++ [ modules = modules ++ [
systemMod systemMod
]; ];