clanServices: change tor service to have "client" and "server" roles instead of just "default"

also improve error message when user forgot to update machine in clan
networking command
This commit is contained in:
Qubasa
2025-07-21 13:34:45 +07:00
parent 1f5ef04a61
commit ff65dfc883
2 changed files with 38 additions and 24 deletions

View File

@@ -8,7 +8,29 @@
"Network" "Network"
]; ];
roles.default = { roles.client = {
perInstance =
{
...
}:
{
nixosModule =
{
...
}:
{
config = {
services.tor = {
enable = true;
torsocks.enable = true;
client.enable = true;
};
};
};
};
};
roles.server = {
# interface = # interface =
# { lib, ... }: # { lib, ... }:
# { # {
@@ -42,7 +64,7 @@
generator = "tor_${instanceName}"; generator = "tor_${instanceName}";
file = "hostname"; file = "hostname";
}; };
}) roles.default.machines; }) roles.server.machines;
}; };
nixosModule = nixosModule =
{ {
@@ -54,8 +76,6 @@
config = { config = {
services.tor = { services.tor = {
enable = true; enable = true;
torsocks.enable = true;
client.enable = true;
relay.onionServices."clan_${instanceName}" = { relay.onionServices."clan_${instanceName}" = {
version = 3; version = 3;
# TODO get ports from instance machine config # TODO get ports from instance machine config

View File

@@ -1,11 +1,11 @@
import logging import logging
import textwrap
import time import time
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from dataclasses import dataclass from dataclasses import dataclass
from functools import cached_property from functools import cached_property
from typing import Any from typing import Any
from clan_cli.vars.generate import run_generators
from clan_cli.vars.get import get_machine_var from clan_cli.vars.get import get_machine_var
from clan_lib.errors import ClanError from clan_lib.errors import ClanError
from clan_lib.flake import Flake from clan_lib.flake import Flake
@@ -35,15 +35,16 @@ class Peer:
f"{generator}/{_var['file']}", f"{generator}/{_var['file']}",
) )
if not var.exists: if not var.exists:
for _ in range(3): msg = (
res = run_generators( textwrap.dedent(f"""
machine_name=machine_name, It looks like you added a networking module to your machine, but forgot
generators=[generator], to deploy your changes. Please run "clan machines update {machine_name}"
all_prompt_values={}, so that the appropriate vars are generated and deployed properly.
base_dir=self.flake.path, """)
) .rstrip("\n")
if res: .lstrip("\n")
break )
raise ClanError(msg)
return var.value.decode() return var.value.decode()
msg = f"Unknown Var Type {self._host}" msg = f"Unknown Var Type {self._host}"
raise ClanError(msg) raise ClanError(msg)
@@ -77,14 +78,6 @@ class NetworkTechnologyBase(ABC):
return None return None
return None return None
def __str__(self) -> str:
"""Return a VSCode-clickable string representation."""
return f"{self.source.file_path}:{self.source.line_number}"
def __repr__(self) -> str:
"""Return a detailed representation with VSCode-clickable path."""
return f"<{self.__class__.__name__} at {self.source.file_path}:{self.source.line_number}>"
@dataclass(frozen=True) @dataclass(frozen=True)
class Network: class Network:
@@ -145,8 +138,9 @@ def get_network_overview(networks: dict[str, Network]) -> dict:
result[network_name]["status"] = None result[network_name]["status"] = None
result[network_name]["peers"] = {} result[network_name]["peers"] = {}
network_online = False network_online = False
log.debug(f"Using network module: {network.module}") module = network.module
if network.module.is_running(): log.debug(f"Using network module: {module}")
if module.is_running():
result[network_name]["status"] = True result[network_name]["status"] = True
network_online = True network_online = True
for peer_name in network.peers: for peer_name in network.peers: