From 3dc01cc80304705af006b71b43eda4ef08438107 Mon Sep 17 00:00:00 2001 From: Chris Kruining Date: Tue, 16 Sep 2025 08:43:38 +0200 Subject: [PATCH] this should be able to read the generated values from the controller --- clanServices/k3s/agent.nix | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/clanServices/k3s/agent.nix b/clanServices/k3s/agent.nix index fe16499..e217e41 100644 --- a/clanServices/k3s/agent.nix +++ b/clanServices/k3s/agent.nix @@ -1,6 +1,16 @@ -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, roles, ... }: let + inherit (builtins) pathExists readFile; + controller = head (lib.attrNames roles.controller.machines or {}); + + # Read the controller's ip address + ipAddressPath = "${config.clan.core.settings.directory}/vars/per-machine/${controller}/k3s-ip/ip_v4"; + ipAddress = if pathExists ipAddressPath then readFile ipAddressPath else null; + + # Read the controller's token + tokenPath = "${config.clan.core.settings.directory}/vars/per-machine/${controller}/k3s-token/token"; + token = if pathExists ipAddressPath then readFile ipAddressPath else null; in { config = { @@ -20,8 +30,8 @@ in k3s = { enable = true; role = "agent"; - token = "somehow get the token that is generated for the controller"; # config.clan.core.vars.generators.k3s-token.token.value; - serverAddr = "https://"; + token = token; + serverAddr = "https://${ipAddress}:6443"; }; }; };