54 lines
1.1 KiB
Nix
54 lines
1.1 KiB
Nix
{ lib }:
|
|
let
|
|
inherit (lib)
|
|
filterAttrs
|
|
hasSuffix
|
|
mapAttrs
|
|
mapAttrs'
|
|
mkOption
|
|
nameValuePair
|
|
removeSuffix
|
|
types
|
|
;
|
|
|
|
registryName = fileName: removeSuffix ".nix" fileName;
|
|
|
|
registryOption = registry: mkOption {
|
|
type = types.attrsOf (types.attrsOf registry.type);
|
|
default = { };
|
|
description = ''
|
|
Lazily collected fleet-visible registry entries, nested by host and entry name.
|
|
'';
|
|
};
|
|
in
|
|
{
|
|
load =
|
|
{
|
|
dir,
|
|
args ? { },
|
|
}:
|
|
let
|
|
definitions = mapAttrs' (
|
|
name: type:
|
|
let
|
|
path = dir + "/${name}";
|
|
in
|
|
nameValuePair (registryName name) (import path args)
|
|
) (filterAttrs (name: type: type == "regular" && hasSuffix ".nix" name) (builtins.readDir dir));
|
|
in
|
|
{
|
|
inherit definitions;
|
|
|
|
module = {
|
|
options.registry = mapAttrs (_name: registry: registryOption registry) definitions;
|
|
};
|
|
|
|
collect =
|
|
{ hosts }:
|
|
mapAttrs (
|
|
registryName: _registry:
|
|
mapAttrs (hostName: host: host.config.registry.${registryName}.${hostName} or { }) hosts
|
|
) definitions;
|
|
};
|
|
}
|