feat(registry): add generic fleet namespace
This commit was merged in pull request #59.
This commit is contained in:
45
lib/registry.nix
Normal file
45
lib/registry.nix
Normal file
@@ -0,0 +1,45 @@
|
||||
{ lib, self }:
|
||||
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.
|
||||
'';
|
||||
};
|
||||
|
||||
definitions = mapAttrs' (
|
||||
name: type:
|
||||
let
|
||||
path = self + "/registry/${name}";
|
||||
in
|
||||
nameValuePair (registryName name) (import path { inherit lib; })
|
||||
) (filterAttrs (name: type: type == "regular" && hasSuffix ".nix" name) (builtins.readDir (self + "/registry")));
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user