From 0a6bf04fd2f283f0aa41c78624189af6599b34d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Tue, 11 Apr 2023 00:24:56 +0200 Subject: [PATCH] flake: move hostRegistry to lib --- flake.nix | 21 +-------------------- lib/network.nix | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 lib/network.nix diff --git a/flake.nix b/flake.nix index c1a5a3a8..8df2c96c 100644 --- a/flake.nix +++ b/flake.nix @@ -223,27 +223,8 @@ let inherit (nixos) lib; - extractZwHosts = { hosts4, hosts6, ... }: - lib.recursiveUpdate ( - builtins.foldl' (result: name: - lib.recursiveUpdate result { - "${name}".ip4 = hosts4."${name}"; - } - ) {} (builtins.attrNames hosts4) - ) ( - builtins.foldl' (result: ctx: - builtins.foldl' (result: name: - lib.recursiveUpdate result { - "${name}".ip6 = hosts6."${ctx}"."${name}"; - } - ) result (builtins.attrNames hosts6."${ctx}") - ) {} (builtins.attrNames hosts6) - ); + inherit (import ./lib/network.nix { inherit lib zentralwerk; }) hostRegistry; - hostRegistry = - builtins.foldl' (result: net: - lib.recursiveUpdate result (extractZwHosts zentralwerk.lib.config.site.net."${net}") - ) {} [ "core" "cluster" "c3d2" "serv" "flpk" "pub" ]; overlayList = [ self.overlays diff --git a/lib/network.nix b/lib/network.nix new file mode 100644 index 00000000..7cab5988 --- /dev/null +++ b/lib/network.nix @@ -0,0 +1,25 @@ +{ lib, zentralwerk }: + +rec { + extractZwHosts = { hosts4, hosts6, ... }: + lib.recursiveUpdate ( + builtins.foldl' (result: name: + lib.recursiveUpdate result { + "${name}".ip4 = hosts4."${name}"; + } + ) {} (builtins.attrNames hosts4) + ) ( + builtins.foldl' (result: ctx: + builtins.foldl' (result: name: + lib.recursiveUpdate result { + "${name}".ip6 = hosts6."${ctx}"."${name}"; + } + ) result (builtins.attrNames hosts6."${ctx}") + ) {} (builtins.attrNames hosts6) + ); + + hostRegistry = + builtins.foldl' (result: net: + lib.recursiveUpdate result (extractZwHosts zentralwerk.lib.config.site.net."${net}") + ) {} [ "core" "cluster" "c3d2" "serv" "flpk" "pub" ]; +}