feat: generating firewall forwarding rules from individual machiene configs complete

This commit is contained in:
silver 2023-01-15 18:27:21 +00:00
parent c5f1bedec4
commit badcfe1ada
3 changed files with 27 additions and 9 deletions

View file

@ -16,6 +16,14 @@
A list of routes to forward A list of routes to forward
''; '';
}; };
# need to seperate it out as to not cause infinite loops
forward_parsed = lib.mkOption {
default = "";
type = lib.types.str;
description = ''
A list of routes to forward joined as a single string
'';
};
}; };
}; };
@ -69,7 +77,7 @@
# ip saddr 193.1.99.123 tcp dport 443 counter packets 0 bytes 0 accept # ip saddr 193.1.99.123 tcp dport 443 counter packets 0 bytes 0 accept
# can basically make each machiene responsibile for their own forwarding (in config at least) # can basically make each machiene responsibile for their own forwarding (in config at least)
${lib.strings.concatMapStrings (x: x + "\n") config.skynet_firewall.forward} ${config.skynet_firewall.forward_parsed}
counter packets 0 bytes 0 reject with icmp type admin-prohibited counter packets 0 bytes 0 reject with icmp type admin-prohibited
} }

View file

@ -1,8 +1,5 @@
{ pkgs, ... }: { pkgs, lib, nodes, ... }: {
{
imports = [ imports = [
# applications for this particular server # applications for this particular server
../applications/firewall.nix ../applications/firewall.nix
]; ];
@ -14,6 +11,19 @@
}; };
# this server is teh firewall # this server is teh firewall
skynet_firewall.enable = true; skynet_firewall = {
enable = true;
# gonna have to get all the
forward_parsed =
# merge together with a newline char
lib.strings.concatMapStrings (x: x + "\n") (
# merge the lists together
builtins.concatLists (
# using this function "(key: value: value.config.skynet_firewall.forward)" turn the values ointo a list
lib.attrsets.mapAttrsToList (key: value: value.config.skynet_firewall.forward) nodes
)
);
};
} }

View file

@ -1,8 +1,8 @@
{ pkgs, ... }: { pkgs, ... }: {
{
imports = [ imports = [
# import it in so the options are available
../applications/firewall.nix
]; ];
skynet_firewall.forward = [ skynet_firewall.forward = [