diff --git a/pkgs/os-specific/linux/kernel/update-xanmod.sh b/pkgs/os-specific/linux/kernel/update-xanmod.sh new file mode 100755 index 000000000000..fd786872fd3c --- /dev/null +++ b/pkgs/os-specific/linux/kernel/update-xanmod.sh @@ -0,0 +1,86 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p bash nix-prefetch curl jq gawk gnused nixfmt-rfc-style + +set -euo pipefail + +SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")" +FILE_PATH="$SCRIPT_DIR/xanmod-kernels.nix" + +get_old_version() { + local file_path="$1" + local variant="$2" + + grep -A 2 "$variant = {" "$file_path" | grep "version =" | cut -d '"' -f 2 +} + +VARIANT="${1:-lts}" +OLD_VERSION=${UPDATE_NIX_OLD_VERSION:-$(get_old_version "$FILE_PATH" "$VARIANT")} + +RELEASES=$(curl --silent https://gitlab.com/api/v4/projects/xanmod%2Flinux/releases) + +# list of URLs. latest first, oldest last +RELEASE_URLS=$(echo "$RELEASES" | jq '.[].assets.links.[0].name') + +while IFS= read -r url; do + # Get variant, version and suffix from url fields: + # 8 9 NF + # | | | + # https://...//- + release_variant=$(echo "$url" | awk -F'[/-]' '{print $8}') + release_version=$(echo "$url" | awk -F'[/-]' '{print $9}') + + # either xanmod1 or xanmod2 + suffix=$(echo "$url" | awk -F'[/-]' '{print $NF}') + + if [[ "$release_variant" == "$VARIANT" ]]; then + if [[ "$release_version" == "$OLD_VERSION" ]]; then + echo "Xanmod $VARIANT is up-to-date: ${OLD_VERSION}" + exit 0 + else + NEW_VERSION="$release_version" + SUFFIX="$suffix" + break + fi + fi +done < <(echo "$RELEASE_URLS" | jq -r) + +echo "Updating Xanmod \"$VARIANT\" from $OLD_VERSION to $NEW_VERSION ($SUFFIX)" + +URL="https://gitlab.com/api/v4/projects/xanmod%2Flinux/repository/archive.tar.gz?sha=$NEW_VERSION-$SUFFIX" +HASH="$(nix-prefetch fetchzip --quiet --url "$URL")" + +update_variant() { + local file_path="$1" + local variant="$2" + local new_version="$3" + local new_hash="$4" + local suffix="$5" + + # ${variant} = { <- range start + # version = ... + # hash = ... + # suffix = ... + # }; <- range end + range_start="^\s*$variant = {" + range_end="^\s*};" + + # - Update the version and hash using sed range addresses + # - Remove suffix line, if it exists + sed -i -e "/$range_start/,/$range_end/ { + s|^\s*version = \".*\";| version = \"$new_version\";|; + s|^\s*hash = \".*\";| hash = \"$new_hash\";|; + /^\s*suffix = /d + }" "$file_path" + + # Add suffix, if it's different than xanmod1 (the default) + if [[ "$suffix" != "xanmod1" ]]; then + sed -i -e "/$range_start/,/$range_end/ { + s|$range_end| suffix = \"$suffix\";\n };|; + }" "$file_path" + fi + + # Apply proper formatting + nixfmt "$file_path" +} + +update_variant "$FILE_PATH" "$VARIANT" "$NEW_VERSION" "$HASH" "$SUFFIX" diff --git a/pkgs/os-specific/linux/kernel/xanmod-kernels.nix b/pkgs/os-specific/linux/kernel/xanmod-kernels.nix index ec5c1056188c..c2d9abd53d29 100644 --- a/pkgs/os-specific/linux/kernel/xanmod-kernels.nix +++ b/pkgs/os-specific/linux/kernel/xanmod-kernels.nix @@ -13,13 +13,16 @@ let # NOTE: When updating these, please also take a look at the changes done to # kernel config in the xanmod version commit variants = { + # ./update-xanmod.sh lts lts = { - version = "6.12.28"; - hash = "sha256-afmAC1tdiggI2qN1Kf9fJiUJqC9d8gzTj5PAg7wsiuw="; + version = "6.12.47"; + hash = "sha256-jR1VqFE1jF5mTRAp+Xxswmh9bMIolJtCk4QgMHzIhao="; + isLTS = true; }; + # ./update-xanmod.sh main main = { - version = "6.14.6"; - hash = "sha256-wI383p+g03RrNUkPdo0TnB1n5yZI7bGwcSjB/9HpQH0="; + version = "6.16.7"; + hash = "sha256-/CFSGaDbK0pZgGGOOxixwOQgeD1OsbUhtRss4VbXHxE="; }; }; @@ -28,6 +31,7 @@ let version, suffix ? "xanmod1", hash, + isLTS ? false, }: buildLinux ( args @@ -70,6 +74,12 @@ let RCU_EXP_KTHREAD = yes; }; + extraPassthru.updateScript = [ + ./update-xanmod.sh + variant + ]; + inherit isLTS; + extraMeta = { branch = lib.versions.majorMinor version; maintainers = with lib.maintainers; [