mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-21 00:25:42 +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;
|
defaultPkgs = pkgs;
|
||||||
}
|
}
|
||||||
// extraSpecialArgs;
|
// 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
|
let
|
||||||
helpers = import ../lib/helpers.nix { inherit pkgs lib _nixvimTests; };
|
helpers = import ../lib/helpers.nix { inherit pkgs lib _nixvimTests; };
|
||||||
|
|
||||||
inherit (helpers.modules) specialArgsWith;
|
inherit (helpers.modules) evalNixvim;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
mkNvim =
|
mkNvim =
|
||||||
mod:
|
mod:
|
||||||
let
|
let
|
||||||
evaledModule = lib.evalModules {
|
evaledModule = evalNixvim {
|
||||||
modules = [
|
modules = [
|
||||||
mod
|
mod
|
||||||
./modules/standalone.nix
|
./modules/standalone.nix
|
||||||
../modules/top-level
|
|
||||||
];
|
];
|
||||||
specialArgs = specialArgsWith extraSpecialArgs;
|
inherit extraSpecialArgs;
|
||||||
};
|
};
|
||||||
config = handleAssertions evaledModule.config;
|
inherit (evaledModule.config) enableMan finalPackage printInitPackage;
|
||||||
in
|
in
|
||||||
(pkgs.symlinkJoin {
|
(pkgs.symlinkJoin {
|
||||||
name = "nixvim";
|
name = "nixvim";
|
||||||
paths = [
|
paths = [
|
||||||
config.finalPackage
|
finalPackage
|
||||||
config.printInitPackage
|
printInitPackage
|
||||||
] ++ pkgs.lib.optional config.enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
] ++ pkgs.lib.optional enableMan self.packages.${pkgs.stdenv.hostPlatform.system}.man-docs;
|
||||||
meta.mainProgram = "nvim";
|
meta.mainProgram = "nvim";
|
||||||
})
|
})
|
||||||
// rec {
|
// rec {
|
||||||
inherit config;
|
inherit (evaledModule) config options;
|
||||||
inherit (evaledModule) options;
|
|
||||||
extend =
|
extend =
|
||||||
extension:
|
extension:
|
||||||
mkNvim {
|
mkNvim {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue