From 9347348d39c85e7e47c48aaee964947558dbcbbd Mon Sep 17 00:00:00 2001 From: Lyn Date: Wed, 13 Nov 2024 05:15:14 +0100 Subject: [PATCH] huh would this work? --- hosts/network.nix | 71 +++++++++++++++++++-------------- modules/services/wgautomesh.nix | 11 +++-- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/hosts/network.nix b/hosts/network.nix index f8db806..9d3bc5c 100644 --- a/hosts/network.nix +++ b/hosts/network.nix @@ -1,5 +1,9 @@ -{lib, ...}: let - prefix = "lyn"; +{ + lib, + config, + ... +}: let + prefix = "meshconfig"; #define wireguard subnets wg_subnets = { @@ -63,36 +67,41 @@ }) filteredHosts; in { - #create first options because apparently you have to do that in Nix - config.${prefix}.network.IPv6.peerlist = lib.mkOption { - type = lib.types.list; - description = "List of all IPv6 Wireguard peers"; - }; - config.${prefix}.network.IPv4.peerlist = lib.mkOption { - type = lib.types.list; - description = "List of all IPv4 Wireguard peers"; - }; - config.${prefix}.network.IPv6.wg_subnet = lib.mkOption { - type = string; - description = "The IPv6 range that the peers will use"; - }; - config.${prefix}.network.IPv4.wg_subnet = lib.mkOption { - type = string; - description = "The IPv4 range that the peers will use"; - }; - config.${prefix}.network.IPv6.hosts = lib.mkOption { - type = lib.types.set; - description = "All hosts in this network that this config should be aware of"; - }; - config.${prefix}.network = { - IPv4 = { - wg_subnet = wg_subnets.v4; - peerlist = buildPeerlist "v4" hosts; + options = { + config.${prefix} = { + network.IPv6.peerlist = lib.mkOption { + type = lib.types.list; + description = "List of all IPv6 Wireguard peers"; + }; + network.IPv4.peerlist = lib.mkOption { + type = lib.types.list; + description = "List of all IPv4 Wireguard peers"; + }; + network.IPv6.wg_subnet = lib.mkOption { + type = string; + description = "The IPv6 range that the peers will use"; + }; + network.IPv4.wg_subnet = lib.mkOption { + type = string; + description = "The IPv4 range that the peers will use"; + }; + network.hosts = lib.mkOption { + type = lib.types.set; + description = "All hosts in this network that this config should be aware of"; + }; }; - IPv6 = { - wg_subnet = wg_subnets.v6; - peerlist = buildPeerlist "v6" hosts; + }; + config = { + network = { + IPv4 = { + wg_subnet = wg_subnets.v4; + peerlist = buildPeerlist "v4" hosts; + }; + IPv6 = { + wg_subnet = wg_subnets.v6; + peerlist = buildPeerlist "v6" hosts; + }; + inherit hosts; }; - inherit hosts; }; } diff --git a/modules/services/wgautomesh.nix b/modules/services/wgautomesh.nix index 2cd8ec9..cb29b76 100644 --- a/modules/services/wgautomesh.nix +++ b/modules/services/wgautomesh.nix @@ -5,8 +5,11 @@ cfg, ... }: let + prefix = "meshconfig"; + # helper vars to prettify - currentHost = lyn.network.hosts.${networking.hostName}; + meshnetwork = config.${prefix}.network; + currentHost = meshnetwork.hosts.${networking.hostName}; wireguardPort = currentHost.wg.port; in { opt.useIPv6 = lib.mkOption { @@ -16,7 +19,7 @@ in { }; networking.wireguard.interfaces.wg0 = { - ips = ["${lyn.network.IPv4.wg_subnet}"]; + ips = ["${meshnetwork.IPv4.wg_subnet}"]; listenPort = cfg.wireguardPort; privateKeyFile = "/var/lib/wireguard-keys/private"; mtu = 1420; @@ -27,8 +30,8 @@ in { interface = "wg0"; peers = if cfg.useIPv6 - then lyn.network.IPv6.peerlist - else lyn.network.IPv4.peerlist; + then meshnetwork.IPv6.peerlist + else meshnetwork.IPv4.peerlist; upnp_forward_external_port = wireguardPort; }; };