Release NixOS 23.11
[NixPkgs.git] / nixos / tests / adguardhome.nix
bloba6f790b83f5fcabff61fac5443225091b7fbb833
2   name = "adguardhome";
4   nodes = {
5     nullConf = { ... }: { services.adguardhome = { enable = true; }; };
7     emptyConf = { lib, ... }: {
8       services.adguardhome = {
9         enable = true;
10       };
11     };
13     declarativeConf = { ... }: {
14       services.adguardhome = {
15         enable = true;
17         mutableSettings = false;
18         settings = {
19           schema_version = 0;
20           dns = {
21             bind_host = "0.0.0.0";
22             bootstrap_dns = "127.0.0.1";
23           };
24         };
25       };
26     };
28     mixedConf = { ... }: {
29       services.adguardhome = {
30         enable = true;
32         mutableSettings = true;
33         settings = {
34           schema_version = 0;
35           dns = {
36             bind_host = "0.0.0.0";
37             bootstrap_dns = "127.0.0.1";
38           };
39         };
40       };
41     };
43     dhcpConf = { lib, ... }: {
44       virtualisation.vlans = [ 1 ];
46       networking = {
47         # Configure static IP for DHCP server
48         useDHCP = false;
49         interfaces."eth1" = lib.mkForce {
50           useDHCP = false;
51           ipv4 = {
52             addresses = [{
53               address = "10.0.10.1";
54               prefixLength = 24;
55             }];
57             routes = [{
58               address = "10.0.10.0";
59               prefixLength = 24;
60             }];
61           };
62         };
64         # Required for DHCP
65         firewall.allowedUDPPorts = [ 67 68 ];
66       };
68       services.adguardhome = {
69         enable = true;
70         allowDHCP = true;
71         mutableSettings = false;
72         settings = {
73           schema_version = 0;
74           dns = {
75             bind_host = "0.0.0.0";
76             bootstrap_dns = "127.0.0.1";
77           };
78           dhcp = {
79             # This implicitly enables CAP_NET_RAW
80             enabled = true;
81             interface_name = "eth1";
82             local_domain_name = "lan";
83             dhcpv4 = {
84               gateway_ip = "10.0.10.1";
85               range_start = "10.0.10.100";
86               range_end = "10.0.10.101";
87               subnet_mask = "255.255.255.0";
88             };
89           };
90         };
91       };
92     };
94     client = { lib, ... }: {
95       virtualisation.vlans = [ 1 ];
96       networking = {
97         interfaces.eth1 = {
98           useDHCP = true;
99           ipv4.addresses = lib.mkForce [ ];
100         };
101       };
102     };
103   };
105   testScript = ''
106     with subtest("Minimal (settings = null) config test"):
107         nullConf.wait_for_unit("adguardhome.service")
109     with subtest("Default config test"):
110         emptyConf.wait_for_unit("adguardhome.service")
111         emptyConf.wait_for_open_port(3000)
113     with subtest("Declarative config test, DNS will be reachable"):
114         declarativeConf.wait_for_unit("adguardhome.service")
115         declarativeConf.wait_for_open_port(53)
116         declarativeConf.wait_for_open_port(3000)
118     with subtest("Mixed config test, check whether merging works"):
119         mixedConf.wait_for_unit("adguardhome.service")
120         mixedConf.wait_for_open_port(53)
121         mixedConf.wait_for_open_port(3000)
122         # Test whether merging works properly, even if nothing is changed
123         mixedConf.systemctl("restart adguardhome.service")
124         mixedConf.wait_for_unit("adguardhome.service")
125         mixedConf.wait_for_open_port(3000)
127     with subtest("Testing successful DHCP start"):
128         dhcpConf.wait_for_unit("adguardhome.service")
129         client.wait_for_unit("network-online.target")
130         # Test IP assignment via DHCP
131         dhcpConf.wait_until_succeeds("ping -c 5 10.0.10.100")
132         # Test hostname resolution over DHCP-provided DNS
133         dhcpConf.wait_until_succeeds("ping -c 5 client.lan")
134   '';