move resolved configuration to a dummy interface
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
let
|
||||
localAddress = "fd66:29e9:f422:8dfe:beba:68ec:bd09:7876";
|
||||
cfg = config.clan.networking.meshnamed;
|
||||
in
|
||||
{
|
||||
options.clan.networking.meshnamed = {
|
||||
enable = (lib.mkEnableOption "meshnamed") // {
|
||||
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 {
|
||||
default = { };
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
|
||||
@@ -32,21 +39,24 @@ in
|
||||
};
|
||||
config = lib.mkIf config.clan.networking.meshnamed.enable {
|
||||
# we assign this random source address to bind meshnamed to.
|
||||
systemd.network.networks.loopback-addresses = {
|
||||
matchConfig.Name = "lo";
|
||||
networkConfig.Address = [ localAddress ];
|
||||
systemd.network.netdevs."08-meshnamed" = {
|
||||
netdevConfig = {
|
||||
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
|
||||
networking.extraHosts = ''
|
||||
${localAddress} meshnamed
|
||||
${cfg.listenAddress} meshnamed
|
||||
'';
|
||||
|
||||
systemd.services.meshnamed =
|
||||
@@ -55,11 +65,12 @@ in
|
||||
(builtins.attrValues config.clan.networking.meshnamed.networks);
|
||||
in
|
||||
{
|
||||
after = [ "network.target" "sys-devices-virtual-net-meshnamed.device" ];
|
||||
bindsTo = [ "sys-devices-virtual-net-meshnamed.device" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
serviceConfig = {
|
||||
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
|
||||
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
||||
|
||||
Reference in New Issue
Block a user