Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions checks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ in
testInheritance = import ./testInheritance.nix lib;

testRuleType = import ./testRuleType.nix lib;

testNixosFirewall = import ./testNixosFirewall.nix lib;
};
}
54 changes: 54 additions & 0 deletions checks/testNixosFirewall.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
machineTest,
flakes,
...
}:
machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
snippets.nnf-common.enable = false;
snippets.nnf-nixos-firewall.enable = true;
};

networking.firewall.allowedTCPPorts = [22];
networking.firewall.allowedTCPPortRanges = [
{ from = 80; to = 90; }
];
networking.firewall.allowedUDPPorts = [220];
networking.firewall.allowedUDPPortRanges = [
{ from = 32768; to = 60999; }
];

output = {
expr = config.networking.nftables.ruleset;
expected = ''
table inet firewall {

chain forward {
type filter hook forward priority 0; policy drop;
}

chain input {
type filter hook input priority 0; policy drop
jump rule-nixos-firewall
}

chain postrouting {
type nat hook postrouting priority srcnat;
}

chain prerouting {
type nat hook prerouting priority dstnat;
}

chain rule-nixos-firewall {
tcp dport { 22, 80-90 } accept
udp dport { 220, 32768-60999 } accept
}

}
'';
};
})
2 changes: 2 additions & 0 deletions modules/snippets/nnf-nixos-firewall.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ in
from = mkDefault "all";
to = [localZoneName];
allowedTCPPorts = config.networking.firewall.allowedTCPPorts;
allowedTCPPortRanges = config.networking.firewall.allowedTCPPortRanges;
allowedUDPPorts = config.networking.firewall.allowedUDPPorts;
allowedUDPPortRanges = config.networking.firewall.allowedUDPPortRanges;
ignoreEmptyRule = true;
};
};
Expand Down