Merge pull request #161773 from psydvl/kernel/zen+lqx

`linux_zen` & `linux_lqx`: unify, add `updateScript` & `linux_lqx` -> 5.18.7

authored by Thiago Kenji Okada and committed by GitHub 1cd3bf82 944270bc

+150 -92
-26
pkgs/os-specific/linux/kernel/linux-lqx.nix
··· 1 - { lib, fetchFromGitHub, buildLinux, linux_zen, ... } @ args: 2 - 3 - let 4 - version = "5.15.16"; 5 - suffix = "lqx2"; 6 - in 7 - 8 - buildLinux (args // { 9 - modDirVersion = "${version}-${suffix}"; 10 - inherit version; 11 - isZen = true; 12 - 13 - src = fetchFromGitHub { 14 - owner = "zen-kernel"; 15 - repo = "zen-kernel"; 16 - rev = "v${version}-${suffix}"; 17 - sha256 = "sha256-kdT/hiASZ72pkS0Igta0KT0GWTgDRjxBnd5CQ0eonfg="; 18 - }; 19 - 20 - extraMeta = { 21 - branch = "5.14/master"; 22 - maintainers = with lib.maintainers; [ atemu ]; 23 - description = linux_zen.meta.description + " (Same as linux_zen but less aggressive release schedule)"; 24 - }; 25 - 26 - } // (args.argsOverride or { }))
···
-39
pkgs/os-specific/linux/kernel/linux-zen.nix
··· 1 - { lib, fetchFromGitHub, buildLinux, ... } @ args: 2 - 3 - let 4 - # having the full version string here makes it easier to update 5 - modDirVersion = "5.18.5-zen1"; 6 - parts = lib.splitString "-" modDirVersion; 7 - version = lib.elemAt parts 0; 8 - suffix = lib.elemAt parts 1; 9 - 10 - numbers = lib.splitString "." version; 11 - branch = "${lib.elemAt numbers 0}.${lib.elemAt numbers 1}"; 12 - rev = if ((lib.elemAt numbers 2) == "0") then "v${branch}-${suffix}" else "v${modDirVersion}"; 13 - in 14 - 15 - buildLinux (args // { 16 - inherit version modDirVersion; 17 - isZen = true; 18 - 19 - src = fetchFromGitHub { 20 - owner = "zen-kernel"; 21 - repo = "zen-kernel"; 22 - inherit rev; 23 - sha256 = "sha256-q6a8Wyzs6GNQ39mV+q/9N6yo/kXS9ZH+QTfGka42gk4="; 24 - }; 25 - 26 - structuredExtraConfig = with lib.kernel; { 27 - ZEN_INTERACTIVE = yes; 28 - # TODO: Remove once #175433 reaches master 29 - # https://nixpk.gs/pr-tracker.html?pr=175433 30 - WERROR = no; 31 - }; 32 - 33 - extraMeta = { 34 - inherit branch; 35 - maintainers = with lib.maintainers; [ atemu andresilva ]; 36 - description = "Built using the best configuration and kernel sources for desktop, multimedia, and gaming workloads."; 37 - }; 38 - 39 - } // (args.argsOverride or { }))
···
+97
pkgs/os-specific/linux/kernel/update-zen.py
···
··· 1 + #! /usr/bin/env nix-shell 2 + #! nix-shell -i python3 -p python3 nix nix-prefetch-git 3 + 4 + import fileinput 5 + import json 6 + import os 7 + import sys 8 + import re 9 + import subprocess 10 + 11 + from datetime import datetime 12 + from urllib.request import urlopen, Request 13 + 14 + 15 + def panic(exc): 16 + raise Exception(exc) 17 + 18 + 19 + DIR = os.path.dirname(os.path.abspath(__file__)) 20 + HEADERS = {'Accept': 'application/vnd.github.v3+json'} 21 + 22 + 23 + def github_api_request(endpoint): 24 + base_url = 'https://api.github.com/' 25 + request = Request(base_url + endpoint, headers=HEADERS) 26 + with urlopen(request) as http_response: 27 + return json.loads(http_response.read().decode('utf-8')) 28 + 29 + 30 + def get_commit_date(repo, sha): 31 + url = f'https://api.github.com/repos/{repo}/commits/{sha}' 32 + request = Request(url, headers=HEADERS) 33 + with urlopen(request) as http_response: 34 + commit = json.loads(http_response.read().decode()) 35 + date = commit['commit']['committer']['date'].rstrip('Z') 36 + date = datetime.fromisoformat(date).date().isoformat() 37 + return 'unstable-' + date 38 + 39 + 40 + def nix_prefetch_git(url, rev): 41 + """Prefetches the requested Git revision (incl. submodules) of the given repository URL.""" 42 + print(f'nix-prefetch-git {url} {rev}') 43 + out = subprocess.check_output([ 44 + 'nix-prefetch-git', '--quiet', 45 + '--url', url, 46 + '--rev', rev, 47 + '--fetch-submodules']) 48 + return json.loads(out)['sha256'] 49 + 50 + 51 + def nix_prefetch_url(url, unpack=False): 52 + """Prefetches the content of the given URL.""" 53 + print(f'nix-prefetch-url {url}') 54 + options = ['--type', 'sha256'] 55 + if unpack: 56 + options += ['--unpack'] 57 + out = subprocess.check_output(['nix-prefetch-url'] + options + [url]) 58 + return out.decode('utf-8').rstrip() 59 + 60 + 61 + def update_file(relpath, variant, version, suffix, sha256): 62 + file_path = os.path.join(DIR, relpath) 63 + with fileinput.FileInput(file_path, inplace=True) as f: 64 + for line in f: 65 + result = line 66 + result = re.sub( 67 + fr'^ version = ".+"; #{variant}', 68 + f' version = "{version}"; #{variant}', 69 + result) 70 + result = re.sub( 71 + fr'^ suffix = ".+"; #{variant}', 72 + f' suffix = "{suffix}"; #{variant}', 73 + result) 74 + result = re.sub( 75 + fr'^ sha256 = ".+"; #{variant}', 76 + f' sha256 = "{sha256}"; #{variant}', 77 + result) 78 + print(result, end='') 79 + 80 + 81 + if __name__ == "__main__": 82 + if len(sys.argv) == 1: 83 + panic("Update variant expected") 84 + variant = sys.argv[1] 85 + if variant not in ("zen", "lqx"): 86 + panic(f"Unexepected variant instead of 'zen' or 'lqx': {sys.argv[1]}") 87 + pattern = re.compile(fr"v(\d+\.\d+\.?\d*)-({variant}\d+)") 88 + zen_tags = github_api_request('repos/zen-kernel/zen-kernel/releases') 89 + for tag in zen_tags: 90 + zen_match = pattern.match(tag['tag_name']) 91 + if zen_match: 92 + zen_tag = zen_match.group(0) 93 + zen_version = zen_match.group(1) 94 + zen_suffix = zen_match.group(2) 95 + break 96 + zen_hash = nix_prefetch_git('https://github.com/zen-kernel/zen-kernel.git', zen_tag) 97 + update_file('zen-kernels.nix', variant, zen_version, zen_suffix, zen_hash)
-23
pkgs/os-specific/linux/kernel/update-zen.sh
··· 1 - #! /usr/bin/env nix-shell 2 - #! nix-shell -I nixpkgs=../../../.. -i bash -p nix-prefetch git gnused gnugrep nix curl 3 - set -euo pipefail -x 4 - 5 - nixpkgs="$(git rev-parse --show-toplevel)" 6 - old=$(nix-instantiate --eval -A linuxPackages_zen.kernel.modDirVersion "$nixpkgs") 7 - old="${old%\"}" 8 - old="${old#\"}" 9 - new=$(curl https://github.com/zen-kernel/zen-kernel/releases.atom | grep -m1 -o -E '[0-9.]+-zen[0-9]+') 10 - # add ".0" patch to modDirVersion when minor only 11 - new=$(echo "$new" | sed -E 's/^([0-9]+)\.([0-9]+)-(\w+)$/\1.\2.0-\3/') 12 - if [[ "$new" == "$old" ]]; then 13 - echo "already up-to-date" 14 - exit 0 15 - fi 16 - 17 - path="$nixpkgs/pkgs/os-specific/linux/kernel/linux-zen.nix" 18 - 19 - sed -i -e "s!modDirVersion = \".*\"!modDirVersion = \"${new}\"!" "$path" 20 - checksum=$(nix-prefetch "(import ${nixpkgs} {}).linuxPackages_zen.kernel") 21 - sed -i -e "s!sha256 = \".*\"!sha256 = \"${checksum}\"!" "$path" 22 - 23 - git commit -m "linuxKernel.kernels.linux_zen: ${old} -> ${new}" $path
···
+45
pkgs/os-specific/linux/kernel/zen-kernels.nix
···
··· 1 + { lib, fetchFromGitHub, buildLinux, ... } @ args: 2 + 3 + let 4 + # comments with variant added for update script 5 + # ./update-zen.py zen 6 + zenVariant = { 7 + version = "5.18.7"; #zen 8 + suffix = "zen1"; #zen 9 + sha256 = "1dxiwrbf15njqcq2kxbsg22hllpcvdwjhdf0gs3xx0xyjbwjyd26"; #zen 10 + isLqx = false; 11 + }; 12 + # ./update-zen.py lqx 13 + lqxVariant = { 14 + version = "5.18.7"; #lqx 15 + suffix = "lqx1"; #lqx 16 + sha256 = "0gyp4x8rlsg5bjr9c8qq0mk3wckyg0navc1sripkj8hrl51vm28c"; #lqx 17 + isLqx = true; 18 + }; 19 + zenKernelsFor = { version, suffix, sha256, isLqx }: buildLinux (args // { 20 + inherit version; 21 + modDirVersion = "${lib.concatStringsSep "." (lib.take 3 (lib.splitVersion version ++ [ "0" "0" ]))}-${suffix}"; 22 + isZen = true; 23 + 24 + src = fetchFromGitHub { 25 + owner = "zen-kernel"; 26 + repo = "zen-kernel"; 27 + rev = "v${version}-${suffix}"; 28 + inherit sha256; 29 + }; 30 + 31 + passthru.updateScript = [ ./update-zen.py (if isLqx then "lqx" else "zen") ]; 32 + 33 + extraMeta = { 34 + branch = lib.versions.majorMinor version + "/master"; 35 + maintainers = with lib.maintainers; [ atemu andresilva psydvl ]; 36 + description = "Built using the best configuration and kernel sources for desktop, multimedia, and gaming workloads." + 37 + lib.optionalString isLqx " (Same as linux_zen but less aggressive release schedule)"; 38 + }; 39 + 40 + } // (args.argsOverride or { })); 41 + in 42 + { 43 + zen = zenKernelsFor zenVariant; 44 + lqx = zenKernelsFor lqxVariant; 45 + }
+8 -4
pkgs/top-level/linux-kernels.nix
··· 196 ]; 197 }; 198 199 - linux_zen = callPackage ../os-specific/linux/kernel/linux-zen.nix { 200 kernelPatches = [ 201 kernelPatches.bridge_stp_helper 202 kernelPatches.request_key_helper 203 ]; 204 - }; 205 206 - linux_lqx = callPackage ../os-specific/linux/kernel/linux-lqx.nix { 207 kernelPatches = [ 208 kernelPatches.bridge_stp_helper 209 kernelPatches.request_key_helper 210 ]; 211 - }; 212 213 # This contains both the STABLE and EDGE variants of the XanMod kernel 214 xanmodKernels = callPackage ../os-specific/linux/kernel/xanmod-kernels.nix;
··· 196 ]; 197 }; 198 199 + # Using zenKernels like this due lqx&zen came from one source, but may have different base kernel version 200 + # https://github.com/NixOS/nixpkgs/pull/161773#discussion_r820134708 201 + zenKernels = callPackage ../os-specific/linux/kernel/zen-kernels.nix; 202 + 203 + linux_zen = (zenKernels { 204 kernelPatches = [ 205 kernelPatches.bridge_stp_helper 206 kernelPatches.request_key_helper 207 ]; 208 + }).zen; 209 210 + linux_lqx = (zenKernels { 211 kernelPatches = [ 212 kernelPatches.bridge_stp_helper 213 kernelPatches.request_key_helper 214 ]; 215 + }).lqx; 216 217 # This contains both the STABLE and EDGE variants of the XanMod kernel 218 xanmodKernels = callPackage ../os-specific/linux/kernel/xanmod-kernels.nix;