network/nix/lib/config/default.nix

61 lines
1.2 KiB
Nix
Raw Normal View History

{ self
, pkgs ? import <nixpkgs> {}
2021-03-19 23:25:31 +01:00
}:
2021-03-19 01:24:31 +01:00
let
result = pkgs.lib.evalModules {
args = {
inherit self pkgs;
};
2021-03-19 01:24:31 +01:00
modules = [
2021-03-19 23:25:31 +01:00
(
{ lib, ... }:
with lib;
{
options.assertions = mkOption {
type = with types; listOf unspecified;
internal = true;
};
options.warnings = mkOption {
type = types.listOf types.str;
default = [];
internal = true;
};
2021-03-19 23:25:31 +01:00
}
)
./options.nix
2021-11-13 01:23:23 +01:00
../../../config
2021-03-19 01:24:31 +01:00
];
};
2021-11-13 01:23:23 +01:00
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
2021-11-13 01:23:23 +01:00
failed = builtins.filter ({ assertion, ... }:
!assertion
) config.assertions;
in
if failed != []
then throw ''
Errors:
${self.lib.concatMapStringsSep "\n" ({ message, ... }: message) failed}
''
else result;
2021-11-13 01:23:23 +01:00
in warn (error ({
inherit (result) options;
config = builtins.removeAttrs config [ "assertions" "warnings" ];
}))