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 #define wireguard subnets
wg_subnets = { wg_subnets = {
@ -63,36 +67,41 @@
}) })
filteredHosts; filteredHosts;
in { in {
#create first options because apparently you have to do that in Nix options = {
config.${prefix}.network.IPv6.peerlist = lib.mkOption { config.${prefix} = {
type = lib.types.list; network.IPv6.peerlist = lib.mkOption {
description = "List of all IPv6 Wireguard peers"; type = lib.types.list;
}; description = "List of all IPv6 Wireguard peers";
config.${prefix}.network.IPv4.peerlist = lib.mkOption { };
type = lib.types.list; network.IPv4.peerlist = lib.mkOption {
description = "List of all IPv4 Wireguard peers"; type = lib.types.list;
}; description = "List of all IPv4 Wireguard peers";
config.${prefix}.network.IPv6.wg_subnet = lib.mkOption { };
type = string; network.IPv6.wg_subnet = lib.mkOption {
description = "The IPv6 range that the peers will use"; type = string;
}; description = "The IPv6 range that the peers will use";
config.${prefix}.network.IPv4.wg_subnet = lib.mkOption { };
type = string; network.IPv4.wg_subnet = lib.mkOption {
description = "The IPv4 range that the peers will use"; type = string;
}; description = "The IPv4 range that the peers will use";
config.${prefix}.network.IPv6.hosts = lib.mkOption { };
type = lib.types.set; network.hosts = lib.mkOption {
description = "All hosts in this network that this config should be aware of"; 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;
}; };
IPv6 = { };
wg_subnet = wg_subnets.v6; config = {
peerlist = buildPeerlist "v6" hosts; 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, cfg,
... ...
}: let }: let
prefix = "meshconfig";
# helper vars to prettify # helper vars to prettify
currentHost = lyn.network.hosts.${networking.hostName}; meshnetwork = config.${prefix}.network;
currentHost = meshnetwork.hosts.${networking.hostName};
wireguardPort = currentHost.wg.port; wireguardPort = currentHost.wg.port;
in { in {
opt.useIPv6 = lib.mkOption { opt.useIPv6 = lib.mkOption {
@ -16,7 +19,7 @@ in {
}; };
networking.wireguard.interfaces.wg0 = { networking.wireguard.interfaces.wg0 = {
ips = ["${lyn.network.IPv4.wg_subnet}"]; ips = ["${meshnetwork.IPv4.wg_subnet}"];
listenPort = cfg.wireguardPort; listenPort = cfg.wireguardPort;
privateKeyFile = "/var/lib/wireguard-keys/private"; privateKeyFile = "/var/lib/wireguard-keys/private";
mtu = 1420; mtu = 1420;
@ -27,8 +30,8 @@ in {
interface = "wg0"; interface = "wg0";
peers = peers =
if cfg.useIPv6 if cfg.useIPv6
then lyn.network.IPv6.peerlist then meshnetwork.IPv6.peerlist
else lyn.network.IPv4.peerlist; else meshnetwork.IPv4.peerlist;
upnp_forward_external_port = wireguardPort; upnp_forward_external_port = wireguardPort;
}; };
}; };