From 9e7ba7ded32551521563820bd28dabf9ec3fc5e7 Mon Sep 17 00:00:00 2001
From: zowoq <59103226+zowoq@users.noreply.github.com>
Date: Wed, 16 Oct 2024 21:59:06 +1000
Subject: [PATCH] tasks.py: simplify deploy, require host(s) input

---
 tasks.py | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/tasks.py b/tasks.py
index 22ac7a4..a909b4d 100644
--- a/tasks.py
+++ b/tasks.py
@@ -14,9 +14,12 @@ ROOT = Path(__file__).parent.resolve()
 os.chdir(ROOT)
 
 
-# Deploy to all hosts in parallel
-def deploy_nixos(hosts: List[DeployHost]) -> None:
-    g = DeployGroup(hosts)
+@task
+def deploy(c: Any, hosts: str) -> None:
+    """
+    Use inv deploy --hosts build01,darwin01
+    """
+    g = DeployGroup(get_hosts(hosts))
 
     def deploy(h: DeployHost) -> None:
         if "darwin" in h.host:
@@ -109,17 +112,6 @@ def docs_linkcheck(c: Any) -> None:
 
 
 def get_hosts(hosts: str) -> List[DeployHost]:
-    if hosts == "":
-        res = subprocess.run(
-            ["nix", "flake", "show", "--json", "--all-systems"],
-            check=True,
-            text=True,
-            stdout=subprocess.PIPE,
-        )
-        data = json.loads(res.stdout)
-        systems = data["nixosConfigurations"]
-        return [DeployHost(f"{n}.nix-community.org") for n in systems]
-
     if "darwin" in hosts:
         return [
             DeployHost(f"{h}.nix-community.org", user="customer")
@@ -129,14 +121,6 @@ def get_hosts(hosts: str) -> List[DeployHost]:
     return [DeployHost(f"{h}.nix-community.org") for h in hosts.split(",")]
 
 
-@task
-def deploy(c: Any, hosts: str = "") -> None:
-    """
-    Deploy to all servers. Use inv deploy --hosts build01 to deploy to a single server
-    """
-    deploy_nixos(get_hosts(hosts))
-
-
 def decrypt_host_key(flake_attr: str, tmpdir: str) -> None:
     def opener(path: str, flags: int) -> Union[str, int]:
         return os.open(path, flags, 0o400)
@@ -178,6 +162,6 @@ def install(c: Any, flake_attr: str, hostname: str) -> None:
 
 
 @task
-def cleanup_gcroots(c: Any, hosts: str = "") -> None:
+def cleanup_gcroots(c: Any, hosts: str) -> None:
     g = DeployGroup(get_hosts(hosts))
     g.run("sudo find /nix/var/nix/gcroots/auto -type s -delete")