nixos-config/machines/chungus/zerotier-controller.nix

23 lines
725 B
Nix
Raw Normal View History

2024-06-26 00:39:52 +02:00
{ 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
'')
];
}