From 4e16961bb215caacd825684f4315f2bf7b8bfa0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
Date: Sat, 15 Jan 2022 13:38:30 +0100
Subject: [PATCH] tasks: reformat with black

---
 tasks.py | 60 ++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 43 insertions(+), 17 deletions(-)

diff --git a/tasks.py b/tasks.py
index e36a01d..914b3a0 100644
--- a/tasks.py
+++ b/tasks.py
@@ -14,14 +14,20 @@ def deploy_nixos(hosts: List[DeployHost]) -> None:
     Deploy to all hosts in parallel
     """
     g = DeployGroup(hosts)
+
     def deploy(h: DeployHost) -> None:
         h.run_local(
             f"rsync --exclude='.git/' -vaF --delete -e ssh . {h.user}@{h.host}:/etc/nixos",
         )
 
-        config = f"/etc/nixos/{h.host.replace('.nix-community.org', '')}/configuration.nix"
+        config = (
+            f"/etc/nixos/{h.host.replace('.nix-community.org', '')}/configuration.nix"
+        )
         # FIXME: build03 has itself as a builder and deadlocks building packages.
-        h.run(f"nixos-rebuild switch --builders '' -I nixos-config={config} -I nixpkgs=$(nix-instantiate --eval -E '(import /etc/nixos/nix {{}}).path')")
+        h.run(
+            f"nixos-rebuild switch --builders '' -I nixos-config={config} -I nixpkgs=$(nix-instantiate --eval -E '(import /etc/nixos/nix {{}}).path')"
+        )
+
     g.run_function(deploy)
 
 
@@ -32,13 +38,17 @@ def sfdisk_json(host: DeployHost, dev: str) -> List[Any]:
 
 
 def _format_disks(host: DeployHost, devices: List[str]) -> None:
-    assert len(devices) == 1 or len(devices) == 2, "we only support single devices or mirror raids at the moment"
+    assert (
+        len(devices) == 1 or len(devices) == 2
+    ), "we only support single devices or mirror raids at the moment"
     # format disk with as follow:
     # - partition 1 will be the boot partition, needed for legacy (BIOS) boot
     # - partition 2 is for boot partition
     # - partition 3 takes up the rest of the space and is for the system
     for device in devices:
-        host.run(f"sgdisk -Z -n 1:2048:4095 -n 2:4096:+2G -N 3 -t 1:ef02 -t 2:8304 -t 3:8304 {device}")
+        host.run(
+            f"sgdisk -Z -n 1:2048:4095 -n 2:4096:+2G -N 3 -t 1:ef02 -t 2:8304 -t 3:8304 {device}"
+        )
 
     # create mdadm raid for /boot with ext4
     if len(devices) == 2:
@@ -50,15 +60,21 @@ def _format_disks(host: DeployHost, devices: List[str]) -> None:
             boot_parts.append(partitions[1]["node"])
             root_parts.append(f"/dev/disk/by-partuuid/{partitions[2]['uuid'].lower()}")
 
-        host.run(f"mdadm --create --verbose /dev/md127 --raid-devices=2 --level=1 {' '.join(boot_parts)}")
-        host.run(f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 mirror {' '.join(root_parts)}")
+        host.run(
+            f"mdadm --create --verbose /dev/md127 --raid-devices=2 --level=1 {' '.join(boot_parts)}"
+        )
+        host.run(
+            f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 mirror {' '.join(root_parts)}"
+        )
         boot = "/dev/md127"
     else:
         partitions = sfdisk_json(host, devices[0])
         boot = partitions[1]["node"]
         uuid = partitions[2]["uuid"].lower()
         root_part = f"/dev/disk/by-partuuid/{uuid}"
-        host.run(f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 -O atime=off {root_part}")
+        host.run(
+            f"zpool create zroot -O acltype=posixacl -O xattr=sa -O compression=lz4 -O atime=off {root_part}"
+        )
 
     host.run(f"partprobe")
     host.run(f"mkfs.ext4 -F {boot}")
@@ -76,7 +92,7 @@ def _format_disks(host: DeployHost, devices: List[str]) -> None:
 
 
 @task
-def format_disks(c, hosts = "", disks = ""):
+def format_disks(c, hosts="", disks=""):
     """
     Format disks with zfs, i.e.: inv format-disks --hosts build02 --disks /dev/nvme0n1,/dev/nvme1n1
     """
@@ -85,26 +101,36 @@ def format_disks(c, hosts = "", disks = ""):
 
 
 @task
-def setup_secret(c, hosts = ""):
+def setup_secret(c, hosts=""):
     """
     Setup SSH key and print age key for sops-nix
     """
     for h in get_hosts(hosts):
-        h.run("install -m600 -D /etc/ssh/ssh_host_rsa_key /mnt/etc/ssh/ssh_host_rsa_key")
-        h.run("install -m600 -D /etc/ssh/ssh_host_ed25519_key /mnt/etc/ssh/ssh_host_ed25519_key")
+        h.run(
+            "install -m600 -D /etc/ssh/ssh_host_rsa_key /mnt/etc/ssh/ssh_host_rsa_key"
+        )
+        h.run(
+            "install -m600 -D /etc/ssh/ssh_host_ed25519_key /mnt/etc/ssh/ssh_host_ed25519_key"
+        )
         print(h.host)
-        h.run("nix-shell -p ssh-to-age --run 'cat /etc/ssh/ssh_host_ed25519_key.pub | ssh-to-age'")
+        h.run(
+            "nix-shell -p ssh-to-age --run 'cat /etc/ssh/ssh_host_ed25519_key.pub | ssh-to-age'"
+        )
 
 
 @task
-def nixos_install(c, hosts = ""):
+def nixos_install(c, hosts=""):
     """
     Run NixOS install
     """
     for h in get_hosts(hosts):
-        h.run("nix-shell -p git --run 'git clone https://github.com/nix-community/infra && cd infra && nix-shell'")
-        hostname = h.host.replace('.nix-community.org', '')
-        h.run(f"cd /root/infra && nixos-install --system $(nix-build -A {hostname}-system)")
+        h.run(
+            "nix-shell -p git --run 'git clone https://github.com/nix-community/infra && cd infra && nix-shell'"
+        )
+        hostname = h.host.replace(".nix-community.org", "")
+        h.run(
+            f"cd /root/infra && nixos-install --system $(nix-build -A {hostname}-system)"
+        )
 
 
 def get_hosts(hosts: str) -> List[DeployHost]:
@@ -115,7 +141,7 @@ def get_hosts(hosts: str) -> List[DeployHost]:
 
 
 @task
-def deploy(c, hosts = ""):
+def deploy(c, hosts=""):
     """
     Deploy to all servers. Use inv deploy --host build01 to deploy to a single server
     """