about summary refs log tree commit diff
path: root/pkgs/os-specific/linux/kernel/update-mainline.py
diff options
context:
space:
mode:
authorK900 <me@0upti.me>2023-09-22 14:28:05 +0300
committerK900 <me@0upti.me>2023-09-22 16:09:59 +0300
commitc08efe1438362d2cdcb64849bd7e28dd688b55f6 (patch)
treee516fd3ec944e11015b87eab683993e9c9cb7d47 /pkgs/os-specific/linux/kernel/update-mainline.py
parentc792f6b81a1ea61370b87daabb7ff1ad5660efb3 (diff)
linux: more update-script cleanups/fixes
- special case linux-testing fetching
- use hash instead of sha256 everywhere
- respect COMMIT envvar

This causes rebuilds, so should go in with the next bump probably.
Diffstat (limited to 'pkgs/os-specific/linux/kernel/update-mainline.py')
-rwxr-xr-xpkgs/os-specific/linux/kernel/update-mainline.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/pkgs/os-specific/linux/kernel/update-mainline.py b/pkgs/os-specific/linux/kernel/update-mainline.py
index e7c37e9ab999f..8fac82e6633ee 100755
--- a/pkgs/os-specific/linux/kernel/update-mainline.py
+++ b/pkgs/os-specific/linux/kernel/update-mainline.py
@@ -9,6 +9,7 @@ import re
 import subprocess
 import urllib.request
 import sys
+import os
 
 
 HERE = pathlib.Path(__file__).parent
@@ -24,6 +25,7 @@ class KernelNature(Enum):
 class KernelRelease:
     nature: KernelNature
     version: str
+    branch: str
     date: str
     link: str
     eol: bool = False
@@ -43,7 +45,14 @@ def parse_release(release: Tag) -> KernelRelease | None:
     assert link is not None, f'link for kernel {version} is non-existent'
     eol = bool(release.find(class_='eolkernel'))
 
-    return KernelRelease(nature=nature, version=version, date=date, link=link, eol=eol)
+    return KernelRelease(
+        nature=nature,
+        branch=get_branch(version),
+        version=version,
+        date=date,
+        link=link,
+        eol=eol,
+    )
 
 def get_branch(version: str):
     # This is a testing kernel.
@@ -53,9 +62,18 @@ def get_branch(version: str):
         major, minor, *_ = version.split(".")
         return f"{major}.{minor}"
 
+def get_hash(kernel: KernelRelease):
+    if kernel.branch == "testing":
+        args = ["--unpack"]
+    else:
+        args = []
 
-def get_hash(url: str):
-    return subprocess.check_output(["nix-prefetch-url", url]).decode().strip()
+    hash = (
+        subprocess.check_output(["nix-prefetch-url", kernel.link] + args)
+        .decode()
+        .strip()
+    )
+    return f"sha256:{hash}"
 
 
 def commit(message):
@@ -91,13 +109,17 @@ def main():
 
         print(message)
 
-        all_kernels[branch] = {"version": kernel.version, "hash": get_hash(kernel.link)}
+        all_kernels[branch] = {
+            "version": kernel.version,
+            "hash": get_hash(kernel),
+        }
 
         with VERSIONS_FILE.open("w") as fd:
             json.dump(all_kernels, fd, indent=4)
             fd.write("\n")  # makes editorconfig happy
 
-        commit(message)
+        if os.environ.get("COMMIT") == "1":
+            commit(message)
 
 
 if __name__ == "__main__":