|
|
|
|
@@ -4,34 +4,35 @@
|
|
|
|
|
root,
|
|
|
|
|
}:
|
|
|
|
|
let
|
|
|
|
|
checkType = lib.types.submodule {
|
|
|
|
|
options = {
|
|
|
|
|
assertion = lib.mkOption {
|
|
|
|
|
type = lib.types.functionTo lib.types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Predicate run against this registry's flattened collected entries.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
message = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
description = ''
|
|
|
|
|
Error message shown when this registry validation check fails.
|
|
|
|
|
'';
|
|
|
|
|
definitions =
|
|
|
|
|
lib.mapAttrs'
|
|
|
|
|
(
|
|
|
|
|
name: _type:
|
|
|
|
|
let
|
|
|
|
|
path = root + "/${name}";
|
|
|
|
|
in
|
|
|
|
|
lib.nameValuePair (registryName name) (mkRegistry path)
|
|
|
|
|
)
|
|
|
|
|
(
|
|
|
|
|
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
registryName = fileName: lib.removeSuffix ".nix" fileName;
|
|
|
|
|
|
|
|
|
|
mkRegistry =
|
|
|
|
|
path:
|
|
|
|
|
let
|
|
|
|
|
evaluated = lib.evalModules {
|
|
|
|
|
specialArgs.lib = registryLib;
|
|
|
|
|
modules = [
|
|
|
|
|
registryDefinitionModule
|
|
|
|
|
path
|
|
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
inherit (evaluated.config) type replicate checks;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
predicates = {
|
|
|
|
|
uniqueValue =
|
|
|
|
|
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
registryLib = lib // {
|
|
|
|
|
registry = (lib.registry or { }) // {
|
|
|
|
|
inherit predicates;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
registryDefinitionModule = {
|
|
|
|
|
options = {
|
|
|
|
|
@@ -60,61 +61,58 @@ let
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
registryName = fileName: lib.removeSuffix ".nix" fileName;
|
|
|
|
|
|
|
|
|
|
registryOption =
|
|
|
|
|
registry:
|
|
|
|
|
lib.mkOption {
|
|
|
|
|
type = lib.types.attrsOf (lib.types.attrsOf registry.type);
|
|
|
|
|
default = { };
|
|
|
|
|
description = ''
|
|
|
|
|
Lazily collected fleet-visible registry entries, nested by host and entry name.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mkRegistry =
|
|
|
|
|
path:
|
|
|
|
|
let
|
|
|
|
|
evaluated = lib.evalModules {
|
|
|
|
|
specialArgs.lib = registryLib;
|
|
|
|
|
modules = [
|
|
|
|
|
registryDefinitionModule
|
|
|
|
|
path
|
|
|
|
|
];
|
|
|
|
|
checkType = lib.types.submodule {
|
|
|
|
|
options = {
|
|
|
|
|
assertion = lib.mkOption {
|
|
|
|
|
type = lib.types.functionTo lib.types.bool;
|
|
|
|
|
description = ''
|
|
|
|
|
Predicate run against this registry's flattened collected entries.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
message = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
description = ''
|
|
|
|
|
Error message shown when this registry validation check fails.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
inherit (evaluated.config) type replicate checks;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
definitions =
|
|
|
|
|
lib.mapAttrs'
|
|
|
|
|
(
|
|
|
|
|
name: _type:
|
|
|
|
|
let
|
|
|
|
|
path = root + "/${name}";
|
|
|
|
|
in
|
|
|
|
|
lib.nameValuePair (registryName name) (mkRegistry path)
|
|
|
|
|
)
|
|
|
|
|
(
|
|
|
|
|
lib.filterAttrs (name: type: type == "regular" && lib.hasSuffix ".nix" name) (builtins.readDir root)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
flattenRegistryEntries =
|
|
|
|
|
registryName: data:
|
|
|
|
|
lib.concatLists (
|
|
|
|
|
lib.mapAttrsToList (
|
|
|
|
|
host: entries:
|
|
|
|
|
lib.mapAttrsToList (entry: value: {
|
|
|
|
|
path = "registry.${registryName}.${host}.${entry}";
|
|
|
|
|
inherit host entry value;
|
|
|
|
|
}) entries
|
|
|
|
|
) data
|
|
|
|
|
withOperations =
|
|
|
|
|
registry:
|
|
|
|
|
registry
|
|
|
|
|
// {
|
|
|
|
|
join = host: entry: join registry host entry;
|
|
|
|
|
};
|
|
|
|
|
join =
|
|
|
|
|
registry: host: entry:
|
|
|
|
|
lib.filterAttrs (_name: value: value != null) (
|
|
|
|
|
lib.mapAttrs (
|
|
|
|
|
registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null
|
|
|
|
|
) definitions
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
rawDeclarations =
|
|
|
|
|
registryName: hosts:
|
|
|
|
|
lib.mapAttrs (_hostName: host: host.config.registry.${registryName} or { }) hosts;
|
|
|
|
|
collectData =
|
|
|
|
|
{ hosts }:
|
|
|
|
|
let
|
|
|
|
|
data = lib.mapAttrs (
|
|
|
|
|
registryName: registry:
|
|
|
|
|
if registry.replicate or false then
|
|
|
|
|
replicatedData registryName hosts raw.${registryName}
|
|
|
|
|
else
|
|
|
|
|
lib.mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
|
|
|
|
|
) definitions;
|
|
|
|
|
raw = lib.mapAttrs (registryName: _registry: rawDeclarations registryName hosts) definitions;
|
|
|
|
|
in
|
|
|
|
|
assertValid data;
|
|
|
|
|
|
|
|
|
|
replicatedData =
|
|
|
|
|
registryName: hosts: raw:
|
|
|
|
|
let
|
|
|
|
|
entries = lib.mapAttrs (_entryName: entry: entry.value) (replicatedEntries registryName raw);
|
|
|
|
|
in
|
|
|
|
|
lib.mapAttrs (_hostName: _host: entries) hosts;
|
|
|
|
|
|
|
|
|
|
replicatedEntries =
|
|
|
|
|
registryName: raw:
|
|
|
|
|
@@ -148,12 +146,20 @@ let
|
|
|
|
|
}
|
|
|
|
|
) { } entries;
|
|
|
|
|
|
|
|
|
|
replicatedData =
|
|
|
|
|
registryName: hosts: raw:
|
|
|
|
|
rawDeclarations =
|
|
|
|
|
registryName: hosts:
|
|
|
|
|
lib.mapAttrs (_hostName: host: host.config.registry.${registryName} or { }) hosts;
|
|
|
|
|
|
|
|
|
|
assertValid =
|
|
|
|
|
data:
|
|
|
|
|
let
|
|
|
|
|
entries = lib.mapAttrs (_entryName: entry: entry.value) (replicatedEntries registryName raw);
|
|
|
|
|
assertions = validationAssertions data;
|
|
|
|
|
failures = lib.filter (assertion: !assertion.assertion) assertions;
|
|
|
|
|
in
|
|
|
|
|
lib.mapAttrs (_hostName: _host: entries) hosts;
|
|
|
|
|
assert lib.assertMsg (lib.all (assertion: assertion.assertion) assertions) (
|
|
|
|
|
lib.concatMapStringsSep "\n" (assertion: assertion.message) failures
|
|
|
|
|
);
|
|
|
|
|
data;
|
|
|
|
|
|
|
|
|
|
validationAssertions =
|
|
|
|
|
data:
|
|
|
|
|
@@ -170,45 +176,39 @@ let
|
|
|
|
|
) definitions
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assertValid =
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
join =
|
|
|
|
|
registry: host: entry:
|
|
|
|
|
lib.filterAttrs (_name: value: value != null) (
|
|
|
|
|
lib.mapAttrs (
|
|
|
|
|
registryName: _registry: (registry.${registryName}.${host} or { }).${entry} or null
|
|
|
|
|
) definitions
|
|
|
|
|
flattenRegistryEntries =
|
|
|
|
|
registryName: data:
|
|
|
|
|
lib.concatLists (
|
|
|
|
|
lib.mapAttrsToList (
|
|
|
|
|
host: entries:
|
|
|
|
|
lib.mapAttrsToList (entry: value: {
|
|
|
|
|
path = "registry.${registryName}.${host}.${entry}";
|
|
|
|
|
inherit host entry value;
|
|
|
|
|
}) entries
|
|
|
|
|
) data
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
collectData =
|
|
|
|
|
{ hosts }:
|
|
|
|
|
let
|
|
|
|
|
raw = lib.mapAttrs (registryName: _registry: rawDeclarations registryName hosts) definitions;
|
|
|
|
|
data = lib.mapAttrs (
|
|
|
|
|
registryName: registry:
|
|
|
|
|
if registry.replicate or false then
|
|
|
|
|
replicatedData registryName hosts raw.${registryName}
|
|
|
|
|
else
|
|
|
|
|
lib.mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
|
|
|
|
|
) definitions;
|
|
|
|
|
in
|
|
|
|
|
assertValid data;
|
|
|
|
|
predicates = {
|
|
|
|
|
uniqueValue =
|
|
|
|
|
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
withOperations =
|
|
|
|
|
registry:
|
|
|
|
|
registry
|
|
|
|
|
// {
|
|
|
|
|
join = host: entry: join registry host entry;
|
|
|
|
|
registryLib = lib // {
|
|
|
|
|
registry = (lib.registry or { }) // {
|
|
|
|
|
inherit predicates;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
registryOption =
|
|
|
|
|
registry:
|
|
|
|
|
lib.mkOption {
|
|
|
|
|
type = lib.types.attrsOf (lib.types.attrsOf registry.type);
|
|
|
|
|
default = { };
|
|
|
|
|
description = ''
|
|
|
|
|
Lazily collected fleet-visible registry entries, nested by host and entry name.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
types = lib.mapAttrs (_name: definition: definition.type) definitions;
|
|
|
|
|
|