zerotier-static-peers: init module #1400
@ -19,6 +19,7 @@
|
|||||||
thelounge = ./thelounge;
|
thelounge = ./thelounge;
|
||||||
user-password = ./user-password;
|
user-password = ./user-password;
|
||||||
xfce = ./xfce;
|
xfce = ./xfce;
|
||||||
|
zerotier-static-peers = ./zerotier-static-peers;
|
||||||
zt-tcp-relay = ./zt-tcp-relay;
|
zt-tcp-relay = ./zt-tcp-relay;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
5
clanModules/zerotier-static-peers/README.md
Normal file
5
clanModules/zerotier-static-peers/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Statically configure the `zerotier` peers of a clan network.
|
||||||
|
---
|
||||||
|
Statically configure the `zerotier` peers of a clan network.
|
||||||
|
|
||||||
|
Requires a machine, that is the zerotier controller configured in the network.
|
71
clanModules/zerotier-static-peers/default.nix
Normal file
71
clanModules/zerotier-static-peers/default.nix
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
inputs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
clanDir = config.clanCore.clanDir;
|
||||||
|
machineDir = clanDir + "/machines/";
|
||||||
|
machinesFileSet = builtins.readDir machineDir;
|
||||||
|
machines = lib.mapAttrsToList (name: _: name) machinesFileSet;
|
||||||
|
|
||||||
|
zerotierNetworkIdPath = machines: machineDir + machines + "/facts/zerotier-network-id";
|
||||||
|
networkIdsUnchecked = builtins.map (
|
||||||
|
machine:
|
||||||
|
let
|
||||||
|
fullPath = zerotierNetworkIdPath machine;
|
||||||
|
in
|
||||||
|
if builtins.pathExists fullPath then builtins.readFile fullPath else null
|
||||||
|
) machines;
|
||||||
|
networkIds = lib.filter (machine: machine != null) networkIdsUnchecked;
|
||||||
|
networkId = builtins.elemAt networkIds 0;
|
||||||
|
in
|
||||||
|
#TODO:trace on multiple found network-ids
|
||||||
|
#TODO:trace on no single found networkId
|
||||||
|
{
|
||||||
|
options.clan.zerotier-static-peers = {
|
||||||
|
excludeHosts = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ config.clanCore.machineName ];
|
||||||
|
description = "Hosts that should be excluded";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config.systemd.services.zerotier-static-peers-autoaccept =
|
||||||
|
let
|
||||||
|
machines = builtins.readDir machineDir;
|
||||||
|
zerotierIpMachinePath = machines: machineDir + machines + "/facts/zerotier-ip";
|
||||||
|
filteredMachines = lib.filterAttrs (
|
||||||
|
name: _: !(lib.elem name config.clan.static-hosts.excludeHosts)
|
||||||
|
) machines;
|
||||||
|
hosts = lib.mapAttrsToList (host: _: host) (
|
||||||
|
lib.mapAttrs' (
|
||||||
|
machine: _:
|
||||||
|
let
|
||||||
|
fullPath = zerotierIpMachinePath machine;
|
||||||
|
in
|
||||||
|
if builtins.pathExists fullPath then
|
||||||
|
lib.nameValuePair (builtins.readFile fullPath) [ machine ]
|
||||||
|
else
|
||||||
|
null
|
||||||
|
) filteredMachines
|
||||||
|
);
|
||||||
|
in
|
||||||
|
lib.mkIf (config.clan.networking.zerotier.controller.enable) {
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "zerotierone.service" ];
|
||||||
|
path = [ pkgs.zerotierone ];
|
||||||
|
serviceConfig.ExecStart = pkgs.writeScript "static-zerotier-peers-autoaccept" ''
|
||||||
|
#!/bin/sh
|
||||||
|
${lib.concatMapStringsSep "\n" (host: ''
|
||||||
|
${
|
||||||
|
inputs.clan-core.packages.${pkgs.system}.zerotier-members
|
||||||
|
}/bin/zerotier-members allow --member-ip ${host}
|
||||||
|
'') hosts}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
config.clan.networking.zerotier.networkId = lib.mkDefault networkId;
|
||||||
|
}
|
@ -66,6 +66,7 @@ nav:
|
|||||||
- reference/clanModules/thelounge.md
|
- reference/clanModules/thelounge.md
|
||||||
- reference/clanModules/user-password.md
|
- reference/clanModules/user-password.md
|
||||||
- reference/clanModules/xfce.md
|
- reference/clanModules/xfce.md
|
||||||
|
- reference/clanModules/zerotier-static-peers.md
|
||||||
- reference/clanModules/zt-tcp-relay.md
|
- reference/clanModules/zt-tcp-relay.md
|
||||||
- CLI:
|
- CLI:
|
||||||
- reference/cli/index.md
|
- reference/cli/index.md
|
||||||
|
Loading…
Reference in New Issue
Block a user