Created
March 7, 2025 02:58
-
-
Save adisbladis/91a3b033b0f21c517d59df10c94e2097 to your computer and use it in GitHub Desktop.
Stupidly recursively walk narinfo's
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib3 | |
import sys | |
CACHE = "https://cache.nixos.org" | |
visited: set[str] = set() | |
def get_narinfo(hash) -> dict[str, str | list[str]]: | |
resp = urllib3.request("GET", f"{CACHE}/{hash}.narinfo") | |
if resp.status != 200: | |
raise ValueError(f"Status: {resp.status}") | |
ret = { } | |
for line in resp.data.decode().split("\n"): | |
if not line: | |
continue | |
name, data = line.split(": ") | |
if name == "References": | |
data = data.split() | |
ret[name] = data | |
return ret | |
def recurse(hash: str): | |
if hash in visited: | |
return | |
visited.add(hash) | |
narinfo = get_narinfo(hash) | |
print(narinfo["StorePath"].split("/")[-1]) | |
for reference in narinfo.get("References", []): | |
hash, _ = reference.split("-", 1) | |
recurse(hash) | |
def main() -> None: | |
store_path = sys.argv[1] | |
hash, _ = store_path.split("/")[-1].split("-", 1) | |
recurse(hash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment