tasks.py: switch to nix flake archive for deploy
This commit is contained in:
parent
d831662177
commit
44f0a96e96
2 changed files with 6 additions and 17 deletions
|
@ -6,7 +6,6 @@
|
||||||
jq
|
jq
|
||||||
python3.pkgs.deploykit
|
python3.pkgs.deploykit
|
||||||
python3.pkgs.invoke
|
python3.pkgs.invoke
|
||||||
rsync
|
|
||||||
sops
|
sops
|
||||||
ssh-to-age
|
ssh-to-age
|
||||||
];
|
];
|
||||||
|
|
22
tasks.py
22
tasks.py
|
@ -19,33 +19,23 @@ os.chdir(ROOT)
|
||||||
def deploy_nixos(hosts: List[DeployHost]) -> None:
|
def deploy_nixos(hosts: List[DeployHost]) -> None:
|
||||||
g = DeployGroup(hosts)
|
g = DeployGroup(hosts)
|
||||||
|
|
||||||
res = subprocess.run(
|
|
||||||
["nix", "flake", "metadata", "--json"],
|
|
||||||
check=True,
|
|
||||||
text=True,
|
|
||||||
stdout=subprocess.PIPE,
|
|
||||||
)
|
|
||||||
data = json.loads(res.stdout)
|
|
||||||
path = data["path"]
|
|
||||||
|
|
||||||
def deploy(h: DeployHost) -> None:
|
def deploy(h: DeployHost) -> None:
|
||||||
if "darwin" in h.host:
|
if "darwin" in h.host:
|
||||||
# don't use sudo for darwin-rebuild
|
# don't use sudo for darwin-rebuild
|
||||||
command = "darwin-rebuild"
|
command = "darwin-rebuild"
|
||||||
target = f"hetzner@{h.host}"
|
|
||||||
flakedir = "/etc/nix-darwin"
|
|
||||||
else:
|
else:
|
||||||
command = "sudo nixos-rebuild"
|
command = "sudo nixos-rebuild"
|
||||||
target = f"{h.host}"
|
|
||||||
flakedir = "/etc/nixos"
|
|
||||||
|
|
||||||
h.run_local(
|
res = h.run_local(
|
||||||
f"rsync --rsync-path='sudo rsync' --checksum -vaF --delete -e ssh {path}/ {target}:{flakedir}"
|
["nix", "flake", "archive", "--to", f"ssh://{h.host}", "--json"],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
)
|
)
|
||||||
|
data = json.loads(res.stdout)
|
||||||
|
path = data["path"]
|
||||||
|
|
||||||
hostname = h.host.replace(".nix-community.org", "")
|
hostname = h.host.replace(".nix-community.org", "")
|
||||||
h.run(
|
h.run(
|
||||||
f"{command} switch --option accept-flake-config true --flake {flakedir}#{hostname}"
|
f"{command} switch --option accept-flake-config true --flake {path}#{hostname}"
|
||||||
)
|
)
|
||||||
|
|
||||||
g.run_function(deploy)
|
g.run_function(deploy)
|
||||||
|
|
Loading…
Add table
Reference in a new issue