mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
Splits everything that depends on a `pkgs` instance into an optional attrs, allowing `helpers.nix` to be bootstrapped without `pkgs`. This required some refactoring: - `modules.specialArgs` is only available when `pkgs` is used - `modules.specialArgsWith` now requires `defaultPkgs` be provided - `builders.*` now have `*With` variants that take `pkgs` as an argument and a `withPkgs` function that returns the old interface - Had to define the fixed part of `builders` outside the attrs for now, to avoid infinite recursion. - The old `builders` are now deprecated, and print a warning when evaluated - `withOptoinalFns` was introduced to merge the optional attrs into the final lib.
51 lines
1.4 KiB
Nix
51 lines
1.4 KiB
Nix
{
|
|
lib,
|
|
self,
|
|
}:
|
|
rec {
|
|
# Build specialArgs for evaluating nixvim modules
|
|
specialArgsWith =
|
|
# TODO: switch defaultPkgs -> pkgsPath (i.e. pkgs.path or inputs.nixvim)
|
|
# FIXME: Ideally, we should not require callers to pass in _anything_ specific
|
|
{ defaultPkgs, ... }@extraSpecialArgs:
|
|
{
|
|
inherit lib defaultPkgs;
|
|
# TODO: deprecate `helpers`
|
|
helpers = self;
|
|
}
|
|
// extraSpecialArgs;
|
|
|
|
# Evaluate nixvim modules, checking warnings and assertions
|
|
evalNixvim =
|
|
{
|
|
modules ? [ ],
|
|
extraSpecialArgs ? { },
|
|
# Set to false to disable warnings and assertions
|
|
# Intended to aid accessing config.test.derivation
|
|
# 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))
|
|
];
|
|
}
|