linux_xanmod, linux_xanmod_latest: add update script

Co-authored-by: Mathias Zhang <me@zzzsy.top>

authored by eljamm Mathias Zhang and committed by Alyssa Ross 6f2ad75d 8396333e

+93
+86
pkgs/os-specific/linux/kernel/update-xanmod.sh
···
··· 1 + #!/usr/bin/env nix-shell 2 + #!nix-shell -i bash -p bash nix-prefetch curl jq gawk gnused nixfmt-rfc-style 3 + 4 + set -euo pipefail 5 + 6 + SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" 7 + FILE_PATH="$SCRIPT_DIR/xanmod-kernels.nix" 8 + 9 + get_old_version() { 10 + local file_path="$1" 11 + local variant="$2" 12 + 13 + grep -A 2 "$variant = {" "$file_path" | grep "version =" | cut -d '"' -f 2 14 + } 15 + 16 + VARIANT="${1:-lts}" 17 + OLD_VERSION=${UPDATE_NIX_OLD_VERSION:-$(get_old_version "$FILE_PATH" "$VARIANT")} 18 + 19 + RELEASES=$(curl --silent https://gitlab.com/api/v4/projects/xanmod%2Flinux/releases) 20 + 21 + # list of URLs. latest first, oldest last 22 + RELEASE_URLS=$(echo "$RELEASES" | jq '.[].assets.links.[0].name') 23 + 24 + while IFS= read -r url; do 25 + # Get variant, version and suffix from url fields: 26 + # 8 9 NF 27 + # | | | 28 + # https://.../<variant>/<version>-<suffix> 29 + release_variant=$(echo "$url" | awk -F'[/-]' '{print $8}') 30 + release_version=$(echo "$url" | awk -F'[/-]' '{print $9}') 31 + 32 + # either xanmod1 or xanmod2 33 + suffix=$(echo "$url" | awk -F'[/-]' '{print $NF}') 34 + 35 + if [[ "$release_variant" == "$VARIANT" ]]; then 36 + if [[ "$release_version" == "$OLD_VERSION" ]]; then 37 + echo "Xanmod $VARIANT is up-to-date: ${OLD_VERSION}" 38 + exit 0 39 + else 40 + NEW_VERSION="$release_version" 41 + SUFFIX="$suffix" 42 + break 43 + fi 44 + fi 45 + done < <(echo "$RELEASE_URLS" | jq -r) 46 + 47 + echo "Updating Xanmod \"$VARIANT\" from $OLD_VERSION to $NEW_VERSION ($SUFFIX)" 48 + 49 + URL="https://gitlab.com/api/v4/projects/xanmod%2Flinux/repository/archive.tar.gz?sha=$NEW_VERSION-$SUFFIX" 50 + HASH="$(nix-prefetch fetchzip --quiet --url "$URL")" 51 + 52 + update_variant() { 53 + local file_path="$1" 54 + local variant="$2" 55 + local new_version="$3" 56 + local new_hash="$4" 57 + local suffix="$5" 58 + 59 + # ${variant} = { <- range start 60 + # version = ... 61 + # hash = ... 62 + # suffix = ... 63 + # }; <- range end 64 + range_start="^\s*$variant = {" 65 + range_end="^\s*};" 66 + 67 + # - Update the version and hash using sed range addresses 68 + # - Remove suffix line, if it exists 69 + sed -i -e "/$range_start/,/$range_end/ { 70 + s|^\s*version = \".*\";| version = \"$new_version\";|; 71 + s|^\s*hash = \".*\";| hash = \"$new_hash\";|; 72 + /^\s*suffix = /d 73 + }" "$file_path" 74 + 75 + # Add suffix, if it's different than xanmod1 (the default) 76 + if [[ "$suffix" != "xanmod1" ]]; then 77 + sed -i -e "/$range_start/,/$range_end/ { 78 + s|$range_end| suffix = \"$suffix\";\n };|; 79 + }" "$file_path" 80 + fi 81 + 82 + # Apply proper formatting 83 + nixfmt "$file_path" 84 + } 85 + 86 + update_variant "$FILE_PATH" "$VARIANT" "$NEW_VERSION" "$HASH" "$SUFFIX"
+7
pkgs/os-specific/linux/kernel/xanmod-kernels.nix
··· 13 # NOTE: When updating these, please also take a look at the changes done to 14 # kernel config in the xanmod version commit 15 variants = { 16 lts = { 17 version = "6.12.40"; 18 hash = "sha256-L8wL47kD+lrnJsrp0B1MZ2Lg8zs+m1vQ24gPGuvxIA0="; 19 }; 20 main = { 21 version = "6.15.8"; 22 hash = "sha256-P4DpTS0RhvsgBrNDsZMiA1NvCQucuPmJ4GDyF9mZ7ZU="; ··· 69 RCU_BOOST_DELAY = freeform "0"; 70 RCU_EXP_KTHREAD = yes; 71 }; 72 73 extraMeta = { 74 branch = lib.versions.majorMinor version;
··· 13 # NOTE: When updating these, please also take a look at the changes done to 14 # kernel config in the xanmod version commit 15 variants = { 16 + # ./update-xanmod.sh lts 17 lts = { 18 version = "6.12.40"; 19 hash = "sha256-L8wL47kD+lrnJsrp0B1MZ2Lg8zs+m1vQ24gPGuvxIA0="; 20 }; 21 + # ./update-xanmod.sh main 22 main = { 23 version = "6.15.8"; 24 hash = "sha256-P4DpTS0RhvsgBrNDsZMiA1NvCQucuPmJ4GDyF9mZ7ZU="; ··· 71 RCU_BOOST_DELAY = freeform "0"; 72 RCU_EXP_KTHREAD = yes; 73 }; 74 + 75 + extraPassthru.updateScript = [ 76 + ./update-xanmod.sh 77 + variant 78 + ]; 79 80 extraMeta = { 81 branch = lib.versions.majorMinor version;