Skip to content

Commit

Permalink
bird: add templates
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelCoding committed Nov 12, 2024
1 parent 5a0fb26 commit f7d4de7
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,38 @@ in
services.bird2 = {
config =
let
protocols = lib.flatten (lib.mapAttrsToList
(type: entries: lib.mapAttrsToList
(name: conf: ''
protocol ${if type == "ospfv2" then "ospf v2" else if type == "ospfv3" then "ospf v3" else type} ${name} {
${conf}
}
'')
entries)
cfg.protocols);
mkTemplate = { name, type, conf }: ''
template ${type} ${name} {
${conf}
}
'';

mkTemplates = templates: lib.flatten (lib.mapAttrsToList
(type: entries:
lib.mapAttrsToList
(name: conf: mkTemplate { inherit name type conf; })
entries)
templates);

mkProtocol = { name, type, conf }: ''
protocol ${if type == "ospfv2" then "ospf v2" else if type == "ospfv3" then "ospf v3" else type} ${name} {
${conf}
}
'';

mkProtocols = protocols: lib.flatten (lib.mapAttrsToList
(type: entries:
lib.mapAttrsToList
(name: conf: mkProtocol { inherit name type conf; })
entries)
protocols);
in
#hostname ${cfg.hostName};
''
router id ${cfg.routerId};
${builtins.concatStringsSep "\n" protocols}
${builtins.concatStringsSep "\n" (mkTemplates cfg.templates)}
${builtins.concatStringsSep "\n" (mkProtocols cfg.protocols)}
'';
};
};
Expand Down

0 comments on commit f7d4de7

Please sign in to comment.