vuko | 740a52d | 2022-12-27 20:45:00 +0100 | [diff] [blame] | 1 | { config, pkgs, modulesPath, ... }: |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 2 | |
| 3 | let |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 4 | hw = builtins.fromJSON (builtins.readFile ./hw.json); |
| 5 | fw = import ./fw-7535.nix; |
| 6 | vuko-pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFhaCaC/CVYv6hphqmEdKaPrIn+Q946+myvL9SSnzFZk vuko@eagle"; |
| 7 | q3k-pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG599UildOrAq+LIOQjKqtGMwjgjIxozI1jtQQRKHtCP q3k@mimeomia"; |
| 8 | networks = { |
| 9 | uplink = { |
| 10 | description = "Hackerspace Internet Uplink"; |
| 11 | hw_addr = builtins.elemAt fw.hw_addresses 0; |
| 12 | ipv4 = "185.236.240.5"; |
| 13 | ipv6 = "2a0d:eb00:2137:1::3"; |
| 14 | }; |
| 15 | lan = { |
| 16 | description = "Hackerspace LAN"; |
| 17 | hw_addr = builtins.elemAt fw.hw_addresses 1; |
| 18 | ipv4 = "10.8.1.2"; |
| 19 | ipv6 = "2a0d:eb00:4242::1"; |
| 20 | }; |
| 21 | managment = { |
| 22 | description = "Management network (temporary routing)"; |
| 23 | hw_addr = builtins.elemAt fw.hw_addresses 2; |
| 24 | }; |
| 25 | lte = { |
| 26 | description = "temp LTE uplink"; |
| 27 | hw_addr = builtins.elemAt fw.hw_addresses 3; |
| 28 | }; |
| 29 | vpn = { |
| 30 | description = "Hackerspace members vpn"; |
| 31 | ipv4 = "10.9.1.1"; |
| 32 | }; |
vuko | c17bf90 | 2023-11-15 22:57:46 +0100 | [diff] [blame^] | 33 | bms = { |
| 34 | ipv4 = "10.11.1.1"; |
| 35 | }; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 36 | }; |
| 37 | hostname = "customs"; |
| 38 | openvpn-auth = import ./openvpn-auth { inherit pkgs; }; |
| 39 | secrets-path = "/etc/nixos/secrets/"; |
| 40 | update_authorized_keys = pkgs.writeShellScriptBin "update_authorized_keys" '' |
| 41 | ${pkgs.python3.withPackages (pp: [ pp.ldap3 ])}/bin/python ${./update_authorized_keys.py} ${hostname} ${secrets-path}/ldap-password.txt |
| 42 | ''; |
| 43 | |
| 44 | in { |
| 45 | imports = |
| 46 | [ |
| 47 | ./ulogd2/service.nix |
| 48 | #./hardware-configuration.nix |
vuko | 740a52d | 2022-12-27 20:45:00 +0100 | [diff] [blame] | 49 | (modulesPath + "/profiles/minimal.nix") |
| 50 | (modulesPath + "/profiles/all-hardware.nix") |
Piotr Dobrowolski | 6f6187c | 2021-10-16 23:22:22 +0200 | [diff] [blame] | 51 | ../../../bgpwtf/machines/modules/routing.nix |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 52 | ./checkinator-tracker.nix |
| 53 | ./checkinator-web.nix |
| 54 | ./mikrotik-exporter.nix |
| 55 | ./netboot.nix |
Piotr Dobrowolski | 9c5d866 | 2022-05-08 02:17:41 +0200 | [diff] [blame] | 56 | ./beyondspace.nix |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 57 | ./laserproxy/service.nix |
| 58 | ]; |
| 59 | |
Piotr Dobrowolski | ab299d4 | 2023-10-16 19:10:23 +0200 | [diff] [blame] | 60 | # Prevent spurious rebuilds due to dbus override on minimal profile |
| 61 | environment.noXlibs = false; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 62 | |
| 63 | boot.loader.grub.enable = true; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 64 | boot.loader.grub.device = "nodev"; |
| 65 | boot.loader.grub.extraConfig = '' |
| 66 | serial --unit=0 --speed=115200 |
| 67 | terminal_input serial |
| 68 | terminal_output serial |
| 69 | ''; |
| 70 | boot.kernelParams = ["console=tty0" "console=ttyS0,115200"]; |
| 71 | |
| 72 | time.timeZone = "Europe/Warsaw"; |
| 73 | |
| 74 | fileSystems."/" = { |
| 75 | device = "/dev/disk/by-partuuid/${hw.rootUUID}"; |
| 76 | fsType = "ext4"; |
| 77 | }; |
| 78 | |
| 79 | services.postfix = let acme_dir = "/var/lib/acme"; in { |
| 80 | enable = true; |
| 81 | domain = "customs.hackerspace.pl"; |
| 82 | hostname = "customs.hackerspace.pl"; |
| 83 | destination = [ "localhost" ]; |
| 84 | sslCert = "${acme_dir}/customs.hackerspace.pl/full.pem"; |
| 85 | sslKey = "${acme_dir}/customs.hackerspace.pl/key.pem"; |
| 86 | enableSmtp = true; |
| 87 | enableSubmission = false; |
| 88 | #relayHost = "hackerspace.pl"; |
| 89 | extraConfig = '' |
| 90 | inet_interfaces = loopback-only |
| 91 | ''; |
| 92 | }; |
| 93 | |
| 94 | fileSystems."/mnt/secrets" = { |
| 95 | fsType = "tmpfs"; |
| 96 | options = [ "rw" "mode=755" "size=200M" "nosuid" "nodev" "relatime" "noexec" ]; |
| 97 | }; |
| 98 | |
| 99 | networking.hostName = hostname; |
| 100 | networking.domain = "hackerspace.pl"; |
| 101 | |
| 102 | networking.useDHCP = false; |
| 103 | networking.vlans = { |
| 104 | laser = { |
| 105 | id = 4001; |
| 106 | interface = "lan"; |
| 107 | }; |
| 108 | bms = { |
| 109 | id = 4002; |
| 110 | interface = "lan"; |
| 111 | }; |
| 112 | }; |
| 113 | |
| 114 | systemd.services.secrets = { |
| 115 | enable = true; |
| 116 | description = "Copy secrets and fix permissions"; |
| 117 | script = '' |
| 118 | ${pkgs.coreutils}/bin/install --owner=root --mode=700 --directory /mnt/secrets/nginx/ |
| 119 | ${pkgs.coreutils}/bin/install --owner=root --mode=400 -t /mnt/secrets/nginx/ \ |
| 120 | ${secrets-path}/nginx/at.hackerspace.pl.key \ |
| 121 | ${secrets-path}/nginx/at.hackerspace.pl.crt |
| 122 | ${pkgs.acl}/bin/setfacl -m "u:nginx:rx" /mnt/secrets/nginx |
| 123 | ${pkgs.acl}/bin/setfacl -m "u:nginx:r" /mnt/secrets/nginx/* |
| 124 | ''; |
| 125 | wantedBy = [ "nginx.service" ]; |
| 126 | partOf = [ "nginx.service" ]; |
| 127 | serviceConfig.Type = "oneshot"; |
| 128 | serviceConfig.RemainAfterExit = "true"; |
| 129 | serviceConfig.User = "root"; |
| 130 | }; |
| 131 | |
| 132 | services.prometheus.exporters.node = { |
| 133 | enable = true; |
| 134 | listenAddress = "[::1]"; |
| 135 | port = 9100; |
| 136 | enabledCollectors = [ "systemd" ]; |
| 137 | }; |
| 138 | |
| 139 | systemd.network.links = builtins.listToAttrs (map ( |
| 140 | name: { name = "10-link-${name}"; value = { |
| 141 | enable = true; |
| 142 | matchConfig = { |
| 143 | MACAddress = networks."${name}".hw_addr; |
| 144 | }; |
| 145 | linkConfig = { |
| 146 | Name = "${name}"; |
| 147 | }; |
| 148 | }; } |
| 149 | ) (builtins.filter (name: builtins.hasAttr "hw_addr" networks."${name}") (builtins.attrNames networks))); |
| 150 | |
| 151 | #networking.interfaces.vpn = { |
| 152 | # virtual = true; |
| 153 | # name = "vpn"; |
| 154 | # #ipv4.addresses = [ { address = 10.9.1.1; prefixlen = 16; } ]; |
| 155 | #}; |
| 156 | |
| 157 | boot.kernel.sysctl = { |
| 158 | "net.ipv4.ip_forward" = true; |
| 159 | "net.ipv6.conf.all.forwarding" = true; |
| 160 | }; |
| 161 | |
| 162 | # using nftables so firewall has to be disabled |
| 163 | networking.firewall.enable = false; |
| 164 | networking.nftables.enable = true; |
| 165 | networking.nftables.ruleset = '' |
| 166 | table inet filter { |
| 167 | chain input { |
| 168 | type filter hook input priority 0; |
| 169 | |
| 170 | # accept any localhost traffic |
| 171 | iifname lo accept |
| 172 | |
| 173 | # accept traffic originated from us |
| 174 | ct state {established, related} accept |
| 175 | |
| 176 | # ICMP |
| 177 | ip6 nexthdr icmpv6 icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, mld-listener-query, nd-router-solicit } accept |
| 178 | ip protocol icmp icmp type { destination-unreachable, router-advertisement, time-exceeded, parameter-problem } accept |
| 179 | |
| 180 | # allow "ping" |
| 181 | ip6 nexthdr icmpv6 icmpv6 type echo-request accept |
| 182 | ip protocol icmp icmp type echo-request accept |
| 183 | |
| 184 | # allow OSPFv3 |
| 185 | ip6 nexthdr 89 accept |
| 186 | |
| 187 | tcp dport 22 accept |
| 188 | tcp dport 53 accept |
| 189 | udp dport 53 accept |
| 190 | tcp dport 80 accept |
| 191 | tcp dport 443 accept |
| 192 | udp dport tftp accept |
| 193 | |
| 194 | iifname managment udp dport tftp accept |
| 195 | iifname lan tcp dport 8080 accept |
| 196 | |
vuko | c17bf90 | 2023-11-15 22:57:46 +0100 | [diff] [blame^] | 197 | # mosquitto |
| 198 | iifname bms tcp dport 1883 accept |
| 199 | |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 200 | # openvpn-members |
| 201 | udp dport 20001 accept |
| 202 | tcp dport 20001 accept |
| 203 | |
| 204 | # laserproxy |
| 205 | udp dport 40200 accept |
| 206 | udp dport 50200 accept |
| 207 | |
| 208 | counter drop |
| 209 | } |
| 210 | |
| 211 | # Allow all outgoing connections. |
| 212 | chain output { |
| 213 | type filter hook output priority 0; policy accept; |
| 214 | } |
| 215 | |
| 216 | chain forward { |
| 217 | type filter hook forward priority 0; policy drop; |
| 218 | ct state {established, related} jump accepted |
| 219 | oifname "loop" jump accepted |
| 220 | ip saddr 10.8.0.0/16 iifname "lan" jump accepted |
| 221 | ip saddr 10.9.0.0/16 iifname "vpn" jump accepted |
| 222 | ip6 saddr 2a0d:eb00:4242::0/64 iifname "lan" jump accepted |
| 223 | ip6 saddr 2a0d:eb00:4242:1::0/64 iifname "vpn" jump accepted |
| 224 | ip6 saddr 2a0d:eb00:4242:1::1/128 iifname "loop" jump accepted |
| 225 | } |
| 226 | |
| 227 | chain accepted { |
| 228 | # IMPORTANT |
| 229 | # Log all connections to the outside world from LAN interface, as we are |
| 230 | # required to do so |
| 231 | oifname != "uplink" accept |
| 232 | iifname "uplink" accept |
| 233 | ip daddr { 10.0.0.0/8, 225.225.225.225/32 } accept |
| 234 | ip6 daddr { 2a0d:eb00::/29, fe80::/8 } accept |
| 235 | log group 2 accept |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | table inet net { |
| 240 | chain postrouting { |
| 241 | type nat hook postrouting priority 100; |
| 242 | ip saddr 10.8.0.0/16 oifname uplink snat ${networks.uplink.ipv4} |
| 243 | ip saddr 10.9.0.0/16 oifname uplink snat ${networks.uplink.ipv4} |
| 244 | } |
| 245 | |
| 246 | chain prerouting { |
| 247 | type nat hook prerouting priority -100; |
| 248 | |
| 249 | # Access to staszkecoin from Internet |
| 250 | ip version 4 iifname "uplink" tcp dport 8333 dnat 10.8.1.49 |
| 251 | } |
| 252 | } |
| 253 | ''; |
| 254 | |
| 255 | systemd.services."loop-netdev" = let n = "loop"; in { |
| 256 | description = "Dummy interface: loop"; |
| 257 | wantedBy = [ "network-setup.service" "sys-subsystem-net-devices-${n}.device" ]; |
| 258 | partOf = [ "network-setup.service" ]; |
| 259 | after = [ "network-pre.target" ]; |
| 260 | before = [ "network-setup.service" ]; |
| 261 | serviceConfig.Type = "oneshot"; |
| 262 | serviceConfig.RemainAfterExit = true; |
| 263 | path = [ pkgs.iproute ]; |
| 264 | script = '' |
| 265 | # Remove Dead Interfaces |
| 266 | ip link show "${n}" >/dev/null 2>&1 && ip link delete "${n}" |
| 267 | ip link add "${n}" type dummy |
| 268 | ip link set "${n}" up |
| 269 | ''; |
| 270 | postStop = '' |
| 271 | ip link delete "${n}" |
| 272 | ''; |
| 273 | }; |
| 274 | |
| 275 | |
| 276 | networking.interfaces = { |
| 277 | uplink = { |
| 278 | ipv4.addresses = [ { address = networks.uplink.ipv4; prefixLength = 31; } ]; |
| 279 | ipv6.addresses = [ |
| 280 | { address = networks.uplink.ipv6; prefixLength = 112; } |
| 281 | ]; |
| 282 | }; |
| 283 | lan = { |
| 284 | ipv4.addresses = [ { address = networks.lan.ipv4; prefixLength = 16; } ]; |
| 285 | ipv6.addresses = [ { address = networks.lan.ipv6; prefixLength = 64; } ]; |
| 286 | }; |
| 287 | loop = { |
| 288 | ipv6.addresses = [ { address = "2a0d:eb00:4242:1::1"; prefixLength = 128; } ]; |
| 289 | }; |
| 290 | laser = { |
| 291 | ipv4.addresses = [ { address = "10.11.0.1"; prefixLength = 24; } ]; |
| 292 | }; |
| 293 | bms = { |
vuko | c17bf90 | 2023-11-15 22:57:46 +0100 | [diff] [blame^] | 294 | ipv4.addresses = [ { address = networks.bms.ipv4; prefixLength = 24; } ]; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 295 | }; |
| 296 | managment = { |
| 297 | ipv4.addresses = [ { address = "10.10.1.1"; prefixLength = 24; } ]; |
| 298 | }; |
| 299 | lte = { |
| 300 | ipv4.addresses = [ { address = "192.168.1.2"; prefixLength = 24; } ]; |
| 301 | }; |
| 302 | }; |
| 303 | |
| 304 | networking.defaultGateway = { |
| 305 | address = "185.236.240.4"; |
| 306 | interface = "uplink"; |
| 307 | }; |
| 308 | networking.defaultGateway6 = { |
| 309 | address = "2a0d:eb00:2137:1::1"; |
| 310 | interface = "uplink"; |
| 311 | }; |
| 312 | |
| 313 | |
| 314 | networking.nameservers = [ "1.0.0.1" "8.8.8.8" ]; |
| 315 | |
| 316 | services.openssh = { |
| 317 | enable = true; |
Piotr Dobrowolski | ab299d4 | 2023-10-16 19:10:23 +0200 | [diff] [blame] | 318 | settings = { |
| 319 | PasswordAuthentication = false; |
| 320 | LogLevel = "INFO"; |
| 321 | }; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | users.users.root.openssh.authorizedKeys.keys = [ vuko-pubkey q3k-pubkey ]; |
| 325 | |
| 326 | services.dhcpd4 = { |
| 327 | enable = true; |
vuko | ee8f1d5 | 2022-12-31 01:04:42 +0100 | [diff] [blame] | 328 | configFile = "${./dhcpd.conf}"; |
vuko | c17bf90 | 2023-11-15 22:57:46 +0100 | [diff] [blame^] | 329 | interfaces = ["lan" "bms"]; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 330 | }; |
| 331 | |
vuko | c17bf90 | 2023-11-15 22:57:46 +0100 | [diff] [blame^] | 332 | services.mosquitto.enable = true; |
| 333 | services.mosquitto.listeners = [ |
| 334 | { |
| 335 | address = networks.bms.ipv4; |
| 336 | port = 1883; |
| 337 | settings = { |
| 338 | allow_anonymous = true; |
| 339 | }; |
| 340 | acl = [ |
| 341 | "topic readwrite #" |
| 342 | ]; |
| 343 | } |
| 344 | ]; |
| 345 | |
vuko | ee8f1d5 | 2022-12-31 01:04:42 +0100 | [diff] [blame] | 346 | # Checkinator needs access to leases file. When DynamicUser is enable this |
| 347 | # file is hidden in /var/lib/private |
| 348 | systemd.services.dhcpd4.serviceConfig.DynamicUser= pkgs.lib.mkForce false; |
| 349 | users.users.dhcpd = { |
| 350 | group = "dhcpd"; |
| 351 | isSystemUser = true; |
| 352 | uid = 1005; |
| 353 | }; |
| 354 | users.groups."dhcpd" = {}; |
| 355 | |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 356 | hscloud.routing = { |
| 357 | enable = true; |
| 358 | # TODO(q3k): make this optional in upstream |
| 359 | extra = ""; |
| 360 | routerID = "185.236.240.5"; |
| 361 | tables.master.program = true; |
| 362 | pipe.v6.aggregate_to_kernel = { |
| 363 | table = "master"; |
| 364 | peerTable = "aggregate"; |
| 365 | filterIn = '' |
| 366 | if source = RTS_OSPF then accept; |
| 367 | if source = RTS_OSPF_EXT2 then accept; |
| 368 | reject; |
| 369 | ''; |
| 370 | }; |
| 371 | ospf.v6.upstream = { |
| 372 | table = "aggregate"; |
| 373 | area."0.0.0.0" = { |
| 374 | interfaces.uplink = { type = "bcast"; }; |
| 375 | interfaces.lan = { type = "bcast"; stub = true; }; |
| 376 | interfaces.loop = { type = "ptp"; stub = true; }; |
| 377 | }; |
| 378 | }; |
| 379 | }; |
| 380 | |
| 381 | services.radvd = { |
| 382 | enable = true; |
| 383 | config = '' |
| 384 | interface lan { |
| 385 | AdvSendAdvert on; |
| 386 | prefix 2a0d:eb00:4242::/64 { |
| 387 | }; |
| 388 | route 0::/0 { }; |
| 389 | }; |
| 390 | interface vpn { |
| 391 | AdvSendAdvert on; |
| 392 | prefix 2a0d:eb00:4242:1::/64 { |
| 393 | AdvRouterAddr on; |
| 394 | }; |
| 395 | route 0::/0 { }; |
| 396 | }; |
| 397 | ''; |
| 398 | }; |
| 399 | |
| 400 | services.logrotate = { |
| 401 | enable = true; |
vuko | 740a52d | 2022-12-27 20:45:00 +0100 | [diff] [blame] | 402 | settings = { |
| 403 | "/var/log/ulogd.pcap" = { |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 404 | frequency = "weekly"; |
vuko | 740a52d | 2022-12-27 20:45:00 +0100 | [diff] [blame] | 405 | postrotate = '' |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 406 | ${pkgs.killall}/bin/killall -HUP ulogd |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 407 | ''; |
vuko | 740a52d | 2022-12-27 20:45:00 +0100 | [diff] [blame] | 408 | rotate = 55; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 409 | }; |
| 410 | }; |
| 411 | }; |
| 412 | |
| 413 | services.cron = let |
| 414 | log-neigh = pkgs.writeShellScript "log-neigh" '' |
| 415 | mkdir -p /var/log/arptables |
| 416 | chmod 700 /var/log/arptables |
| 417 | |
| 418 | # Larger than 10MB? rotate. |
| 419 | if [[ $(find /var/log/arptables/arptables.log -type f -size +10485760c 2>/dev/null) ]]; then |
| 420 | f=/var/log/arptables/$(date "+%s").log |
| 421 | cp /var/log/arptables/arptables.log $f |
| 422 | gzip -9 $f |
| 423 | rm /var/log/arptables/arptables.log |
| 424 | fi |
| 425 | |
| 426 | ip neigh >> /var/log/arptables/arptables.log |
| 427 | date --iso-8601=seconds >> /var/log/arptables/arptables.log |
| 428 | ''; |
| 429 | in { |
vuko | ca6dba9 | 2023-01-05 19:54:20 +0100 | [diff] [blame] | 430 | mailto = "both@hackerspace.pl"; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 431 | enable = true; |
| 432 | systemCronJobs = [ |
| 433 | "*/5 * * * * root ${log-neigh}" |
| 434 | "0 3 * * * root ${update_authorized_keys}/bin/update_authorized_keys" |
| 435 | ]; |
| 436 | }; |
| 437 | |
| 438 | services.knot = { |
| 439 | enable = true; |
| 440 | extraConfig = '' |
| 441 | server: |
| 442 | listen: ${networks.uplink.ipv4}@53 |
| 443 | listen: ${networks.uplink.ipv6}@53 |
| 444 | |
| 445 | zone: |
| 446 | - domain: waw.hackerspace.pl |
| 447 | storage: ${./zones} |
| 448 | file: waw.hackerspace.pl |
| 449 | - domain: i |
| 450 | storage: ${./zones} |
| 451 | file: i |
| 452 | - domain: api.ustream.tv |
| 453 | storage: ${./zones} |
| 454 | file: api.ustream.tv |
| 455 | - domain: api.eye.fi |
| 456 | storage: ${./zones} |
| 457 | file: api.eye.fi |
| 458 | log: |
| 459 | - target: syslog |
| 460 | any: info |
| 461 | ''; |
| 462 | }; |
| 463 | |
| 464 | services.nginx.enable = true; |
| 465 | services.nginx.mapHashBucketSize = 64; |
| 466 | services.nginx.appendHttpConfig = '' |
| 467 | server_names_hash_bucket_size 64; |
| 468 | ''; |
Piotr Dobrowolski | 9c5d866 | 2022-05-08 02:17:41 +0200 | [diff] [blame] | 469 | services.nginx.resolver.addresses = [ "127.0.0.1" ]; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 470 | |
vuko | 740a52d | 2022-12-27 20:45:00 +0100 | [diff] [blame] | 471 | security.acme.acceptTerms = true; |
| 472 | security.acme.defaults.email = "bofh@hackerspace.pl"; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 473 | |
| 474 | services.nginx.virtualHosts."customs.hackerspace.pl" = { |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 475 | enableACME = true; |
| 476 | |
| 477 | locations."/" = { |
| 478 | extraConfig = '' |
| 479 | return 302 https://isztar.mf.gov.pl; |
| 480 | ''; |
| 481 | }; |
| 482 | locations."/metrics/luftdaten" = { |
| 483 | proxyPass = "http://10.8.0.146"; |
| 484 | }; |
| 485 | locations."/metrics/spejsiot" = { |
vuko | 3262409 | 2022-12-22 23:09:06 +0100 | [diff] [blame] | 486 | proxyPass = "http://10.8.1.16/metrics"; |
| 487 | extraConfig = '' |
| 488 | proxy_set_header Host spejsiot.waw.hackerspace.pl; |
| 489 | ''; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 490 | }; |
| 491 | locations."/metrics/apm" = { |
| 492 | proxyPass = "http://10.8.1.40:5000/metrics"; |
| 493 | }; |
| 494 | locations."/metrics/vending" = { |
| 495 | proxyPass = "http://10.8.1.32:8000/"; |
| 496 | }; |
| 497 | locations."/metrics/sztancarka" = { |
| 498 | proxyPass = "http://10.8.0.96:8888/"; |
| 499 | }; |
| 500 | locations."/metrics/mikrotik" = { |
| 501 | proxyPass = "http://127.0.0.1:9436/metrics"; |
| 502 | extraConfig = '' |
| 503 | allow 209.250.231.127; |
| 504 | deny all; |
| 505 | ''; |
| 506 | }; |
| 507 | locations."/metrics/node" = { |
| 508 | proxyPass = "http://[::1]:9100/metrics"; |
| 509 | extraConfig = '' |
| 510 | allow 209.250.231.127; |
| 511 | deny all; |
| 512 | ''; |
| 513 | }; |
| 514 | locations."/stats/sztancarka-ppm" = { |
| 515 | proxyPass = "http://10.8.0.96:9090/api/v1/query?query=rate%28cut_count_total%5B15m%5D%29+*+60"; |
| 516 | }; |
| 517 | locations."/stats/sztancarka-last-24h" = { |
| 518 | proxyPass = "http://10.8.0.96:9090/api/v1/query?query=round(increase(cut_count_total[24h]))"; |
| 519 | }; |
| 520 | }; |
| 521 | |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 522 | services.unbound = let |
| 523 | local-zones = [ "waw.hackerspace.pl." "api.eye.fi." "api.ustream.tv." "i." ]; |
| 524 | in { |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 525 | enable = true; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 526 | |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 527 | #enableRootTrustAnchor = false; |
| 528 | |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 529 | settings = { |
| 530 | server = { |
| 531 | interface = [ |
| 532 | networks.lan.ipv4 |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 533 | networks.lan.ipv6 |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 534 | "127.0.0.1" |
| 535 | "::1" |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 536 | ]; |
| 537 | access-control = [ |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 538 | "::1/128 allow" |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 539 | "127.0.0.1/8 allow" |
| 540 | "10.0.0.0/8 allow" |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 541 | "${networks.lan.ipv6}/64 allow" |
| 542 | "${networks.lan.ipv4}/8 allow" |
| 543 | ]; |
| 544 | |
| 545 | # disable DNSSEC on locally resolved domains |
| 546 | domain-insecure = local-zones; |
| 547 | |
| 548 | # allow LAN adresses only for local domains |
| 549 | private-domain = local-zones; |
| 550 | private-address = [ |
| 551 | "10.0.0.0/8" |
| 552 | "${networks.lan.ipv6}/64" |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 553 | ]; |
| 554 | }; |
| 555 | |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 556 | # authoritative DNS servers |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 557 | stub-zone = map (name: { |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 558 | inherit name; |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 559 | stub-addr = networks.uplink.ipv4; |
vuko | 3125aa1 | 2022-12-31 02:52:24 +0100 | [diff] [blame] | 560 | }) local-zones; |
| 561 | |
| 562 | # recursive DNS servers |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 563 | forward-zone = { |
| 564 | name = "."; |
| 565 | forward-addr = "185.236.240.1"; |
| 566 | }; |
| 567 | }; |
| 568 | }; |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 569 | |
| 570 | # Public VPN access for Hackerspace members |
| 571 | services.openvpn.servers.members.config = '' |
| 572 | script-security 3 |
| 573 | auth-user-pass-verify ${openvpn-auth}/bin/openvpn-auth-member via-env |
| 574 | verify-client-cert none |
| 575 | username-as-common-name |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 576 | |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 577 | #user _openvpn |
| 578 | #group _openvpn |
| 579 | multihome |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 580 | |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 581 | port 20001 |
| 582 | proto udp |
| 583 | proto udp6 |
| 584 | dev vpn |
| 585 | dev-type tun |
| 586 | ca ${secrets-path}/openvpn-public/ca.crt |
| 587 | cert ${secrets-path}/openvpn-public/server.crt |
| 588 | key ${secrets-path}/openvpn-public/server.key |
| 589 | dh ${secrets-path}/openvpn-public/dh.pem |
| 590 | server 10.9.1.0 255.255.255.0 |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 591 | |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 592 | push "route 10.8.0.0 255.255.0.0" |
| 593 | push "route 10.9.0.0 255.255.0.0" |
| 594 | push "route 10.10.0.0 255.255.0.0" |
| 595 | push "route 10.11.0.0 255.255.0.0" |
| 596 | push "dhcp-option DNS ${networks.lan.ipv4}" |
| 597 | push "dhcp-option DOMAIN waw.hackerspace.pl" |
Piotr Dobrowolski | b6bc3e6 | 2021-10-16 21:56:59 +0200 | [diff] [blame] | 598 | |
Piotr Dobrowolski | a01905a | 2021-10-16 18:22:46 +0200 | [diff] [blame] | 599 | ifconfig-pool-persist /var/lib/openvpn-public/ipp.txt |
| 600 | #client-config-dir /var/lib/openvpn-public/ccd |
| 601 | client-to-client |
| 602 | keepalive 10 120 |
| 603 | comp-lzo |
| 604 | persist-key |
| 605 | persist-tun |
| 606 | ''; |
| 607 | |
| 608 | environment.systemPackages = with pkgs; [ |
| 609 | vim tcpdump htop nmon tmux git file procps parted dmidecode ack utillinux nmap mosh ncdu tree lz4 bind |
| 610 | rxvt_unicode.terminfo update_authorized_keys |
| 611 | ]; |
| 612 | programs.mtr.enable = true; |
| 613 | |
| 614 | environment.variables = { |
| 615 | EDITOR = "vim"; |
| 616 | }; |
| 617 | |
| 618 | system.stateVersion = "20.03"; |
| 619 | |
| 620 | boot.vesa = false; |
| 621 | boot.loader.grub.splashImage = null; |
| 622 | } |
| 623 | |