From fdf14765fd8bf4efd3031d7e17fd6e272ab33d1a Mon Sep 17 00:00:00 2001 From: William Date: Sun, 30 Nov 2025 09:46:47 -0300 Subject: [PATCH] cleaner shared services file --- shared/services.nix | 29 ++++++++++++----------------- utils.nix | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/shared/services.nix b/shared/services.nix index 44f9208..1173b3b 100644 --- a/shared/services.nix +++ b/shared/services.nix @@ -1,48 +1,43 @@ # Shared service definitions for cross-host configuration -# Used by: -# - alexandria: DNS server (LAN) + service hosting (vaultwarden, nextcloud, jellyfin, kanidm) -# - trantor: DNS server (Tailnet) + service hosting (forgejo) { + # Host IP definitions + hosts = { + alexandria = { + lanIP = "192.168.15.142"; + tailscaleIP = "100.76.19.50"; + }; + trantor = { + tailscaleIP = "100.108.5.90"; + }; + }; + + # Service definitions - IPs are inherited from host services = [ { name = "kanidm"; domain = "auth.baduhai.dev"; host = "alexandria"; - lanIP = "192.168.15.142"; - tailscaleIP = "100.76.19.50"; - port = 8443; } { name = "vaultwarden"; domain = "pass.baduhai.dev"; host = "alexandria"; - lanIP = "192.168.15.142"; - tailscaleIP = "100.76.19.50"; - port = 8222; } { name = "forgejo"; domain = "git.baduhai.dev"; host = "trantor"; public = true; - tailscaleIP = "100.108.5.90"; - port = 3000; } { name = "nextcloud"; domain = "cloud.baduhai.dev"; host = "alexandria"; - lanIP = "192.168.15.142"; - tailscaleIP = "100.76.19.50"; - port = 443; } { name = "jellyfin"; domain = "jellyfin.baduhai.dev"; host = "alexandria"; - lanIP = "192.168.15.142"; - tailscaleIP = "100.76.19.50"; - port = 8096; } ]; } diff --git a/utils.nix b/utils.nix index 8c20ab9..e65837c 100644 --- a/utils.nix +++ b/utils.nix @@ -11,11 +11,21 @@ let # Import shared service definitions sharedServices = import ./shared/services.nix; + + # Enrich services with host IP information + enrichedServices = builtins.map (svc: + let + hostInfo = sharedServices.hosts.${svc.host} or {}; + in + svc // lib.optionalAttrs (hostInfo ? lanIP) { inherit (hostInfo) lanIP; } + // lib.optionalAttrs (hostInfo ? tailscaleIP) { inherit (hostInfo) tailscaleIP; } + ) sharedServices.services; in { - # Re-export shared services for use in host configs - inherit (sharedServices) services; + # Re-export enriched services and hosts for use in host configs + services = enrichedServices; + inherit (sharedServices) hosts; # Tag-based host configuration system mkHost = {