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.
This commit is contained in:
K900 2023-09-22 14:28:05 +03:00
parent c792f6b81a
commit c08efe1438
3 changed files with 54 additions and 23 deletions

View file

@ -1,38 +1,38 @@
{
"testing": {
"version": "6.6-rc1",
"hash": "02zh3dnikyhhlas9xccia963d4yqmzq0m4b8s10x8mjng3na45hd"
"version": "6.6-rc2",
"hash": "sha256:1hbva5vsfi48h82ll4kmhzm5hxp7340bj2smwgvjikam26icaj54"
},
"6.5": {
"version": "6.5.4",
"hash": "0s8nzd8yaq06bq8byk7aakbk95gh0rhlif26h1biw94v48anrxxx"
"hash": "sha256:0s8nzd8yaq06bq8byk7aakbk95gh0rhlif26h1biw94v48anrxxx"
},
"6.4": {
"version": "6.4.16",
"hash": "0zgj1z97jyx7wf12zrnlcp0mj4cl43ais9qsy6dh1jwylf2fq9ln"
"hash": "sha256:0zgj1z97jyx7wf12zrnlcp0mj4cl43ais9qsy6dh1jwylf2fq9ln"
},
"6.1": {
"version": "6.1.54",
"hash": "09sfrq2l8f777mx2n9mhb6bgz1064bl04921byqnmk87si31w653"
"hash": "sha256:09sfrq2l8f777mx2n9mhb6bgz1064bl04921byqnmk87si31w653"
},
"5.15": {
"version": "5.15.132",
"hash": "1b0qjsaqjw2rk86shmmrj2aasblkn27acjmc761vnjg7sv2baxs1"
"hash": "sha256:1b0qjsaqjw2rk86shmmrj2aasblkn27acjmc761vnjg7sv2baxs1"
},
"5.10": {
"version": "5.10.195",
"hash": "0n4vg2i9sq89wnz85arlyvwysh9s83cgzs5bk2wh98bivi5fwfs1"
"hash": "sha256:0n4vg2i9sq89wnz85arlyvwysh9s83cgzs5bk2wh98bivi5fwfs1"
},
"5.4": {
"version": "5.4.256",
"hash": "0fim5q9xakwnjfg48bpsic9r2r8dvrjlalqqkm9vh1rml9mhi967"
"hash": "sha256:0fim5q9xakwnjfg48bpsic9r2r8dvrjlalqqkm9vh1rml9mhi967"
},
"4.19": {
"version": "4.19.294",
"hash": "03x0xsb8a369zdr81hg6xdl5n5v48k6iwnhj6r29725777lvvbfc"
"hash": "sha256:03x0xsb8a369zdr81hg6xdl5n5v48k6iwnhj6r29725777lvvbfc"
},
"4.14": {
"version": "4.14.325",
"hash": "117p1mdha57f6d3kdwac9jrbmib7g77q4xhir8ghl6fmrs1f2sav"
"hash": "sha256:117p1mdha57f6d3kdwac9jrbmib7g77q4xhir8ghl6fmrs1f2sav"
}
}

View file

@ -1,18 +1,27 @@
{ branch, lib, fetchurl, buildLinux, ... } @ args:
{ branch, lib, fetchurl, fetchzip, buildLinux, ... } @ args:
let
allKernels = builtins.fromJSON (builtins.readFile ./kernels-org.json);
thisKernel = allKernels.${branch};
inherit (thisKernel) version;
src =
# testing kernels are a special case because they don't have tarballs on the CDN
if branch == "testing"
then fetchzip {
url = "https://git.kernel.org/torvalds/t/linux-${version}.tar.gz";
inherit (thisKernel) hash;
}
else fetchurl {
url = "mirror://kernel/linux/kernel/v${lib.versions.major version}.x/linux-${version}.tar.xz";
inherit (thisKernel) hash;
};
args' = (builtins.removeAttrs args ["branch"]) // {
inherit src version;
args' = (builtins.removeAttrs args ["branch"]) // rec {
inherit (thisKernel) version;
modDirVersion = lib.versions.pad 3 version;
extraMeta.branch = branch;
src = fetchurl {
url = "mirror://kernel/linux/kernel/v${lib.versions.major version}.x/linux-${version}.tar.xz";
sha256 = thisKernel.hash;
};
} // (args.argsOverride or {});
in
buildLinux args'

View file

@ -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__":