Commit c08efe14 authored by K900's avatar K900
Browse files

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.
parent c792f6b8
Loading
Loading
Loading
Loading
+10 −10
Original line number Diff line number Diff line
{
    "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"
    }
}
+17 −8
Original line number Diff line number Diff line
{ branch, lib, fetchurl, buildLinux, ... } @ args:
{ branch, lib, fetchurl, fetchzip, buildLinux, ... } @ args:

let
  allKernels = builtins.fromJSON (builtins.readFile ./kernels-org.json);
  thisKernel = allKernels.${branch};

  args' = (builtins.removeAttrs args ["branch"]) // rec {
  inherit (thisKernel) version;
    modDirVersion = lib.versions.pad 3 version;
    extraMeta.branch = branch;

    src = fetchurl {
  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";
      sha256 = thisKernel.hash;
        inherit (thisKernel) hash;
      };

  args' = (builtins.removeAttrs args ["branch"]) // {
    inherit src version;

    modDirVersion = lib.versions.pad 3 version;
    extraMeta.branch = branch;
  } // (args.argsOverride or {});
in
buildLinux args'
+27 −5
Original line number Diff line number Diff line
@@ -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,12 +109,16 @@ 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

        if os.environ.get("COMMIT") == "1":
            commit(message)