Skip to content

Commit

Permalink
Apply alejandra formatting
Browse files Browse the repository at this point in the history
According to the current working document for the formatting RFC
(https://github.com/nix-rfc-101/rfcs/blob/master/rfcs/0101-nix-formatting.md)
alejandra will not be used ase the base for the common formatter. But
alejandra is the formatter that produces the most similar output to the
one proposed by the RFC right now.
  • Loading branch information
thelegy committed Sep 17, 2023
1 parent 6cb2533 commit cfac118
Show file tree
Hide file tree
Showing 17 changed files with 641 additions and 571 deletions.
38 changes: 16 additions & 22 deletions checks/default.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
system:
flakes@{ nixpkgs, ... }:
system: flakes @ {nixpkgs, ...}: let
lib = nixpkgs.lib.extend (import ./utils.nix system nixpkgs) // {inherit flakes;};
in
with lib; {
tests = run-tests {
testChains = import ./testChains.nix lib;

let
testEmpty = import ./testEmpty.nix lib;

lib = nixpkgs.lib.extend (import ./utils.nix system nixpkgs) // { inherit flakes; };
testZoneExpressions = import ./testZoneExpressions.nix lib;

in with lib; {
tests = run-tests {
testWebserver = import ./testWebserver.nix lib;

testChains = import ./testChains.nix lib;
testForward = import ./testForward.nix lib;

testEmpty = import ./testEmpty.nix lib;
testNat = import ./testNat.nix lib;

testZoneExpressions = import ./testZoneExpressions.nix lib;
testPortRules = import ./testPortRules.nix lib;

testWebserver = import ./testWebserver.nix lib;
testInheritance = import ./testInheritance.nix lib;

testForward = import ./testForward.nix lib;

testNat = import ./testNat.nix lib;

testPortRules = import ./testPortRules.nix lib;

testInheritance = import ./testInheritance.nix lib;

testRuleType = import ./testRuleType.nix lib;

};
}
testRuleType = import ./testRuleType.nix lib;
};
}
74 changes: 51 additions & 23 deletions checks/testChains.nix
Original file line number Diff line number Diff line change
@@ -1,36 +1,65 @@
{ machineTest
, flakes
, ... }:

machineTest ({ config, ... }: {

imports = [ flakes.self.nixosModules.default ];
{
machineTest,
flakes,
...
}:
machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.chains = {
input.a.rules = [
{ onExpression = "iifname empty-goto"; goto = "empty"; }
{ onExpression = "iifname single-goto"; goto = "single"; }
{ onExpression = "iifname multiple-goto"; goto = "multiple"; }
{
onExpression = "iifname empty-goto";
goto = "empty";
}
{
onExpression = "iifname single-goto";
goto = "single";
}
{
onExpression = "iifname multiple-goto";
goto = "multiple";
}

{ onExpression = "iifname empty-jump"; jump = "empty"; }
{ onExpression = "iifname inlinable-jump"; jump = "inlinable"; }
{ onExpression = "iifname multiple-jump"; jump = "multiple"; }
{ onExpression = "iifname indirect1-jump"; jump = "indirect1"; }
{ onExpression = "iifname accept-jump"; jump = "accept"; }
{
onExpression = "iifname empty-jump";
jump = "empty";
}
{
onExpression = "iifname inlinable-jump";
jump = "inlinable";
}
{
onExpression = "iifname multiple-jump";
jump = "multiple";
}
{
onExpression = "iifname indirect1-jump";
jump = "indirect1";
}
{
onExpression = "iifname accept-jump";
jump = "accept";
}
];

accept.a.rules = [ "accept" ];
empty.a.rules = [ ];
single.a.rules = [ "foo" ];
inlinable.a.rules = [ "foo" ];
indirect1.a.rules = [ { onExpression = "iifname indirect2"; jump = "indirect2"; } ];
indirect2.a.rules = [ "foo" ];
accept.a.rules = ["accept"];
empty.a.rules = [];
single.a.rules = ["foo"];
inlinable.a.rules = ["foo"];
indirect1.a.rules = [
{
onExpression = "iifname indirect2";
jump = "indirect2";
}
];
indirect2.a.rules = ["foo"];
multiple.a.rules = [
"tcp dport 22 accept"
"counter drop"
];

unused.a.rules = [ ];
unused.a.rules = [];
};

output = {
Expand Down Expand Up @@ -71,5 +100,4 @@ machineTest ({ config, ... }: {
}
'';
};

})
15 changes: 7 additions & 8 deletions checks/testEmpty.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{ machineTest
, flakes
, ... }:

machineTest ({ config, ... }: {

imports = [ flakes.self.nixosModules.default ];
{
machineTest,
flakes,
...
}:
machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
Expand Down Expand Up @@ -53,5 +53,4 @@ machineTest ({ config, ... }: {
}
'';
};

})
35 changes: 17 additions & 18 deletions checks/testForward.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
{ machineTest
, flakes
, ... }:

machineTest ({ config, ... }: {

imports = [ flakes.self.nixosModules.default ];
{
machineTest,
flakes,
...
}:
machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
zones.a.interfaces = [ "a" ];
zones.b.interfaces = [ "b" ];
zones.a.interfaces = ["a"];
zones.b.interfaces = ["b"];

rules.ssh.enable = false;

rules.forward = {
from = [ "a" ];
to = [ "b" ];
allowedTCPPorts = [ 22 ];
from = ["a"];
to = ["b"];
allowedTCPPorts = [22];
};

rules.from-all = {
from = "all";
to = [ "b" ];
allowedTCPPorts = [ 25 ];
to = ["b"];
allowedTCPPorts = [25];
};

rules.to-all = {
from = [ "a" ];
from = ["a"];
to = "all";
allowedTCPPorts = [ 80 ];
allowedTCPPorts = [80];
};

rules.from-to-all = {
from = "all";
to = "all";
allowedTCPPorts = [ 42 ];
allowedTCPPorts = [42];
};
};

Expand Down Expand Up @@ -94,5 +94,4 @@ machineTest ({ config, ... }: {
}
'';
};

})
34 changes: 16 additions & 18 deletions checks/testInheritance.nix
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
{ machineTest
, flakes
, ... }:

machineTest ({ config, ... }: {

imports = [ flakes.self.nixosModules.default ];
{
machineTest,
flakes,
...
}:
machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;

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

zones.b = {
parent = "a";
interfaces = [ "b" ];
interfaces = ["b"];
};

zones.c = {
parent = "fw";
interfaces = [ "c" ];
interfaces = ["c"];
};

rules.b-to-b = {
from = [ "b" ];
to = [ "b" ];
allowedTCPPorts = [ 1000 ];
from = ["b"];
to = ["b"];
allowedTCPPorts = [1000];
};

rules.b-to-c = {
from = [ "b" ];
to = [ "c" ];
allowedTCPPorts = [ 2000 ];
from = ["b"];
to = ["c"];
allowedTCPPorts = [2000];
};

};

output = {
Expand Down Expand Up @@ -84,5 +83,4 @@ machineTest ({ config, ... }: {
}
'';
};

})
23 changes: 11 additions & 12 deletions checks/testNat.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{ machineTest
, flakes
, ... }:

machineTest ({ config, ... }: {

imports = [ flakes.self.nixosModules.default ];
{
machineTest,
flakes,
...
}:
machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
zones.a.interfaces = [ "a" ];
zones.b.interfaces = [ "b" ];
zones.a.interfaces = ["a"];
zones.b.interfaces = ["b"];

rules.nat = {
from = [ "a" ];
to = [ "b" ];
from = ["a"];
to = ["b"];
masquerade = true;
};
};
Expand Down Expand Up @@ -62,5 +62,4 @@ machineTest ({ config, ... }: {
}
'';
};

})
42 changes: 26 additions & 16 deletions checks/testPortRules.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
{ machineTest
, flakes
, ... }:

machineTest ({ config, ... }: {

imports = [ flakes.self.nixosModules.default ];
{
machineTest,
flakes,
...
}:
machineTest ({config, ...}: {
imports = [flakes.self.nixosModules.default];

networking.nftables.firewall = {
enable = true;
rules.nose = {
from = "all";
to = [ "fw" ];
allowedTCPPorts = [ 555 ];
to = ["fw"];
allowedTCPPorts = [555];
};
rules.range = {
from = "all";
to = [ "fw" ];
allowedUDPPortRanges = [ { from = 60000; to = 62000; } ];
to = ["fw"];
allowedUDPPortRanges = [
{
from = 60000;
to = 62000;
}
];
};
rules.multiple = {
from = "all";
to = [ "fw" ];
to = ["fw"];
allowedTCPPortRanges = [
{ from = 42000; to = 42004; }
{ from = 42005; to = 62009; }
{
from = 42000;
to = 42004;
}
{
from = 42005;
to = 62009;
}
];
allowedUDPPorts = [ 42 1337 ];
allowedUDPPorts = [42 1337];
};
};

Expand Down Expand Up @@ -80,5 +91,4 @@ machineTest ({ config, ... }: {
}
'';
};

})
Loading

0 comments on commit cfac118

Please sign in to comment.