feat(registry): add generic fleet namespace
This commit is contained in:
@@ -14,6 +14,11 @@ let
|
||||
;
|
||||
|
||||
serviceIdentityRegistry = import ./service-identities.nix { inherit lib; };
|
||||
registryLib = import ./registry.nix { inherit lib; };
|
||||
registry = registryLib.load {
|
||||
dir = self + "/registry";
|
||||
args = { inherit lib; };
|
||||
};
|
||||
networkEndpoints = import ./network-endpoints.nix { inherit lib; };
|
||||
reverseProxyRoutes = import ./reverse-proxy-routes.nix { inherit lib; };
|
||||
|
||||
@@ -41,6 +46,7 @@ let
|
||||
{
|
||||
inherit inputs networkFleetEndpoints self;
|
||||
my = self.lib;
|
||||
registry = self.lib.registry.collect { hosts = self.nixosConfigurations; };
|
||||
reverseProxyFleetRoutes = self.lib.reverseProxyRoutes.collectFleetRoutes self.nixosConfigurations networkFleetEndpoints;
|
||||
};
|
||||
|
||||
@@ -71,6 +77,7 @@ let
|
||||
inputs.disko.nixosModules.disko
|
||||
inputs.sops-nix.nixosModules.sops
|
||||
inputs.stylix.nixosModules.stylix
|
||||
registry.module
|
||||
(self + "/system.nix")
|
||||
(self + "/hosts/${hostName}")
|
||||
{ networking.hostName = hostName; }
|
||||
@@ -90,6 +97,7 @@ in
|
||||
mkHost
|
||||
mkHosts
|
||||
bridgeName
|
||||
registry
|
||||
networkEndpoints
|
||||
reverseProxyRoutes
|
||||
;
|
||||
|
||||
53
lib/registry.nix
Normal file
53
lib/registry.nix
Normal file
@@ -0,0 +1,53 @@
|
||||
{ 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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user