create shared nixos config between physical and VM
rename nixos -> nix
This commit is contained in:
parent
472175c5a3
commit
32154e7163
39 changed files with 114 additions and 196 deletions
|
@ -1,165 +0,0 @@
|
|||
{ lib, config, machine, ... }:
|
||||
let cfg = config.lab.networking;
|
||||
in {
|
||||
imports = [ ./dmz ];
|
||||
|
||||
options.lab.networking = {
|
||||
allowDMZConnectivity = lib.mkOption {
|
||||
default = false;
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Whether to allow networking on the DMZ bridge interface.
|
||||
'';
|
||||
};
|
||||
|
||||
staticDMZIPv4Address = lib.mkOption {
|
||||
default = "";
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Assign a static IPv4 address on the DMZ interface.
|
||||
'';
|
||||
};
|
||||
|
||||
staticDMZIPv6Address = lib.mkOption {
|
||||
default = "";
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Assign a static IPv6 address on the DMZ interface.
|
||||
'';
|
||||
};
|
||||
|
||||
publicIPv4 = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Public IPv4 address of our home.
|
||||
'';
|
||||
};
|
||||
|
||||
dockerSwarmInternalIPv4 = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Internal IPv4 address of the Docker Swarm.
|
||||
'';
|
||||
};
|
||||
|
||||
dockerSwarmIPv6 = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Globally routable IPv6 address of the Docker Swarm.
|
||||
'';
|
||||
};
|
||||
|
||||
dmzRouterIPv4 = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The router's IPv4 address on the DMZ network.
|
||||
'';
|
||||
};
|
||||
|
||||
dmzServicesIPv4 = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The IPv4 address of the interface serving DHCP and DNS on the DMZ network.
|
||||
'';
|
||||
};
|
||||
|
||||
dmzServicesIPv6 = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The IPv6 address of the interface serving DHCP and DNS on the DMZ network.
|
||||
'';
|
||||
};
|
||||
|
||||
dmzBridgeName = lib.mkOption {
|
||||
default = "bridgedmz";
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The name of the DMZ bridge.
|
||||
'';
|
||||
};
|
||||
|
||||
mainNicNamePattern = lib.mkOption {
|
||||
default = "en*";
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
Pattern to match the name of this machine's main NIC.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
networking = {
|
||||
hostName = machine.hostName;
|
||||
domain = machine.domain;
|
||||
nftables.enable = true;
|
||||
useDHCP = machine.type == "virtual";
|
||||
|
||||
firewall = {
|
||||
enable = true;
|
||||
checkReversePath = false;
|
||||
};
|
||||
};
|
||||
|
||||
systemd.network = lib.mkIf (machine.type == "physical") {
|
||||
enable = true;
|
||||
|
||||
netdevs = {
|
||||
"20-vlandmz" = {
|
||||
vlanConfig.Id = 30;
|
||||
|
||||
netdevConfig = {
|
||||
Kind = "vlan";
|
||||
Name = "vlandmz";
|
||||
};
|
||||
};
|
||||
|
||||
"20-bridgedmz" = {
|
||||
netdevConfig = {
|
||||
Kind = "bridge";
|
||||
Name = cfg.dmzBridgeName;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
networks = {
|
||||
"30-main-nic" = {
|
||||
matchConfig.Name = cfg.mainNicNamePattern;
|
||||
vlan = [ "vlandmz" ];
|
||||
|
||||
networkConfig = {
|
||||
DHCP = "yes";
|
||||
};
|
||||
};
|
||||
|
||||
"40-vlandmz" = {
|
||||
matchConfig.Name = "vlandmz";
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
|
||||
networkConfig = {
|
||||
IPv6AcceptRA = false;
|
||||
LinkLocalAddressing = "no";
|
||||
Bridge = cfg.dmzBridgeName;
|
||||
};
|
||||
};
|
||||
|
||||
"40-bridgedmz" = {
|
||||
matchConfig.Name = cfg.dmzBridgeName;
|
||||
linkConfig.RequiredForOnline = "carrier";
|
||||
|
||||
networkConfig = {
|
||||
IPv6AcceptRA = cfg.allowDMZConnectivity;
|
||||
LinkLocalAddressing = if cfg.allowDMZConnectivity then "ipv6" else "no";
|
||||
DHCP = lib.mkIf (cfg.allowDMZConnectivity && cfg.staticDMZIPv4Address == "") "yes";
|
||||
Address = lib.lists.optional (cfg.staticDMZIPv4Address != "") cfg.staticDMZIPv4Address
|
||||
++ lib.lists.optional (cfg.staticDMZIPv6Address != "") cfg.staticDMZIPv6Address;
|
||||
};
|
||||
};
|
||||
|
||||
"40-vms" = {
|
||||
matchConfig.Name = "vm-*";
|
||||
networkConfig.Bridge = cfg.dmzBridgeName;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
{ pkgs, lib, config, dns, ... }@inputs:
|
||||
let
|
||||
cfg = config.lab.networking.dmzServices;
|
||||
kunisZoneFile = pkgs.writeTextFile {
|
||||
name = "kunis-zone-file";
|
||||
text = (dns.lib.toString "kun.is" (import ./zones/kun.is.nix inputs));
|
||||
};
|
||||
|
||||
geokunis2nlZoneFile = pkgs.writeTextFile {
|
||||
name = "geokunis2nl-zone-file";
|
||||
text = (dns.lib.toString "geokunis2.nl" (import ./zones/geokunis2.nl.nix inputs));
|
||||
};
|
||||
in
|
||||
{
|
||||
options.lab.networking.dmzServices.enable = lib.mkOption {
|
||||
default = false;
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Whether to enable an authoritative DNS server and DNSmasq for DMZ network.
|
||||
'';
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
lab.networking.allowDMZConnectivity = true;
|
||||
|
||||
networking.firewall.interfaces.${config.lab.networking.dmzBridgeName} = {
|
||||
allowedTCPPorts = [ 53 5353 ];
|
||||
allowedUDPPorts = [ 53 67 5353 ];
|
||||
};
|
||||
|
||||
services = {
|
||||
bind = {
|
||||
enable = true;
|
||||
forwarders = [ ];
|
||||
|
||||
extraOptions = ''
|
||||
allow-transfer { none; };
|
||||
allow-recursion { none; };
|
||||
version none;
|
||||
notify no;
|
||||
'';
|
||||
|
||||
zones = {
|
||||
"kun.is" = {
|
||||
master = true;
|
||||
file = kunisZoneFile;
|
||||
allowQuery = [ "any" ];
|
||||
};
|
||||
|
||||
"geokunis2.nl" = {
|
||||
master = true;
|
||||
file = geokunis2nlZoneFile;
|
||||
allowQuery = [ "any" ];
|
||||
slaves = [
|
||||
"87.253.155.96/27"
|
||||
"157.97.168.160/27"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
dnsmasq = {
|
||||
enable = true;
|
||||
settings = import ./dnsmasq.nix inputs;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
{ config, ... }:
|
||||
let
|
||||
inherit (config.lab.networking) publicIPv4 dockerSwarmInternalIPv4 dmzServicesIPv4 dmzServicesIPv6 dmzRouterIPv4;
|
||||
in
|
||||
{
|
||||
no-resolv = true;
|
||||
local = "/dmz/";
|
||||
dhcp-fqdn = true;
|
||||
no-hosts = true;
|
||||
expand-hosts = true;
|
||||
domain = "dmz";
|
||||
dhcp-authoritative = true;
|
||||
ra-param = "*,0,0";
|
||||
alias = "${publicIPv4},${dockerSwarmInternalIPv4}";
|
||||
log-dhcp = true;
|
||||
log-queries = true;
|
||||
port = "5353";
|
||||
host-record = [
|
||||
"hermes.dmz,${dmzServicesIPv4},${dmzServicesIPv6}"
|
||||
"ipv4.hermes.dmz,${dmzServicesIPv4}"
|
||||
"ipv6.hermes.dmz,${dmzServicesIPv6}"
|
||||
];
|
||||
|
||||
server = [
|
||||
dmzRouterIPv4
|
||||
"/geokunis2.nl/${dmzServicesIPv4}"
|
||||
"/kun.is/${dmzServicesIPv4}"
|
||||
];
|
||||
|
||||
dhcp-range = [
|
||||
"192.168.30.50,192.168.30.127,15m"
|
||||
"2a0d:6e00:1a77:30::,ra-stateless,ra-names"
|
||||
];
|
||||
|
||||
dhcp-host = [
|
||||
"b8:27:eb:b9:ab:e2,esrom"
|
||||
"ca:fe:c0:ff:ee:08,maestro,${dockerSwarmInternalIPv4}"
|
||||
];
|
||||
|
||||
dhcp-option = [
|
||||
"3,${dmzRouterIPv4}"
|
||||
"option:dns-server,${dmzRouterIPv4}"
|
||||
"option6:dns-server,[2a02:58:19a:30::1]"
|
||||
];
|
||||
|
||||
address = [
|
||||
"/ns.pizzapim.nl/ns.geokunis2.nl/${dmzServicesIPv4}"
|
||||
"/ns.pizzapim.nl/ns.geokunis2.nl/${dmzServicesIPv6}"
|
||||
];
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
{ config, dns, ... }:
|
||||
with dns.lib.combinators;
|
||||
let
|
||||
inherit (config.lab.networking) publicIPv4 dmzServicesIPv6 dockerSwarmIPv6;
|
||||
in
|
||||
{
|
||||
SOA = {
|
||||
nameServer = "ns";
|
||||
adminEmail = "hostmaster@geokunis2.nl";
|
||||
serial = 2024011401;
|
||||
};
|
||||
|
||||
NS = [
|
||||
"ns.geokunis2.nl."
|
||||
"ns0.transip.net."
|
||||
"ns1.transip.nl."
|
||||
"ns2.transip.eu."
|
||||
];
|
||||
|
||||
MX = [ (mx.mx 10 "mail.geokunis2.nl.") ];
|
||||
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dockerSwarmIPv6 ];
|
||||
CAA = letsEncrypt "caa@geokunis2.nl";
|
||||
|
||||
subdomains = {
|
||||
"*" = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dockerSwarmIPv6 ];
|
||||
};
|
||||
|
||||
ns = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dmzServicesIPv6 ];
|
||||
};
|
||||
|
||||
ns1 = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dmzServicesIPv6 ];
|
||||
};
|
||||
|
||||
ns2 = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dmzServicesIPv6 ];
|
||||
};
|
||||
|
||||
# Override because we don't support IPv6 for KMS.
|
||||
kms = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ ];
|
||||
};
|
||||
|
||||
wg = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ "2a0d:6e00:1a77::1" ];
|
||||
};
|
||||
|
||||
wg4 = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ ];
|
||||
};
|
||||
|
||||
wg6 = {
|
||||
A = [ ];
|
||||
AAAA = [ "2a0d:6e00:1a77::1" ];
|
||||
};
|
||||
};
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
{ config, dns, ... }:
|
||||
with dns.lib.combinators;
|
||||
let
|
||||
inherit (config.lab.networking) publicIPv4 dmzServicesIPv6 dockerSwarmIPv6;
|
||||
in
|
||||
{
|
||||
CAA = letsEncrypt "caa@kun.is";
|
||||
|
||||
SOA = {
|
||||
nameServer = "ns1";
|
||||
adminEmail = "webmaster@kun.is";
|
||||
serial = 2024011401;
|
||||
};
|
||||
|
||||
NS = [
|
||||
"ns1.kun.is."
|
||||
"ns2.kun.is."
|
||||
];
|
||||
|
||||
MX = [
|
||||
(mx.mx 10 "mail.kun.is.")
|
||||
];
|
||||
|
||||
subdomains = {
|
||||
"*" = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dockerSwarmIPv6 ];
|
||||
};
|
||||
|
||||
ns = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dmzServicesIPv6 ];
|
||||
};
|
||||
|
||||
ns1 = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dmzServicesIPv6 ];
|
||||
};
|
||||
|
||||
ns2 = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ dmzServicesIPv6 ];
|
||||
};
|
||||
|
||||
# Override because we don't support IPv6 for Git SSH.
|
||||
git = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ ];
|
||||
};
|
||||
|
||||
# Override because we don't support IPv6 for KMS.
|
||||
kms = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ ];
|
||||
};
|
||||
|
||||
# Override because wg is on opnsense so ipv6 differs from "dmzServicesIPv6"
|
||||
wg = {
|
||||
A = [ publicIPv4 ];
|
||||
AAAA = [ "2a0d:6e00:1a77::1" ];
|
||||
};
|
||||
|
||||
};
|
||||
}
|
Reference in a new issue