huh would this work?
This commit is contained in:
parent
90bbd821b0
commit
9347348d39
2 changed files with 47 additions and 35 deletions
|
@ -1,5 +1,9 @@
|
|||
{lib, ...}: let
|
||||
prefix = "lyn";
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
prefix = "meshconfig";
|
||||
|
||||
#define wireguard subnets
|
||||
wg_subnets = {
|
||||
|
@ -63,28 +67,32 @@
|
|||
})
|
||||
filteredHosts;
|
||||
in {
|
||||
#create first options because apparently you have to do that in Nix
|
||||
config.${prefix}.network.IPv6.peerlist = lib.mkOption {
|
||||
options = {
|
||||
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 {
|
||||
network.IPv4.peerlist = lib.mkOption {
|
||||
type = lib.types.list;
|
||||
description = "List of all IPv4 Wireguard peers";
|
||||
};
|
||||
config.${prefix}.network.IPv6.wg_subnet = lib.mkOption {
|
||||
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 {
|
||||
network.IPv4.wg_subnet = lib.mkOption {
|
||||
type = string;
|
||||
description = "The IPv4 range that the peers will use";
|
||||
};
|
||||
config.${prefix}.network.IPv6.hosts = lib.mkOption {
|
||||
network.hosts = lib.mkOption {
|
||||
type = lib.types.set;
|
||||
description = "All hosts in this network that this config should be aware of";
|
||||
};
|
||||
config.${prefix}.network = {
|
||||
};
|
||||
};
|
||||
config = {
|
||||
network = {
|
||||
IPv4 = {
|
||||
wg_subnet = wg_subnets.v4;
|
||||
peerlist = buildPeerlist "v4" hosts;
|
||||
|
@ -95,4 +103,5 @@ in {
|
|||
};
|
||||
inherit hosts;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue