add some zerotier scripts

This commit is contained in:
Ingolf Wagner 2024-06-26 00:39:52 +02:00
parent 4798da1f71
commit 0a6221d6aa
Signed by: palo
GPG key ID: 76BF5F1928B9618B
3 changed files with 31 additions and 0 deletions

View file

@ -197,6 +197,13 @@
# and makes the controller accept them.
# will automatic look into `/machines/<name>/facts/zerotier-ip
inputs.clan-core.clanModules.zerotier-static-peers
{
environment.systemPackages = [
(pkgs.writers.writeBashBin "zerotier-script-nodeid" ''
sudo ${pkgs.zerotierone}/bin/zerotier-cli info | cut -d " " -f 3
'')
];
}
# Statically configure the host names of machines based on their respective zerotier-ip.
inputs.clan-core.clanModules.static-hosts

View file

@ -46,6 +46,8 @@
./services-s3.nix
./services-vault.nix
./zerotier-controller.nix
];
components.gui.enable = false;

View file

@ -0,0 +1,22 @@
{ pkgs, lib, config, clanLib, ... }:
let
zerotierSetup = ''
export NWID=${config.clan.core.facts.services.zerotier.public."zerotier-network-id".value}
export TOKEN=$(cat /var/lib/zerotier-one/authtoken.secret)
'';
zerotierCommand = name: command: pkgs.writers.writeBashBin name ''
export PATH=${pkgs.curl}/bin:${pkgs.gojq}/bin:${pkgs.zerotierone}/bin:$PATH
${zerotierSetup}
${command}
'';
in
{
environment.systemPackages = [
(zerotierCommand "zerotier-script-members" ''
curl "http://localhost:9993/controller/network/''${NWID}/member" -H "X-ZT1-AUTH: ''${TOKEN}" | gojq
'')
(zerotierCommand "zerotier-script-nodeid" ''
zerotier-cli info | cut -d " " -f 3
'')
];
}