network/nix/lib/config/default.nix

67 lines
1.3 KiB
Nix

{ self
, pkgs ? import <nixpkgs> {}
, gpgKey
}:
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.gpgKey = mkOption {
type = with types; nullOr path;
};
config = {
inherit gpgKey;
};
}
)
./options.nix
./legacy.nix
];
};
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 (
builtins.removeAttrs config [ "assertions" "warnings" "gpgKey" "salt-pillar" ]
)
)