mirror of
https://github.com/nix-community/nixvim.git
synced 2025-07-14 11:14:36 +02:00
lib/modules: add evalNixvim
Evaluates a nixvim config, by default also checking warnings and assertions. This used internally by the standalone wrapper.
This commit is contained in:
parent
bc7a7ad1d6
commit
851edc8df1
2 changed files with 42 additions and 20 deletions
|
@ -16,4 +16,38 @@ rec {
|
|||
defaultPkgs = pkgs;
|
||||
}
|
||||
// extraSpecialArgs;
|
||||
|
||||
# Evaluate nixvim modules, checking warnings and assertions
|
||||
evalNixvim =
|
||||
{
|
||||
modules ? [ ],
|
||||
extraSpecialArgs ? { },
|
||||
# Set to false to disable warnings and assertions
|
||||
# Intended for use with tests, where we may not want to check assertions
|
||||
# WARNING: This argument may be removed without notice:
|
||||
check ? true,
|
||||
}:
|
||||
let
|
||||
result = lib.evalModules {
|
||||
modules = [ ../modules/top-level ] ++ modules;
|
||||
specialArgs = specialArgsWith extraSpecialArgs;
|
||||
};
|
||||
|
||||
failedAssertions = getAssertionMessages result.config.assertions;
|
||||
|
||||
checked =
|
||||
if failedAssertions != [ ] then
|
||||
throw "\nFailed assertions:\n${lib.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||
else
|
||||
lib.showWarnings result.config.warnings result;
|
||||
in
|
||||
if check then checked else result;
|
||||
|
||||
# Return the messages for all assertions that failed
|
||||
getAssertionMessages =
|
||||
assertions:
|
||||
lib.pipe assertions [
|
||||
(lib.filter (x: !x.assertion))
|
||||
(lib.map (x: x.message))
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue