feat(registry): add generic fleet namespace
This commit was merged in pull request #59.
This commit is contained in:
45
flake.nix
45
flake.nix
@@ -246,6 +246,51 @@
|
|||||||
touch $out
|
touch $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
generic-registry-fleet-view =
|
||||||
|
let
|
||||||
|
hosts = {
|
||||||
|
alpha = lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
specialArgs.registry = registry;
|
||||||
|
modules = [
|
||||||
|
self.lib.registry.module
|
||||||
|
{
|
||||||
|
registry.address.alpha.service = "10.0.0.5";
|
||||||
|
system.stateVersion = "26.11";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
beta = lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
specialArgs.registry = registry;
|
||||||
|
modules = [
|
||||||
|
self.lib.registry.module
|
||||||
|
(
|
||||||
|
{ registry, ... }:
|
||||||
|
{
|
||||||
|
environment.etc."registry-address-check".text = registry.address.alpha.service;
|
||||||
|
system.stateVersion = "26.11";
|
||||||
|
}
|
||||||
|
)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
registry = self.lib.registry.collect { inherit hosts; };
|
||||||
|
betaConfig = hosts.beta.config;
|
||||||
|
in
|
||||||
|
pkgs.runCommand "generic-registry-fleet-view-check" { } ''
|
||||||
|
${
|
||||||
|
lib.optionalString (
|
||||||
|
!(
|
||||||
|
registry.address.alpha.service == "10.0.0.5"
|
||||||
|
&& betaConfig.environment.etc."registry-address-check".text == "10.0.0.5"
|
||||||
|
&& !(registry.address ? alpha-service)
|
||||||
|
)
|
||||||
|
) "exit 1"
|
||||||
|
}
|
||||||
|
touch $out
|
||||||
|
'';
|
||||||
|
|
||||||
network-endpoint-fleet-registry =
|
network-endpoint-fleet-registry =
|
||||||
let
|
let
|
||||||
hostEndpointConfig =
|
hostEndpointConfig =
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ let
|
|||||||
;
|
;
|
||||||
|
|
||||||
serviceIdentityRegistry = import ./service-identities.nix { inherit lib; };
|
serviceIdentityRegistry = import ./service-identities.nix { inherit lib; };
|
||||||
|
registry = import ./registry.nix { inherit lib self; };
|
||||||
networkEndpoints = import ./network-endpoints.nix { inherit lib; };
|
networkEndpoints = import ./network-endpoints.nix { inherit lib; };
|
||||||
reverseProxyRoutes = import ./reverse-proxy-routes.nix { inherit lib; };
|
reverseProxyRoutes = import ./reverse-proxy-routes.nix { inherit lib; };
|
||||||
|
|
||||||
@@ -41,6 +42,7 @@ let
|
|||||||
{
|
{
|
||||||
inherit inputs networkFleetEndpoints self;
|
inherit inputs networkFleetEndpoints self;
|
||||||
my = self.lib;
|
my = self.lib;
|
||||||
|
registry = self.lib.registry.collect { hosts = self.nixosConfigurations; };
|
||||||
reverseProxyFleetRoutes = self.lib.reverseProxyRoutes.collectFleetRoutes self.nixosConfigurations networkFleetEndpoints;
|
reverseProxyFleetRoutes = self.lib.reverseProxyRoutes.collectFleetRoutes self.nixosConfigurations networkFleetEndpoints;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -71,6 +73,7 @@ let
|
|||||||
inputs.disko.nixosModules.disko
|
inputs.disko.nixosModules.disko
|
||||||
inputs.sops-nix.nixosModules.sops
|
inputs.sops-nix.nixosModules.sops
|
||||||
inputs.stylix.nixosModules.stylix
|
inputs.stylix.nixosModules.stylix
|
||||||
|
registry.module
|
||||||
(self + "/system.nix")
|
(self + "/system.nix")
|
||||||
(self + "/hosts/${hostName}")
|
(self + "/hosts/${hostName}")
|
||||||
{ networking.hostName = hostName; }
|
{ networking.hostName = hostName; }
|
||||||
@@ -90,6 +93,7 @@ in
|
|||||||
mkHost
|
mkHost
|
||||||
mkHosts
|
mkHosts
|
||||||
bridgeName
|
bridgeName
|
||||||
|
registry
|
||||||
networkEndpoints
|
networkEndpoints
|
||||||
reverseProxyRoutes
|
reverseProxyRoutes
|
||||||
;
|
;
|
||||||
|
|||||||
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;
|
||||||
|
}
|
||||||
4
registry/address.nix
Normal file
4
registry/address.nix
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{ lib }:
|
||||||
|
{
|
||||||
|
type = lib.types.str;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user