{ config, lib, pkgs, ... }: with lib; let cfg = config.services.yggdrasilTinc; in { options = { services.yggdrasilTinc = { enable = mkEnableOption "yggdrasil tinc network"; connect = mkOption { default = true; type = types.bool; description = '' Connect to central server ''; }; useDNS = mkOption { default = true; type = types.bool; description = '' Use heimdallr as primary dns server ''; }; name = mkOption { default = config.networking.hostName; type = types.str; description = '' Node identifier ''; }; interfaceConfig = mkOption { default = {}; description = '' Additional configuration for the generated network interface ''; }; }; }; config = mkIf cfg.enable { networking.extraResolvconfConf = '' interface_order=lo lo[0-9]* yggdrasil ''; services.customTinc.networks."yggdrasil" = { inherit (cfg) name interfaceConfig; debugLevel = 2; hosts = import ../../yggdrasil/hosts.nix; interfaceType = "tap"; extraConfig = '' Mode = switch PingTimeout = 30 ${optionalString cfg.connect "ConnectTo = ymir"} ''; scripts = { "tinc-up" = '' #!${pkgs.stdenv.shell} set -e MACFILE="/var/db/$NETNAME.mac" [ -e $MACFILE ] && ${pkgs.iproute}/bin/ip link set dev $INTERFACE address `cat $MACFILE` || cat /sys/class/net/$INTERFACE/address >$MACFILE ''; }; }; }; }