From 0a6221d6aa08c5f8e6c6dbababcf5a723979030d Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Wed, 26 Jun 2024 00:39:52 +0200 Subject: [PATCH] add some zerotier scripts --- flake.nix | 7 +++++++ machines/chungus/configuration.nix | 2 ++ machines/chungus/zerotier-controller.nix | 22 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 machines/chungus/zerotier-controller.nix diff --git a/flake.nix b/flake.nix index 6817daf..3644839 100644 --- a/flake.nix +++ b/flake.nix @@ -197,6 +197,13 @@ # and makes the controller accept them. # will automatic look into `/machines//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 diff --git a/machines/chungus/configuration.nix b/machines/chungus/configuration.nix index 7e13a7c..1b046bd 100644 --- a/machines/chungus/configuration.nix +++ b/machines/chungus/configuration.nix @@ -46,6 +46,8 @@ ./services-s3.nix ./services-vault.nix + ./zerotier-controller.nix + ]; components.gui.enable = false; diff --git a/machines/chungus/zerotier-controller.nix b/machines/chungus/zerotier-controller.nix new file mode 100644 index 0000000..460c055 --- /dev/null +++ b/machines/chungus/zerotier-controller.nix @@ -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 + '') + ]; +}