Files
nix-stuff/scripts/archive/archive.py
Shelvacu 44231f7d4d stuff
2025-05-15 16:27:54 -07:00

58 lines
1.5 KiB
Python

# flake8: noqa
import json
import subprocess
from typing import Any
from dataclasses import dataclass
@dataclass
class ProcessResult:
stdout: str
returncode: int
def success(self) -> bool:
return self.returncode == 0
def run(*cmd:str) -> ProcessResult:
print(f"running {cmd!r}")
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=None,
stdin=subprocess.DEVNULL,
text=True
)
(stdout_data, _) = proc.communicate()
print(f"finished, exit code {proc.returncode}")
return ProcessResult(stdout=stdout_data, returncode=proc.returncode)
def must_succeed(*cmd:str) -> str:
res = run(*cmd)
assert res.success()
return res.stdout
def run_json(*cmd:str) -> Any:
stdout = must_succeed(*cmd)
return json.loads(stdout)
build_list = run_json("nix", "eval", ".#.", "--json", "--apply", "f: f.archival.archiveList")
for info in build_list:
name = info["name"]
if info["broken"]:
print(f"Skipping {name}, marked broken")
continue
command = ["nix", "build", "-j1", "--keep-going", "--no-link"]
if info["impure"]:
command.append("--impure")
print(f"Going to build {name}")
res = run(*command, f".#archival.drvs.{name}")
if not res.success():
continue
res = run("into-nix-cache", f".#archival.drvs.{name}")
if not res.success():
continue
res = run(*command, f".#archival.buildDepsDrvs.{name}")
if not res.success():
continue
run("into-nix-cache", f".#archival.buildDepsDrvs.{name}")