diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index a8ab81d..812f190 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -100,6 +100,10 @@ let inherit self nixpkgs system; }; + gateway-report = import ./gateway-report.nix { + inherit self nixpkgs system; + }; + vlan-report = import ./vlan-report.nix { inherit self nixpkgs system; }; @@ -111,6 +115,6 @@ in rootfs-packages // vm-packages // device-templates // openwrt-packages // network-graphs // network-cypher-graphs // starlink // subnetplans // { inherit export-openwrt-models export-config dns-slaves encrypt-secrets decrypt-secrets switch-to-production - homepage vlan-report + homepage gateway-report vlan-report ; } diff --git a/nix/pkgs/gateway-report.nix b/nix/pkgs/gateway-report.nix new file mode 100644 index 000000000..509ee3f --- /dev/null +++ b/nix/pkgs/gateway-report.nix @@ -0,0 +1,111 @@ +{ self, nixpkgs, system }: +with nixpkgs.legacyPackages.${system}; +let + config = self.lib.config; + +in +writeText "vlan-report.md" '' + # Gateway Report + + ${lib.concatMapStrings (net: + let + netConfig = config.site.net.${net}; + + routers4 = builtins.filter (hostName: + config.site.hosts ? ${hostName} && + config.site.hosts.${hostName}.isRouter + ) ( + builtins.attrNames netConfig.hosts4 + ); + + routers6 = builtins.filter (hostName: + config.site.hosts ? ${hostName} && + config.site.hosts.${hostName}.isRouter + ) (lib.unique ( + builtins.concatMap builtins.attrNames (builtins.attrValues netConfig.hosts6) + )); + + upstreamAt = l: n: + if n < builtins.length l + then + let + hostName = builtins.elemAt l n; + hostConfig = config.site.hosts.${hostName}; + providers = + map ({ upstream, ... }: upstream.provider) ( + builtins.filter ({ upstream, ... }: + upstream.provider or null != null + ) (builtins.attrValues hostConfig.interfaces) + ); + in + "${hostName}${ + lib.optionalString (providers != []) " (${lib.concatStringsSep ", " providers})" + }" + else ""; + + in + lib.optionalString (net != "core" && (routers4 != [] || routers6 != [])) '' + ## Network ${net} + + ${lib.optionalString (routers4 != []) '' + ### IPv4 `${netConfig.subnet4}` + + | Address | Name | Upstream | Fallback | + |-|-|-|-| + ${lib.concatMapStrings (hostName: + let + hostConfig = config.site.hosts.${hostName}; + isDhcpDefault = hostName == netConfig.dhcp.router or null; + upstream4a = upstreamAt hostConfig.ospf.allowedUpstreams 0; + upstream4b = upstreamAt hostConfig.ospf.allowedUpstreams 1; + in '' + |`${ + netConfig.hosts4.${hostName} + }`|${ + if isDhcpDefault + then "**${hostName}**" + else hostName + }|${ + upstream4a + }|${ + upstream4b + }| + '' + ) (lib.naturalSort routers4)} + ''} + + ${lib.optionalString (routers6 != {}) '' + ### IPv6: ${lib.concatStringsSep " " ( + map (s: "`${s}`") ( + builtins.attrValues netConfig.subnets6 + ) + )} + + | Address | Name | Upstream | Description | + |-|-|-|-| + ${lib.concatMapStrings (hostName: + let + hostConfig = config.site.hosts.${hostName}; + upstream6a = upstreamAt hostConfig.ospf.allowedUpstreams6 0; + upstream6b = upstreamAt hostConfig.ospf.allowedUpstreams6 1; + in '' + |${ + lib.concatMapStringsSep " " (ctx: + "`${netConfig.hosts6.${ctx}.${hostName}}`" + ) (builtins.filter (ctx: + netConfig.hosts6.${ctx} ? ${hostName} + ) (builtins.attrNames netConfig.hosts6)) + }|${ + hostName + }|${ + upstream6a + }|${ + upstream6b + }| + '' + ) (lib.naturalSort routers6)} + ''} + + '' + ) (lib.naturalSort (builtins.attrNames config.site.net))} +'' diff --git a/nix/pkgs/homepage/default.nix b/nix/pkgs/homepage/default.nix index 906a424..e4ba000 100644 --- a/nix/pkgs/homepage/default.nix +++ b/nix/pkgs/homepage/default.nix @@ -7,7 +7,9 @@ let - inherit (self.packages.${system}) network-graphs subnetplans vlan-report; + inherit (self.packages.${system}) + gateway-report network-graphs + subnetplans vlan-report; in stdenv.mkDerivation { @@ -22,6 +24,7 @@ stdenv.mkDerivation { buildPhase = '' pandoc -t html ${../../../doc/hello.md} > index.html pandoc -t html ${vlan-report} > vlan-report.html + pandoc -t html ${gateway-report} > gateway-report.html ln -s ${substituteAll { src = ./figure.html; img = "physical.png"; diff --git a/nix/pkgs/homepage/header.html b/nix/pkgs/homepage/header.html index 195abec..5fdc6ed 100644 --- a/nix/pkgs/homepage/header.html +++ b/nix/pkgs/homepage/header.html @@ -19,6 +19,7 @@