refactor(dotfiles): extract registry schema
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
{ lib, ... }:
|
{ lib, util, ... }:
|
||||||
{
|
{
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
|
|
||||||
checks = [
|
checks = [
|
||||||
{
|
{
|
||||||
assertion = lib.registry.predicates.uniqueValue (entry: entry.value);
|
assertion = util.registry.predicates.uniqueValue (entry: entry.value);
|
||||||
message = "Address registry values must be unique.";
|
message = "Address registry values must be unique.";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
{ lib, ... }:
|
{ lib, util, ... }:
|
||||||
{
|
{
|
||||||
checks = [
|
checks = [
|
||||||
{
|
{
|
||||||
assertion = lib.registry.predicates.uniqueValue (entry: entry.value.domain);
|
assertion = util.registry.predicates.uniqueValue (entry: entry.value.domain);
|
||||||
message = "Route domains must be unique.";
|
message = "Route domains must be unique.";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
assertion =
|
assertion =
|
||||||
entries:
|
entries:
|
||||||
lib.registry.predicates.uniqueValue (entry: entry.value) (
|
util.registry.predicates.uniqueValue (entry: entry.value) (
|
||||||
lib.concatMap (entry: map (port: entry // { value = port; }) entry.value.udp.ports) entries
|
lib.concatMap (entry: map (port: entry // { value = port; }) entry.value.udp.ports) entries
|
||||||
);
|
);
|
||||||
message = "Route UDP ports must be unique.";
|
message = "Route UDP ports must be unique.";
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ let
|
|||||||
path:
|
path:
|
||||||
let
|
let
|
||||||
evaluated = lib.evalModules {
|
evaluated = lib.evalModules {
|
||||||
specialArgs.lib = registryLib;
|
specialArgs = { inherit util; };
|
||||||
modules = [
|
modules = [
|
||||||
registryDefinitionModule
|
(import ./registry/schema.nix { inherit lib; })
|
||||||
path
|
path
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -24,62 +24,6 @@ let
|
|||||||
inherit (evaluated.config) type replicate checks;
|
inherit (evaluated.config) type replicate checks;
|
||||||
};
|
};
|
||||||
|
|
||||||
registryLib = lib // {
|
|
||||||
registry = (lib.registry or { }) // {
|
|
||||||
inherit predicates;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
predicates = {
|
|
||||||
uniqueValue =
|
|
||||||
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
|
|
||||||
};
|
|
||||||
|
|
||||||
registryDefinitionModule = {
|
|
||||||
options = {
|
|
||||||
type = lib.mkOption {
|
|
||||||
type = lib.types.raw;
|
|
||||||
description = ''
|
|
||||||
NixOS option type for one registry entry.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
replicate = lib.mkOption {
|
|
||||||
type = lib.types.bool;
|
|
||||||
default = false;
|
|
||||||
description = ''
|
|
||||||
Whether collected entries are merged and published under every host key.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
checks = lib.mkOption {
|
|
||||||
type = lib.types.listOf checkType;
|
|
||||||
default = [ ];
|
|
||||||
description = ''
|
|
||||||
Validation checks for this registry's flattened collected entries.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
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.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
registryOption =
|
registryOption =
|
||||||
registry:
|
registry:
|
||||||
lib.mkOption {
|
lib.mkOption {
|
||||||
|
|||||||
46
src/dotfiles/registry/schema.nix
Normal file
46
src/dotfiles/registry/schema.nix
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
{ lib }:
|
||||||
|
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.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
type = lib.mkOption {
|
||||||
|
type = lib.types.raw;
|
||||||
|
description = ''
|
||||||
|
NixOS option type for one registry entry.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
replicate = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = false;
|
||||||
|
description = ''
|
||||||
|
Whether collected entries are merged and published under every host key.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
checks = lib.mkOption {
|
||||||
|
type = lib.types.listOf checkType;
|
||||||
|
default = [ ];
|
||||||
|
description = ''
|
||||||
|
Validation checks for this registry's flattened collected entries.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -22,6 +22,9 @@ in
|
|||||||
|
|
||||||
removeNixSuffix = path: lib.removeSuffix ".nix" (builtins.baseNameOf path);
|
removeNixSuffix = path: lib.removeSuffix ".nix" (builtins.baseNameOf path);
|
||||||
|
|
||||||
|
registry.predicates.uniqueValue =
|
||||||
|
value: entries: builtins.length (lib.unique (map value entries)) == builtins.length entries;
|
||||||
|
|
||||||
bridgeName = id: "br-vlan${toString id}";
|
bridgeName = id: "br-vlan${toString id}";
|
||||||
|
|
||||||
deriveMac =
|
deriveMac =
|
||||||
|
|||||||
Reference in New Issue
Block a user