Set up wireguard networks using functions.

This commit is contained in:
Tom Alexander 2024-12-31 08:55:04 -05:00
parent e22b5c1c6c
commit e8dff5ece1
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -5,30 +5,42 @@
... ...
}: }:
let
activatedWg = name: {
networking.wg-quick.interfaces."${name}".configFile = "/persist/manual/wireguard/${name}.conf";
systemd.services."wg-quick-${name}" = {
after = [
"nss-lookup.target"
"systemd-resolved.service"
"multi-user.target"
];
preStart = "${pkgs.toybox}/bin/sleep 10";
};
# systemd.services."wg-quick-${name}".after = [
# "nss-lookup.target"
# "systemd-resolved.service"
# "multi-user.target"
# ];
# systemd.services."wg-quick-${name}".preStart = "${pkgs.toybox}/bin/sleep 10";
};
deactivatedWg = name: {
networking.wg-quick.interfaces."${name}" = {
configFile = "/persist/manual/wireguard/${name}.conf";
autostart = false;
};
};
wgConfig = lib.attrsets.recursiveUpdate (lib.attrsets.recursiveUpdate (lib.attrsets.recursiveUpdate
(lib.attrsets.recursiveUpdate {
networking.firewall.allowedUDPPorts = [ 51821 ];
networking.wireguard.enable = true;
} (activatedWg "drmario"))
(activatedWg "wgh")
) (activatedWg "colo")) (deactivatedWg "wgf");
in
{ {
imports = [ ]; imports = [ ];
config = lib.mkIf (!config.me.buildingIso) { config = lib.mkIf (!config.me.buildingIso) wgConfig;
networking.firewall.allowedUDPPorts = [ 51821 ];
networking.wireguard.enable = true;
networking.wg-quick.interfaces.drmario.configFile = "/persist/manual/wireguard/drmario.conf";
systemd.services."wg-quick-drmario".after = [
"nss-lookup.target"
"systemd-resolved.service"
"multi-user.target"
];
systemd.services."wg-quick-drmario".preStart = "${pkgs.toybox}/bin/sleep 10";
networking.wg-quick.interfaces.wgh.configFile = "/persist/manual/wireguard/wgh.conf";
systemd.services."wg-quick-wgh".after = [
"nss-lookup.target"
"systemd-resolved.service"
"multi-user.target"
];
systemd.services."wg-quick-wgh".preStart = "${pkgs.toybox}/bin/sleep 10";
};
# environment.systemPackages = with pkgs; [ # environment.systemPackages = with pkgs; [
# wireguard-tools # wireguard-tools