~rhaenys/infra-essos

ref: 110e13b8beac0b80eabc50e63b9a2a84478711f5 infra-essos/nixos/essos/hypervisor.nix -rw-r--r-- 3.6 KiB
110e13b8 — rhaenys feat: major refact, proxmox -> libvirtd 5 days ago
                                                                                
3cda9d73 rhaenys
110e13b8 rhaenys
3cda9d73 rhaenys
110e13b8 rhaenys
3cda9d73 rhaenys
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
{ lib, pkgs, config, ... }: {
  systemd.network.wait-online.enable = false;

  #networking.wlanInterfaces = {
  #  wlan-ap0 = {
  #    device = "wlp0s20f3";
  #    mac = "d2:61:cf:a2:df:57";
  #  };
  #};

  virtualisation.libvirtd = {
    enable = true;
    qemu = {
      package = pkgs.qemu_kvm;
      runAsRoot = false;
    };
    extraConfig = ''
      listen_tls = 1
      listen_tcp = 1
    '';
  };

  systemd.sockets."libvirtd-tcp".enable = true;
  systemd.sockets."libvirtd-tls".enable = true;

  systemd.network.enable = true;

  systemd.network.netdevs."wlan-ap0" = {
    enable = true;
    netdevConfig = {
      Name = "wlan-ap0";
      Kind = "wlan";
    };
    wlanConfig = {
      PhysicalDevice = 0;
      Type = "ap";
    };
  };

  systemd.network.networks."10-ap" = {
    matchConfig = {
      #Name = "wlan-ap0";
      Name = "vmbr0";
    };

    networkConfig = {
      Address = "10.1.1.1/16";
      Gateway = "10.1.1.1";
    };
  };

  networking.defaultGateway = {
    address = "192.168.0.1";
    interface = "wlp0s20f3";
  };

  networking.networkmanager.unmanaged = [ "wlan-ap0" "vmbr0" ];

  networking.bridges = {
    vmbr0 = {
      interfaces = [ "wlan-ap0" ];
    };
  };

  networking.nftables = {
    enable = true;
    ruleset = ''
      table ip nat {
        chain PREROUTING {
          type nat hook prerouting priority dstnat; policy accept;
        }
      }
    '';
  };

  networking.nat = {
    enable = true;
    internalInterfaces = [ "vmbr0" ];
    externalInterface = "wlp0s20f3";
  };

  networking.hosts = {
    "10.1.1.1" = [ "essos.local" ];
    "10.1.2.1" = [ "nas.essos.local" ];
  };

  networking.nameservers = [
    "1.1.1.1"
    "8.8.8.8"
  ];

  networking.resolvconf.enable = false;

  networking.firewall.allowedTCPPorts = [ 53 16514 16509 ];
  networking.firewall.allowedUDPPorts = [ 53 ];

  services.hostapd = {
    enable = true;
    radios = {
      wlan-ap0 = {
        band = "5g";
        channel = 153;
        networks.wlan-ap0 = {
          ssid = "essos";
          authentication.saePasswords = [{ password = "valar morghulis"; }];
        };
      };
    };
  };

  services.kea.dhcp4 = {
    enable = true;
    settings = {
      interfaces-config = {
        interfaces = [ "vmbr0" ];
      };

      valid-lifetime = 4000;
      renew-timer = 1000;
      rebind-timer = 1000;

      lease-database = {
        type = "memfile";
        persist = true;
        name = "/var/lib/kea/dhcp4.leases";
      };

      option-data = [
        {
          name = "domain-name-servers";
          code = 6;
          space = "dhcp4";
          csv-format = true;
          data = "10.1.1.1";
          always-send = true;
        }

        {
          name = "routers";
          data = "10.1.1.1";
        }
      ];

      subnet4 = [
        {
          id = 1;
          pools = [{ pool = "10.1.1.2 - 10.1.1.240"; }];
          subnet = "10.1.1.0/16";
        }
      ];
    };
  };

  services.resolved.enable = lib.mkForce false;

  services.dnsmasq = let
    resolv = pkgs.writeTextFile {
      name = "vmbr0-resolv.conf";
      text = ''
        nameserver 1.1.1.1
        nameserver 1.0.0.1
      '';
    };
  in {
    enable = true;

    settings = {
      resolv-file = "${resolv}";
      #listen-address = "10.1.1.1";
    };
  };

  services.nginx = {
    enable = true;

    recommendedProxySettings = true;
    recommendedTlsSettings = true;

    virtualHosts."console.essos.local" = {
      locations."/" = {
        proxyPass = "https://10.1.1.1:8006";
        extraConfig = ''
          proxy_ssl_server_name on;
        '';
      };
    };
  };
}