Files
nixpkgs/pkgs/os-specific/linux/kernel/update-xanmod.sh
T
eljamm 19298c32f0 linux_xanmod: change URL prefetching in update script
Recently, there has been an issue with `nix-prefetch` that broke the
update script:

```
--- SHOWING ERROR LOG FOR linux-xanmod-6.12.62 ----------------------

this path will be fetched (0.02 MiB download, 0.07 MiB unpacked):
  /nix/store/6xiirw87j5l8n6da4ijibw90r8v1b7zh-nix-prefetch-0.4.1
copying path '/nix/store/6xiirw87j5l8n6da4ijibw90r8v1b7zh-nix-prefetch-0.4.1' from 'https://cache.nixos.org'...
Updating Xanmod "lts" from 6.12.62 to 6.12.63 (xanmod1)
error:
       … while calling the 'zipAttrsWith' builtin
         at /nix/store/wdqrnd6fkxdsf4xn2kkfa8f42shfw0i3-source/lib/attrsets.nix:1701:5:
         1700|     in
         1701|     f [ ] [ rhs lhs ];
             |     ^
         1702|

       … while evaluating a branch condition
         at /nix/store/wdqrnd6fkxdsf4xn2kkfa8f42shfw0i3-source/lib/attrsets.nix:1478:29:
         1477|   */
         1478|   optionalAttrs = cond: as: if cond then as else { };
             |                             ^
         1479|

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: expected a set but found a function: «lambda extendsWithExclusion @ /nix/store/wdqrnd6fkxdsf4xn2kkfa8f42shfw0i3-source/lib/customisation.nix:846:30»
```

It's possible that this is caused by something else, but we should keep
the update script working until we find out what exactly and fix it.

Note: This first started happening to me on `nixos-25.11`, and is
[reproducible by other people](https://github.com/NixOS/nixpkgs/pull/468873#issuecomment-3624990626)
2025-12-19 07:36:30 +01:00

104 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env nix-shell
#!nix-shell -I nixpkgs=./. -i bash -p bash nix curl jq gawk gnused nixfmt
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
# Remove trailing slash
url="${url%/}"
# 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)
>&2 echo "Updating Xanmod \"$VARIANT\" from $OLD_VERSION to $NEW_VERSION ($SUFFIX)"
prefetchURL() {
result=$(nix-build -E "with import ./. {}; fetchzip { url=\"$1\"; hash=\"\"; }" 2>&1)
echo "$result" | awk '/got:/ {print $NF}'
}
URL="https://gitlab.com/api/v4/projects/xanmod%2Flinux/repository/archive.tar.gz?sha=$NEW_VERSION-$SUFFIX"
HASH="$(prefetchURL "$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"
# Customize commit
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/README.md#supported-features
COMMIT_BODY="
- Changelog: https://dl.xanmod.org/changelog/${NEW_VERSION%.*}/ChangeLog-$NEW_VERSION-xanmod1.gz
- Diff: https://gitlab.com/xanmod/linux/-/compare/$OLD_VERSION-xanmod1..$NEW_VERSION-xanmod1?from_project_id=51590166
"
jq -n --arg commitBody "$COMMIT_BODY" '[$ARGS.named]'