network/nix/lib/config/default.nix

61 lines
1.2 KiB
Nix

{ self
, pkgs ? import <nixpkgs> {}
}:
let
result = pkgs.lib.evalModules {
args = {
inherit self pkgs;
};
modules = [
(
{ lib, ... }:
with lib;
{
options.assertions = mkOption {
type = with types; listOf unspecified;
internal = true;
};
options.warnings = mkOption {
type = types.listOf types.str;
default = [];
internal = true;
};
}
)
./options.nix
../../../config
];
};
inherit (result) config;
warn = result:
if builtins.length config.warnings > 0
then builtins.trace ''
Warnings:
${self.lib.concatStringsSep "\n" config.warnings}
'' result
else result;
error = result:
let
failed = builtins.filter ({ assertion, ... }:
!assertion
) config.assertions;
in
if failed != []
then throw ''
Errors:
${self.lib.concatMapStringsSep "\n" ({ message, ... }: message) failed}
''
else result;
in warn (error ({
inherit (result) options;
config = builtins.removeAttrs config [ "assertions" "warnings" ];
}))