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,28 +67,32 @@
}) })
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} = {
network.IPv6.peerlist = lib.mkOption {
type = lib.types.list; type = lib.types.list;
description = "List of all IPv6 Wireguard peers"; description = "List of all IPv6 Wireguard peers";
}; };
config.${prefix}.network.IPv4.peerlist = lib.mkOption { network.IPv4.peerlist = lib.mkOption {
type = lib.types.list; type = lib.types.list;
description = "List of all IPv4 Wireguard peers"; description = "List of all IPv4 Wireguard peers";
}; };
config.${prefix}.network.IPv6.wg_subnet = lib.mkOption { network.IPv6.wg_subnet = lib.mkOption {
type = string; type = string;
description = "The IPv6 range that the peers will use"; description = "The IPv6 range that the peers will use";
}; };
config.${prefix}.network.IPv4.wg_subnet = lib.mkOption { network.IPv4.wg_subnet = lib.mkOption {
type = string; type = string;
description = "The IPv4 range that the peers will use"; description = "The IPv4 range that the peers will use";
}; };
config.${prefix}.network.IPv6.hosts = lib.mkOption { network.hosts = lib.mkOption {
type = lib.types.set; type = lib.types.set;
description = "All hosts in this network that this config should be aware of"; description = "All hosts in this network that this config should be aware of";
}; };
config.${prefix}.network = { };
};
config = {
network = {
IPv4 = { IPv4 = {
wg_subnet = wg_subnets.v4; wg_subnet = wg_subnets.v4;
peerlist = buildPeerlist "v4" hosts; peerlist = buildPeerlist "v4" hosts;
@ -95,4 +103,5 @@ in {
}; };
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;
}; };
}; };