mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +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))
|
||||
];
|
||||
}
|
||||
|
|
|
@ -9,42 +9,30 @@ default_pkgs: self:
|
|||
let
|
||||
helpers = import ../lib/helpers.nix { inherit pkgs lib _nixvimTests; };
|
||||
|
||||
inherit (helpers.modules) specialArgsWith;
|
||||
|
||||
handleAssertions =
|
||||
config:
|
||||
let
|
||||
failedAssertions = map (x: x.message) (lib.filter (x: !x.assertion) config.assertions);
|
||||
in
|
||||
if failedAssertions != [ ] then
|
||||
throw "\nFailed assertions:\n${builtins.concatStringsSep "\n" (map (x: "- ${x}") failedAssertions)}"
|
||||
else
|
||||
lib.showWarnings config.warnings config;
|
||||
inherit (helpers.modules) evalNixvim;
|
||||
|
||||
mkNvim =
|
||||
mod:
|
||||
let
|
||||
evaledModule = lib.evalModules {
|
||||
evaledModule = evalNixvim {
|
||||
modules = [
|
||||
mod
|
||||
./modules/standalone.nix
|
||||
../modules/top-level
|
||||
];
|
||||
specialArgs = specialArgsWith extraSpecialArgs;
|
||||
inherit extraSpecialArgs;
|
||||
};
|
||||
config = handleAssertions evaledModule.config;
|
||||
inherit (evaledModule.config) enableMan finalPackage printInitPackage;
|
||||
in
|
||||
(pkgs.symlinkJoin {
|
||||
name = "nixvim";
|
||||
paths = [
|
||||
config.finalPackage
|
||||
config.printInitPackage
|
||||
] ++ pkgs.lib.optional config.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
||||
finalPackage
|
||||
printInitPackage
|
||||
] ++ pkgs.lib.optional enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
||||
meta.mainProgram = "nvim";
|
||||
})
|
||||
// rec {
|
||||
inherit config;
|
||||
inherit (evaledModule) options;
|
||||
inherit (evaledModule) config options;
|
||||
extend =
|
||||
extension:
|
||||
mkNvim {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue