Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions lib/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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))
];
}
28 changes: 8 additions & 20 deletions wrappers/standalone.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down