Skip to content

Commit

Permalink
Enable nnf-common snippet by default, but emit a warning if not man…
Browse files Browse the repository at this point in the history
…ually defined
  • Loading branch information
thelegy committed Dec 14, 2023
1 parent 6e8d86f commit 3ef0e6a
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions checks/testCommon.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

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

Expand Down
1 change: 1 addition & 0 deletions checks/testEmpty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ machineTest ({config, ...}: {

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

output = {
Expand Down
1 change: 1 addition & 0 deletions checks/testForward.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ machineTest ({config, ...}: {

networking.nftables.firewall = {
enable = true;
snippets.nnf-common.enable = false;
zones.a.interfaces = ["a"];
zones.b.interfaces = ["b"];

Expand Down
1 change: 1 addition & 0 deletions checks/testInheritance.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ machineTest ({config, ...}: {

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

zones.a.interfaces = ["a"];

Expand Down
1 change: 1 addition & 0 deletions checks/testNat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
snippets.nnf-common.enable = true;
zones.a.interfaces = ["a"];
zones.b.interfaces = ["b"];
Expand Down
1 change: 1 addition & 0 deletions checks/testPortRules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ machineTest ({config, ...}: {

networking.nftables.firewall = {
enable = true;
snippets.nnf-common.enable = false;
rules.nose = {
from = "all";
to = ["fw"];
Expand Down
1 change: 1 addition & 0 deletions checks/testRuleType.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ machineTest ({config, ...}: {

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

rules.rule = {
from = "all";
Expand Down
1 change: 1 addition & 0 deletions checks/testWebserver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
snippets.nnf-common.enable = true;
rules.webserver = {
from = "all";
Expand Down
1 change: 1 addition & 0 deletions checks/testZoneExpressions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
snippets.nnf-common.enable = true;
zones.a.interfaces = ["a"];
zones.a.ipv4Addresses = ["192.168.1.0/24"];
Expand Down
1 change: 0 additions & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ We will look at the following `configuration.nix´.
snippets.nnf-common.enable = true;
```
This will enable the firewall and also the `nnf-common` snippet.
(Actually the snippet will also enable the firewall, so if you are using it, enabling it by hand is not required.)

### Zones
Next we will add some [zones](zones):
Expand Down
10 changes: 9 additions & 1 deletion nftables-snippets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,16 @@ in {
};

config = mkMerge [
{
assertions = [
{
assertion = cfg.nnf-common.enable -> config.networking.nftables.firewall.enable;
message = "You enabled the `nnf-common` firewall snippet, but you did not enable the firewall itself.";
}
];
}

(mkIf cfg.nnf-common.enable {
networking.nftables.firewall.enable = true;
networking.nftables.firewall.snippets = mkDefault {
nnf-conntrack.enable = true;
nnf-default-stopRuleset.enable = true;
Expand Down
14 changes: 14 additions & 0 deletions nftables-zoned.nix
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ in {
}
];

networking.nftables.firewall.snippets.nnf-common.enable = let
msg = concatStringsSep " " [
"To ease the migration for the nixos-nftables-firewall moving to snippets"
"the option `networking.nftables.firewall.snippets.nnf-common.enable` has"
"been defaulted to `true`. It will some day be switched to default to `false`"
"Please review, if these snippets do, what you need, make overrides as needed"
"and be warned, that their functionality might change in the future."
"You can read more about snippets here:\n"
"https://thelegy.github.io/nixos-nftables-firewall/snippets/\n"
"To remove this warning manually define the option."
];
in
mkOverride 1499 (warn msg true);

networking.nftables.firewall.zones.${cfg.localZoneName} = {
localZone = true;
};
Expand Down

0 comments on commit 3ef0e6a

Please sign in to comment.