Compare commits

2 Commits

Author SHA1 Message Date
58a6d4e554 docs(todo): keep registry refactor pending 2026-09-26 20:19:38 -04:00
62d2513666 refactor(dotfiles): order let bindings 2026-09-26 20:18:19 -04:00
3 changed files with 118 additions and 118 deletions

View File

@@ -5,8 +5,6 @@
root, root,
}: }:
let let
util = import ./util.nix { inherit lib; };
registry = import ./registry.nix { registry = import ./registry.nix {
inherit lib; inherit lib;
hosts = self.nixosConfigurations; hosts = self.nixosConfigurations;
@@ -18,6 +16,8 @@ let
root = root + "/modules"; root = root + "/modules";
}; };
util = import ./util.nix { inherit lib; };
specialArgs = { specialArgs = {
inherit inherit
inputs inputs

View File

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

View File

@@ -25,8 +25,8 @@ in
deriveMac = deriveMac =
name: name:
let let
hash = builtins.hashString "sha256" name;
octet = i: builtins.substring (i * 2) 2 hash; octet = i: builtins.substring (i * 2) 2 hash;
hash = builtins.hashString "sha256" name;
in in
lib.concatStringsSep ":" ( lib.concatStringsSep ":" (
[ "02" ] [ "02" ]