huh would this work?

This commit is contained in:
Lyn 2024-11-13 05:15:14 +01:00
parent 90bbd821b0
commit 9347348d39
2 changed files with 47 additions and 35 deletions

View file

@ -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;
};
}

View file

@ -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;
};
};