From aed29a54ce6bbc932ddcf217a760e25e8dc9355c Mon Sep 17 00:00:00 2001 From: Astro Date: Tue, 13 Apr 2021 00:11:42 +0200 Subject: [PATCH] lib/config/options+legacy: add bgp --- nix/lib/config/legacy.nix | 19 +++++++++++++++---- nix/lib/config/options.nix | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/nix/lib/config/legacy.nix b/nix/lib/config/legacy.nix index a1e2bea..311cbea 100644 --- a/nix/lib/config/legacy.nix +++ b/nix/lib/config/legacy.nix @@ -121,14 +121,25 @@ in ospf = let - hostPillar = self.lib.saltPillarFor name; - ospfConf = hostPillar.ospf; - in lib.optionalAttrs (hostPillar ? ospf && ospfConf ? stubnets-inet) { + ospfConf = ctPillar.ospf; + in lib.optionalAttrs (ctPillar ? ospf && ospfConf ? stubnets-inet) { stubNets4 = ospfConf.stubnets-inet; - } // lib.optionalAttrs (hostPillar ? ospf && ospfConf ? stubnets-inet6) { + } // lib.optionalAttrs (ctPillar ? ospf && ospfConf ? stubnets-inet6) { stubNets6 = ospfConf.stubnets-inet6; }; + bgp = + if ctPillar ? bgp + then + let + bgpConf = ctPillar.bgp; + in { + inherit (bgpConf) asn; + peers4 = bgpConf.peers-inet; + peers6 = bgpConf.peers-inet6; + } + else null; + forwardPorts = if ctPillar ? port-forwarding then map ({ proto, port, to }: { diff --git a/nix/lib/config/options.nix b/nix/lib/config/options.nix index f898135..41b1ab7 100644 --- a/nix/lib/config/options.nix +++ b/nix/lib/config/options.nix @@ -221,6 +221,32 @@ let } )); }; + bgp = mkOption { + default = null; + type = with types; nullOr (submodule { + options = bgpOpts; + }); + }; + }; + }; + bgpPeerOpts = { name, ... }: { + options = { + asn = mkOption { + type = types.int; + }; + }; + }; + bgpOpts = { + asn = mkOption { + type = types.int; + }; + peers4 = mkOption { + type = with types; attrsOf (submodule bgpPeerOpts); + default = {}; + }; + peers6 = mkOption { + type = with types; attrsOf (submodule bgpPeerOpts); + default = {}; }; }; in