Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions pkgs/os-specific/linux/kernel/update-xanmod.sh
Original file line number Diff line number Diff line change
@@ -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://.../<variant>/<version>-<suffix>
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"
7 changes: 7 additions & 0 deletions pkgs/os-specific/linux/kernel/xanmod-kernels.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ 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.40";
hash = "sha256-L8wL47kD+lrnJsrp0B1MZ2Lg8zs+m1vQ24gPGuvxIA0=";
};
# ./update-xanmod.sh main
main = {
version = "6.15.8";
hash = "sha256-P4DpTS0RhvsgBrNDsZMiA1NvCQucuPmJ4GDyF9mZ7ZU=";
Expand Down Expand Up @@ -70,6 +72,11 @@ let
RCU_EXP_KTHREAD = yes;
};

extraPassthru.updateScript = [
./update-xanmod.sh
variant
];

extraMeta = {
branch = lib.versions.majorMinor version;
maintainers = with lib.maintainers; [
Expand Down
Loading