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"; }; }; };