fix formatting

This commit is contained in:
notgne2 2022-09-13 18:08:19 -07:00
parent 3417784008
commit cf401b300c
No known key found for this signature in database
GPG key ID: 5CE0A245A2DAC84A
7 changed files with 240 additions and 217 deletions

View file

@ -25,7 +25,8 @@ let
rangesOutput = pkgs.runCommandNoCC "exclusionary-wildcard-ranges" { } ''
${pkgs.python3}/bin/python3 ${generateRangesScript} > $out
'';
in lib.splitString ":" (builtins.readFile "${rangesOutput}");
in
lib.splitString ":" (builtins.readFile "${rangesOutput}");
subnet = vlanIP: vlanSize:
let
@ -38,7 +39,8 @@ let
subnetOutput = pkgs.runCommandNoCC "subnet-without-host-bits" { } ''
${pkgs.python3}/bin/python3 ${generateSubnetScript} > $out
'';
in builtins.readFile "${subnetOutput}";
in
builtins.readFile "${subnetOutput}";
serverOpts.options = {
ip = mkOption {
@ -86,7 +88,8 @@ let
description = "The IP to use on the wg VLAN";
};
};
in {
in
{
options.services.ezwg = {
enable = mkEnableOption "Enable simple Wireguard connection";
instances = mkOption {
@ -99,37 +102,49 @@ in {
config = mkIf cfg.enable {
networking.firewall.checkReversePath = false;
systemd.paths = mapAttrs' (instName: inst: {
name = "wireguard-${instName}";
value = if inst.autoStart then { } else { wantedBy = mkForce [ ]; };
}) cfg.instances;
systemd.services = lib.listToAttrs (flatten (mapAttrsToList (instName: inst:
[{
systemd.paths = mapAttrs'
(instName: inst: {
name = "wireguard-${instName}";
value = if inst.autoStart then { } else { wantedBy = mkForce [ ]; };
}] ++ map (server: {
name =
"wireguard-${instName}-peer${peerNameReplacement server.publicKey}";
value = if inst.autoStart then { } else { wantedBy = mkForce [ ]; };
}) inst.servers) cfg.instances));
})
cfg.instances;
networking.wireguard.interfaces = mapAttrs (instName: inst:
let
allowedIPs = if inst.proxy then
ranges (map (s: s.ip) inst.servers)
else
[ (subnet inst.vlanIP inst.vlanSize) ];
in {
ips = [ "${inst.vlanIP}/${toString inst.vlanSize}" ];
privateKeyFile = inst.privateKeyFile;
peers = map (server: {
inherit allowedIPs;
publicKey = server.publicKey;
endpoint = "${server.ip}:${toString server.port}";
persistentKeepalive = 25;
}) inst.servers;
}) cfg.instances;
systemd.services = lib.listToAttrs (flatten (mapAttrsToList
(instName: inst:
[{
name = "wireguard-${instName}";
value = if inst.autoStart then { } else { wantedBy = mkForce [ ]; };
}] ++ map
(server: {
name =
"wireguard-${instName}-peer${peerNameReplacement server.publicKey}";
value = if inst.autoStart then { } else { wantedBy = mkForce [ ]; };
})
inst.servers)
cfg.instances));
networking.wireguard.interfaces = mapAttrs
(instName: inst:
let
allowedIPs =
if inst.proxy then
ranges (map (s: s.ip) inst.servers)
else
[ (subnet inst.vlanIP inst.vlanSize) ];
in
{
ips = [ "${inst.vlanIP}/${toString inst.vlanSize}" ];
privateKeyFile = inst.privateKeyFile;
peers = map
(server: {
inherit allowedIPs;
publicKey = server.publicKey;
endpoint = "${server.ip}:${toString server.port}";
persistentKeepalive = 25;
})
inst.servers;
})
cfg.instances;
};
}