move resolved configuration to a dummy interface
This commit is contained in:
@@ -1,12 +1,19 @@
|
|||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
localAddress = "fd66:29e9:f422:8dfe:beba:68ec:bd09:7876";
|
cfg = config.clan.networking.meshnamed;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.clan.networking.meshnamed = {
|
options.clan.networking.meshnamed = {
|
||||||
enable = (lib.mkEnableOption "meshnamed") // {
|
enable = (lib.mkEnableOption "meshnamed") // {
|
||||||
default = config.clan.networking.meshnamed.networks != { };
|
default = config.clan.networking.meshnamed.networks != { };
|
||||||
};
|
};
|
||||||
|
listenAddress = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "fd66:29e9:f422:8dfe:beba:68ec:bd09:7876";
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
The address to listen on.
|
||||||
|
'';
|
||||||
|
};
|
||||||
networks = lib.mkOption {
|
networks = lib.mkOption {
|
||||||
default = { };
|
default = { };
|
||||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
|
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
|
||||||
@@ -32,21 +39,24 @@ in
|
|||||||
};
|
};
|
||||||
config = lib.mkIf config.clan.networking.meshnamed.enable {
|
config = lib.mkIf config.clan.networking.meshnamed.enable {
|
||||||
# we assign this random source address to bind meshnamed to.
|
# we assign this random source address to bind meshnamed to.
|
||||||
systemd.network.networks.loopback-addresses = {
|
systemd.network.netdevs."08-meshnamed" = {
|
||||||
matchConfig.Name = "lo";
|
netdevConfig = {
|
||||||
networkConfig.Address = [ localAddress ];
|
Name = "meshnamed";
|
||||||
|
Kind = "dummy";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
systemd.network.networks."08-meshnamed" = {
|
||||||
|
matchConfig.Name = "meshnamed";
|
||||||
|
networkConfig = {
|
||||||
|
Address = [ "${cfg.listenAddress}/128" ];
|
||||||
|
DNS = [ config.clan.networking.meshnamed.listenAddress ];
|
||||||
|
Domains = [ "~${lib.concatMapStringsSep "," (network: network.name) (builtins.attrValues config.clan.networking.meshnamed.networks)}" ];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
services.resolved.extraConfig = ''
|
|
||||||
[Resolve]
|
|
||||||
DNS=${localAddress}
|
|
||||||
Domains=~${lib.concatMapStringsSep " " (network: network.name) (builtins.attrValues config.clan.networking.meshnamed.networks)}
|
|
||||||
'';
|
|
||||||
|
|
||||||
# for convience, so we can debug with dig
|
# for convience, so we can debug with dig
|
||||||
networking.extraHosts = ''
|
networking.extraHosts = ''
|
||||||
${localAddress} meshnamed
|
${cfg.listenAddress} meshnamed
|
||||||
'';
|
'';
|
||||||
|
|
||||||
systemd.services.meshnamed =
|
systemd.services.meshnamed =
|
||||||
@@ -55,11 +65,12 @@ in
|
|||||||
(builtins.attrValues config.clan.networking.meshnamed.networks);
|
(builtins.attrValues config.clan.networking.meshnamed.networks);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
after = [ "network.target" "sys-devices-virtual-net-meshnamed.device" ];
|
||||||
|
bindsTo = [ "sys-devices-virtual-net-meshnamed.device" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "simple";
|
Type = "simple";
|
||||||
ExecStart = "${pkgs.callPackage ../../../pkgs/meshname/default.nix { }}/bin/meshnamed -networks ${networks} -listenaddr [${localAddress}]:53";
|
ExecStart = "${pkgs.callPackage ../../../pkgs/meshname/default.nix { }}/bin/meshnamed -networks ${networks} -listenaddr [${cfg.listenAddress}]:53";
|
||||||
|
|
||||||
# to bind port 53
|
# to bind port 53
|
||||||
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
||||||
|
|||||||
@@ -27,6 +27,18 @@
|
|||||||
systemd.services.NetworkManager-wait-online.enable = false;
|
systemd.services.NetworkManager-wait-online.enable = false;
|
||||||
systemd.network.wait-online.enable = false;
|
systemd.network.wait-online.enable = false;
|
||||||
|
|
||||||
|
# Provide a default network configuration but don't compete with network-manager or dhcpcd
|
||||||
|
systemd.network.networks."50-uplink" = lib.mkIf (!(config.networking.networkmanager.enable || config.networking.dhcpcd.enable)) {
|
||||||
|
matchConfig.Type = "ether";
|
||||||
|
networkConfig = {
|
||||||
|
DHCP = "yes";
|
||||||
|
LLDP = "yes";
|
||||||
|
LLMNR = "yes";
|
||||||
|
MulticastDNS = "yes";
|
||||||
|
IPv6AcceptRA = "yes";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# Use networkd instead of the pile of shell scripts
|
# Use networkd instead of the pile of shell scripts
|
||||||
networking.useNetworkd = lib.mkDefault true;
|
networking.useNetworkd = lib.mkDefault true;
|
||||||
networking.useDHCP = lib.mkDefault false;
|
networking.useDHCP = lib.mkDefault false;
|
||||||
|
|||||||
@@ -97,17 +97,14 @@ in
|
|||||||
(lib.mkIf (cfg.networkId != null) {
|
(lib.mkIf (cfg.networkId != null) {
|
||||||
clan.networking.meshnamed.networks.vpn.subnet = cfg.subnet;
|
clan.networking.meshnamed.networks.vpn.subnet = cfg.subnet;
|
||||||
|
|
||||||
systemd.network.enable = true;
|
systemd.network.networks."09-zerotier" = {
|
||||||
networking.useNetworkd = true;
|
|
||||||
systemd.network.networks.zerotier = {
|
|
||||||
matchConfig.Name = "zt*";
|
matchConfig.Name = "zt*";
|
||||||
networkConfig = {
|
networkConfig = {
|
||||||
LLMNR = true;
|
|
||||||
LLDP = true;
|
|
||||||
MulticastDNS = true;
|
MulticastDNS = true;
|
||||||
KeepConfiguration = "static";
|
Address = [ "${facts.zerotier-ip.value}/88" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.firewall.interfaces."zt+".allowedTCPPorts = [ 5353 ]; # mdns
|
networking.firewall.interfaces."zt+".allowedTCPPorts = [ 5353 ]; # mdns
|
||||||
networking.firewall.interfaces."zt+".allowedUDPPorts = [ 5353 ]; # mdns
|
networking.firewall.interfaces."zt+".allowedUDPPorts = [ 5353 ]; # mdns
|
||||||
networking.networkmanager.unmanaged = [ "interface-name:zt*" ];
|
networking.networkmanager.unmanaged = [ "interface-name:zt*" ];
|
||||||
|
|||||||
Reference in New Issue
Block a user