mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-03-23 21:18:27 +01:00
Compare commits
3 commits
7fcbc3dcad
...
3f5ea6e161
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f5ea6e161 | |||
| dcf23fabe6 | |||
| 2aba83de58 |
7 changed files with 101 additions and 13 deletions
|
|
@ -21,6 +21,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
|
recursive-nameserver.enable = true;
|
||||||
private-nameserver.enable = true;
|
private-nameserver.enable = true;
|
||||||
|
|
||||||
syncthing = {
|
syncthing = {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
|
recursive-nameserver.enable = true;
|
||||||
private-nameserver.enable = true;
|
private-nameserver.enable = true;
|
||||||
public-nameserver = {
|
public-nameserver = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
|
||||||
|
|
@ -63,8 +63,11 @@ in
|
||||||
default =
|
default =
|
||||||
allHosts
|
allHosts
|
||||||
|> lib.attrValues
|
|> lib.attrValues
|
||||||
|> lib.filter (host: host.config.custom.services.private-nameserver.enable)
|
|> lib.filter (host: host.config.custom.services.recursive-nameserver.enable)
|
||||||
|> lib.map (host: host.config.custom.networking.overlay.address);
|
|> lib.map (
|
||||||
|
host:
|
||||||
|
"${host.config.custom.networking.overlay.address}:${toString host.config.custom.services.recursive-nameserver.port}"
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
implementation = lib.mkOption {
|
implementation = lib.mkOption {
|
||||||
|
|
|
||||||
|
|
@ -58,18 +58,24 @@ let
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.custom.services.private-nameserver.enable = lib.mkEnableOption "";
|
options.custom.services.private-nameserver = {
|
||||||
|
enable = lib.mkEnableOption "";
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 5335;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
services = {
|
services = {
|
||||||
nsd = {
|
nsd = {
|
||||||
enable = true;
|
enable = true;
|
||||||
interfaces = [ netCfg.overlay.interface ];
|
interfaces = [ "${netCfg.overlay.address}@${toString cfg.port}" ];
|
||||||
zones.${netCfg.overlay.domain}.data = zoneData;
|
zones.${netCfg.overlay.domain}.data = zoneData;
|
||||||
};
|
};
|
||||||
|
|
||||||
nebula.networks.mesh.firewall.inbound = lib.singleton {
|
nebula.networks.mesh.firewall.inbound = lib.singleton {
|
||||||
port = 53;
|
inherit (cfg) port;
|
||||||
proto = "any";
|
proto = "any";
|
||||||
host = "any";
|
host = "any";
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,10 @@ in
|
||||||
{
|
{
|
||||||
options.custom.services.public-nameserver = {
|
options.custom.services.public-nameserver = {
|
||||||
enable = lib.mkEnableOption "";
|
enable = lib.mkEnableOption "";
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 53;
|
||||||
|
};
|
||||||
zones = lib.mkOption {
|
zones = lib.mkOption {
|
||||||
type = lib.types.nonEmptyListOf lib.types.nonEmptyStr;
|
type = lib.types.nonEmptyListOf lib.types.nonEmptyStr;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
|
|
@ -73,14 +77,9 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
networking.firewall = {
|
|
||||||
allowedTCPPorts = [ 53 ];
|
|
||||||
allowedUDPPorts = [ 53 ];
|
|
||||||
};
|
|
||||||
|
|
||||||
services.nsd = {
|
services.nsd = {
|
||||||
enable = true;
|
enable = true;
|
||||||
interfaces = [ netCfg.underlay.interface ];
|
interfaces = [ "${netCfg.underlay.address}@${toString cfg.port}" ];
|
||||||
zones =
|
zones =
|
||||||
cfg.zones
|
cfg.zones
|
||||||
|> lib.map (zone: {
|
|> lib.map (zone: {
|
||||||
|
|
@ -89,5 +88,10 @@ in
|
||||||
})
|
})
|
||||||
|> lib.listToAttrs;
|
|> lib.listToAttrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
networking.firewall = {
|
||||||
|
allowedTCPPorts = [ cfg.port ];
|
||||||
|
allowedUDPPorts = [ cfg.port ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
70
modules/nixos/services/nameservers/recursive.nix
Normal file
70
modules/nixos/services/nameservers/recursive.nix
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
allHosts,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfg = config.custom.services.recursive-nameserver;
|
||||||
|
netCfg = config.custom.networking;
|
||||||
|
|
||||||
|
privateNameservers =
|
||||||
|
allHosts
|
||||||
|
|> lib.attrValues
|
||||||
|
|> lib.filter (host: host.config.custom.services.private-nameserver.enable);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.custom.services.recursive-nameserver = {
|
||||||
|
enable = lib.mkEnableOption "";
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.port;
|
||||||
|
default = 53;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable (
|
||||||
|
lib.mkMerge [
|
||||||
|
{
|
||||||
|
services = {
|
||||||
|
unbound = {
|
||||||
|
enable = true;
|
||||||
|
settings.server = {
|
||||||
|
interface = [ "${netCfg.overlay.address}@${toString cfg.port}" ];
|
||||||
|
access-control = [ "${toString netCfg.overlay.networkCidr} allow" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nebula.networks.mesh.firewall.inbound = lib.singleton {
|
||||||
|
inherit (cfg) port;
|
||||||
|
proto = "any";
|
||||||
|
host = "any";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.unbound = {
|
||||||
|
requires = [ netCfg.overlay.systemdUnit ];
|
||||||
|
after = [ netCfg.overlay.systemdUnit ];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
(lib.mkIf (privateNameservers != [ ]) {
|
||||||
|
services.unbound.settings = {
|
||||||
|
server = {
|
||||||
|
local-zone = ''"${netCfg.overlay.domain}." nodefault'';
|
||||||
|
domain-insecure = netCfg.overlay.domain;
|
||||||
|
};
|
||||||
|
|
||||||
|
stub-zone = lib.singleton {
|
||||||
|
name = netCfg.overlay.domain;
|
||||||
|
stub-addr =
|
||||||
|
privateNameservers
|
||||||
|
|> lib.map (
|
||||||
|
host:
|
||||||
|
"${host.config.custom.networking.overlay.address}@${toString host.config.custom.services.private-nameserver.port}"
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
})
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -58,7 +58,10 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.private-nameserver.enable = true;
|
services = {
|
||||||
|
recursive-nameserver.enable = true;
|
||||||
|
private-nameserver.enable = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -133,7 +136,7 @@
|
||||||
client1.wait_for_unit("${client1NetCfg.overlay.systemdUnit}")
|
client1.wait_for_unit("${client1NetCfg.overlay.systemdUnit}")
|
||||||
client2.wait_for_unit("${client2NetCfg.overlay.systemdUnit}")
|
client2.wait_for_unit("${client2NetCfg.overlay.systemdUnit}")
|
||||||
|
|
||||||
lighthouse.wait_for_unit("nsd.service")
|
lighthouse.wait_for_unit("unbound.service")
|
||||||
lighthouse.wait_for_open_port(53, "${lighthouseNetCfg.overlay.address}")
|
lighthouse.wait_for_open_port(53, "${lighthouseNetCfg.overlay.address}")
|
||||||
|
|
||||||
server.wait_for_unit("sshd.service")
|
server.wait_for_unit("sshd.service")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue