refactor(dotfiles): clarify registry validation
This commit was merged in pull request #126.
This commit is contained in:
@@ -19,14 +19,12 @@ let
|
||||
];
|
||||
}).config;
|
||||
|
||||
data = validate (
|
||||
lib.mapAttrs (
|
||||
registryName: _registry:
|
||||
lib.mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
|
||||
) definitions
|
||||
);
|
||||
validation = import ./registry/validation.nix { inherit data definitions lib; };
|
||||
|
||||
validate = import ./registry/validation.nix { inherit definitions lib; };
|
||||
data = lib.mapAttrs (
|
||||
registryName: _registry:
|
||||
lib.mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
|
||||
) definitions;
|
||||
in
|
||||
{
|
||||
types = lib.mapAttrs (_name: definition: definition.type) definitions;
|
||||
@@ -45,13 +43,16 @@ in
|
||||
) definitions;
|
||||
};
|
||||
|
||||
collected = data // {
|
||||
join =
|
||||
host: entry:
|
||||
lib.filterAttrs (_name: value: value != null) (
|
||||
lib.mapAttrs (
|
||||
registryName: _registry: (data.${registryName}.${host} or { }).${entry} or null
|
||||
) definitions
|
||||
);
|
||||
};
|
||||
collected =
|
||||
assert validation;
|
||||
data
|
||||
// {
|
||||
join =
|
||||
host: entry:
|
||||
lib.filterAttrs (_name: value: value != null) (
|
||||
lib.mapAttrs (
|
||||
registryName: _registry: (data.${registryName}.${host} or { }).${entry} or null
|
||||
) definitions
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,41 +1,34 @@
|
||||
{
|
||||
data,
|
||||
definitions,
|
||||
lib,
|
||||
}:
|
||||
let
|
||||
validationAssertions =
|
||||
data:
|
||||
checkResults = lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
registryName: definition:
|
||||
map (check: {
|
||||
assertion = check.assertion (entriesForRegistry registryName);
|
||||
inherit (check) message;
|
||||
}) definition.checks
|
||||
) definitions
|
||||
);
|
||||
|
||||
entriesForRegistry =
|
||||
registryName:
|
||||
lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
registryName: registry:
|
||||
let
|
||||
entries = flattenRegistryEntries registryName data.${registryName};
|
||||
in
|
||||
map (check: {
|
||||
assertion = check.assertion entries;
|
||||
inherit (check) message;
|
||||
}) registry.checks
|
||||
) definitions
|
||||
lib.mapAttrsToList (host: entries: entriesForHost registryName host entries) data.${registryName}
|
||||
);
|
||||
|
||||
flattenRegistryEntries =
|
||||
registryName: data:
|
||||
lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
host: entries:
|
||||
lib.mapAttrsToList (entry: value: {
|
||||
path = "registry.${registryName}.${host}.${entry}";
|
||||
inherit host entry value;
|
||||
}) entries
|
||||
) data
|
||||
);
|
||||
entriesForHost =
|
||||
registryName: host: entries:
|
||||
lib.mapAttrsToList (entry: value: {
|
||||
path = "registry.${registryName}.${host}.${entry}";
|
||||
inherit host entry value;
|
||||
}) entries;
|
||||
|
||||
failures = lib.filter (result: !result.assertion) checkResults;
|
||||
in
|
||||
data:
|
||||
let
|
||||
assertions = validationAssertions data;
|
||||
failures = lib.filter (assertion: !assertion.assertion) assertions;
|
||||
in
|
||||
assert lib.assertMsg (lib.all (assertion: assertion.assertion) assertions) (
|
||||
lib.concatMapStringsSep "\n" (assertion: assertion.message) failures
|
||||
);
|
||||
data
|
||||
lib.assertMsg (lib.all (result: result.assertion) checkResults) (
|
||||
lib.concatMapStringsSep "\n" (result: result.message) failures
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user