nixGL: simplify, update, and use builtins only
parent
b7c3707213
commit
335efeb2d9
|
@ -1,59 +1,60 @@
|
|||
#!/usr/bin/env python3
|
||||
import urllib3
|
||||
import http.client
|
||||
import json
|
||||
|
||||
http = urllib3.PoolManager()
|
||||
dl_dir = http.request("GET", "https://download.nvidia.com/XFree86/Linux-x86_64/")
|
||||
NV_FREE_X86_URL = "download.nvidia.com"
|
||||
POTENTIAL_SHA256_EXTS = [".sha256sum", ".sha256"]
|
||||
conn = http.client.HTTPSConnection(NV_FREE_X86_URL)
|
||||
conn.request("GET", "/XFree86/Linux-x86_64/")
|
||||
response = conn.getresponse()
|
||||
dir_html = response.read()
|
||||
|
||||
assert (dl_dir.status < 400), "Error probably occurred"
|
||||
assert (response.status < 400), "Error occurred fetching for source from"
|
||||
|
||||
def find_versions(dir_html: bytes) -> list[str]:
|
||||
# this algorithm obviously need recursion because we need to discover the items
|
||||
def _rec(dir_html: bytes, start: int = 0, so_far: list[str] = []) -> list[str]:
|
||||
def scrape_driver_versions(dir_html: bytes) -> list[str]:
|
||||
# The idea is to recursively follows all interesting `src` from `<a href={src}>`
|
||||
def _rec(dir_html: bytes, href_url_start: int = 0, so_far: list[str] = []) -> list[str]:
|
||||
MATCH_START = b"<span class=\'dir\'><a href=\'"
|
||||
potential_start = dir_html.find(MATCH_START, start)
|
||||
if potential_start == -1:
|
||||
href_url_start = dir_html.find(MATCH_START, href_url_start)
|
||||
if href_url_start == -1: # EOF
|
||||
return so_far
|
||||
# check that it starts with a number
|
||||
potential_version_start = potential_start + len(MATCH_START)
|
||||
|
||||
# version href should start with a number
|
||||
potential_version_start = href_url_start + len(MATCH_START)
|
||||
p = potential_version_start
|
||||
if not (dir_html[p: p+1].decode().isnumeric()):
|
||||
return _rec(dir_html, potential_version_start, so_far)
|
||||
|
||||
# this thing matches, add to so_far and continue
|
||||
version_end = dir_html.find(b"/", potential_version_start)
|
||||
assert version_end != -1, "There should be matching /"
|
||||
assert version_end != -1, "Should have end-signaling /"
|
||||
so_far.append(dir_html[potential_version_start:version_end].decode())
|
||||
return _rec(dir_html, version_end, so_far)
|
||||
return _rec(dir_html, 0, [])
|
||||
|
||||
versions = find_versions(dl_dir.data)
|
||||
versions = scrape_driver_versions(dir_html)
|
||||
|
||||
download_urls = lambda ver: [f"https://download.nvidia.com/XFree86/Linux-x86_64/{ver}/NVIDIA-Linux-x86_64-{ver}.run"]
|
||||
sha256_urls = lambda ver: [f"{url}{dl_ext}" for dl_ext in [".sha256sum", ".sha256"] for url in download_urls(ver)]
|
||||
def req_monad(url: str, err_fn, then_fn):
|
||||
res = http.request("GET", url)
|
||||
if res.status >= 400:
|
||||
return err_fn(res.status)
|
||||
return then_fn(res.data)
|
||||
download_urls_of = lambda ver: [f"/XFree86/Linux-x86_64/{ver}/NVIDIA-Linux-x86_64-{ver}.run"]
|
||||
sha256_urls_of = lambda ver: [
|
||||
f"{url}{dl_ext}"
|
||||
for dl_ext in POTENTIAL_SHA256_EXTS
|
||||
for url in download_urls_of(ver)
|
||||
]
|
||||
|
||||
identity = lambda e: e
|
||||
none_id = lambda _: None
|
||||
|
||||
def get_sha256(version: str) -> str | None:
|
||||
for url in sha256_urls(version):
|
||||
res = http.request("GET", url)
|
||||
if res.status < 400:
|
||||
return res.data.decode().split()[0]
|
||||
def sha256_of(version: str) -> str | None:
|
||||
for url in sha256_urls_of(version):
|
||||
conn = http.client.HTTPSConnection(NV_FREE_X86_URL)
|
||||
conn.request("GET", url)
|
||||
response = conn.getresponse()
|
||||
if response.status < 400:
|
||||
return response.read().decode().split()[0]
|
||||
return None
|
||||
fetch_data = [(v, download_urls(v)[0], get_sha256(v)) for v in versions]
|
||||
fetch_data.append(("latest", *fetch_data[-1][1:]))
|
||||
|
||||
fetch_data = [(v, download_urls_of(v)[0], sha256_of(v)) for v in versions]
|
||||
fetch_data.append(("latest", *fetch_data[-1][1:]))
|
||||
|
||||
# now print the JSON object
|
||||
print(json.dumps({
|
||||
version: {
|
||||
"url": dl_url,
|
||||
"url": f"https://{NV_FREE_X86_URL}{dl_url}",
|
||||
"sha256": sha256
|
||||
} for (version, dl_url, sha256) in fetch_data if sha256 is not None}, indent=4))
|
||||
# execution: fetch.py >nvidia_versions.json
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
nixGLIntel = pkgs.nixGLIntel;
|
||||
nixVulkanNvidia = pkgs.auto.nixVulkanNvidia;
|
||||
nixVulkanIntel = pkgs.nixVulkanIntel;
|
||||
|
||||
nvida-fetch
|
||||
};
|
||||
|
||||
# deprecated attributes for retro compatibility
|
||||
|
|
|
@ -539,6 +539,10 @@
|
|||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/470.161.03/NVIDIA-Linux-x86_64-470.161.03.run",
|
||||
"sha256": "5da82a7f8c76e781e7d7f0be7b798db4d344f26bd4facf9abcf3c71c71fe7640"
|
||||
},
|
||||
"470.182.03": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/470.182.03/NVIDIA-Linux-x86_64-470.182.03.run",
|
||||
"sha256": "3dbc1408fc48b865d3ddacefc45f4a3fc13b90b83a628ee546b0082ab2c3fc79"
|
||||
},
|
||||
"510.108.03": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/510.108.03/NVIDIA-Linux-x86_64-510.108.03.run",
|
||||
"sha256": "410a515e78df29c2cba4ac0b497889ce0ff1b04cfc711ff889e2dfc80f0da0d8"
|
||||
|
@ -547,6 +551,10 @@
|
|||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/515.86.01/NVIDIA-Linux-x86_64-515.86.01.run",
|
||||
"sha256": "141777e1ca2f11e97d8d33260213f1be327eb73922ae22f4ddab404bb2ef4664"
|
||||
},
|
||||
"515.105.01": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/515.105.01/NVIDIA-Linux-x86_64-515.105.01.run",
|
||||
"sha256": "9dd2221f26c847c864dfe80cc8533f322c5f4dfaa2939cf54a934b8f7a2f6a0d"
|
||||
},
|
||||
"525.53": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.53/NVIDIA-Linux-x86_64-525.53.run",
|
||||
"sha256": "74bb0971f04f1dddd3c4641c891706fb96e8de52e22f6079e50de76d3a51687f"
|
||||
|
@ -563,8 +571,28 @@
|
|||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.78.01/NVIDIA-Linux-x86_64-525.78.01.run",
|
||||
"sha256": "43da42d2bf69bc37ea9c7c0fa02f52db0dcc483c272f52edacad89a5cb495a93"
|
||||
},
|
||||
"525.85.05": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.85.05/NVIDIA-Linux-x86_64-525.85.05.run",
|
||||
"sha256": "ea63b4253403b224bb7313a8977a920dfe9d203d661dd5f6fc26585a70179140"
|
||||
},
|
||||
"525.89.02": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.89.02/NVIDIA-Linux-x86_64-525.89.02.run",
|
||||
"sha256": "0e412c88c5bd98f842a839a6f64614f20e4c0950ef7cffb12b158a71633593e9"
|
||||
},
|
||||
"525.105.17": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.105.17/NVIDIA-Linux-x86_64-525.105.17.run",
|
||||
"sha256": "c635a21a282c9b53485f19ebb64a0f4b536a968b94d4d97629e0bc547a58142a"
|
||||
},
|
||||
"530.30.02": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/530.30.02/NVIDIA-Linux-x86_64-530.30.02.run",
|
||||
"sha256": "47fddbbd7a22ba661923dbce6e7f51eec54df68050c406cc0490c3bfbede7963"
|
||||
},
|
||||
"530.41.03": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/530.41.03/NVIDIA-Linux-x86_64-530.41.03.run",
|
||||
"sha256": "ae27a16a968c85503f5d161dda343c1602612b025f4aee15f92e2ea0acb784b1"
|
||||
},
|
||||
"latest": {
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/525.78.01/NVIDIA-Linux-x86_64-525.78.01.run",
|
||||
"sha256": "43da42d2bf69bc37ea9c7c0fa02f52db0dcc483c272f52edacad89a5cb495a93"
|
||||
"url": "https://download.nvidia.com/XFree86/Linux-x86_64/530.41.03/NVIDIA-Linux-x86_64-530.41.03.run",
|
||||
"sha256": "ae27a16a968c85503f5d161dda343c1602612b025f4aee15f92e2ea0acb784b1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue