1{ lib, pkgs, ... }:
2{
3 name = "doh-proxy-rust";
4 meta.maintainers = with lib.maintainers; [ stephank ];
5
6 nodes = {
7 machine =
8 { pkgs, lib, ... }:
9 {
10 services.bind = {
11 enable = true;
12 extraOptions = "empty-zones-enable no;";
13 zones = lib.singleton {
14 name = ".";
15 master = true;
16 file = pkgs.writeText "root.zone" ''
17 $TTL 3600
18 . IN SOA ns.example.org. admin.example.org. ( 1 3h 1h 1w 1d )
19 . IN NS ns.example.org.
20 ns.example.org. IN A 192.168.0.1
21 '';
22 };
23 };
24 services.doh-proxy-rust = {
25 enable = true;
26 flags = [
27 "--server-address=127.0.0.1:53"
28 ];
29 };
30 };
31 };
32
33 testScript =
34 { nodes, ... }:
35 ''
36 url = "http://localhost:3000/dns-query"
37 query = "AAABAAABAAAAAAAAAm5zB2V4YW1wbGUDb3JnAAABAAE=" # IN A ns.example.org.
38 bin_ip = r"$'\xC0\xA8\x00\x01'" # 192.168.0.1, as shell binary string
39
40 machine.wait_for_unit("bind.service")
41 machine.wait_for_unit("doh-proxy-rust.service")
42 machine.wait_for_open_port(53)
43 machine.wait_for_open_port(3000)
44 machine.succeed(f"curl --fail -H 'Accept: application/dns-message' '{url}?dns={query}' | grep -F {bin_ip}")
45 '';
46}