From 08e206737475db9de0192745aa8f6ff2d9283d9d Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Sun, 3 Aug 2025 16:16:10 -0300 Subject: [PATCH 1/3] k3s: fix update script Fixes #430227 --- .../networking/cluster/k3s/update-script.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/update-script.sh b/pkgs/applications/networking/cluster/k3s/update-script.sh index a2693b542e99..407658b4ee11 100755 --- a/pkgs/applications/networking/cluster/k3s/update-script.sh +++ b/pkgs/applications/networking/cluster/k3s/update-script.sh @@ -76,15 +76,16 @@ EOF mv chart-versions.nix.update chart-versions.nix # Concatenate all sha256sums, one entry per line -SHA256_HASHES="$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-amd64.txt") - \n$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm64.txt") - \n$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm.txt")" +SHA256_HASHES="\ +$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-amd64.txt") +$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm64.txt") +$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm.txt") +$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/k3s-images.txt" | sha256sum | cut -d' ' -f1) k3s-images.txt" # Get all airgap images files associated with this release IMAGES_ARCHIVES=$(curl "https://api.github.com/repos/k3s-io/k3s/releases/tags/v${K3S_VERSION}" | \ # Filter the assets so that only zstd archives and text files that have "images" in their name remain - jq -r '.assets[] | select(.name | contains("images")) | - select(.content_type == "application/zstd" or .content_type == "text/plain; charset=utf-8") | + jq -r '.assets[] | select(.name | (contains("images") and (endswith(".tar.zst") or endswith("k3s-images.txt")))) | "\(.name) \(.browser_download_url)"') # Create a JSON object for each airgap images file and prefetch all download URLs in the process From acd25a81e0be5e89c500b0e7a7d6d6f795e5c7cc Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Sun, 3 Aug 2025 16:43:49 -0300 Subject: [PATCH 2/3] k3s: improve curl usage in update-script --- .../networking/cluster/k3s/update-script.sh | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/update-script.sh b/pkgs/applications/networking/cluster/k3s/update-script.sh index 407658b4ee11..4c9889c18170 100755 --- a/pkgs/applications/networking/cluster/k3s/update-script.sh +++ b/pkgs/applications/networking/cluster/k3s/update-script.sh @@ -8,13 +8,15 @@ MINOR_VERSION="${1:?Must provide a minor version number, like '26', as the only WORKDIR=$(mktemp -d) trap "rm -rf ${WORKDIR}" EXIT +# GitHub caps requests to GitHub API without GITHUB_TOKEN +CURL="curl --silent --fail --location ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"}" + NIXPKGS_ROOT="$(git rev-parse --show-toplevel)"/ NIXPKGS_K3S_PATH=$(cd $(dirname ${BASH_SOURCE[0]}); pwd -P)/ OLD_VERSION="$(nix-instantiate --eval -E "with import $NIXPKGS_ROOT. {}; k3s_1_${MINOR_VERSION}.version or (builtins.parseDrvName k3s_1_${MINOR_VERSION}.name).version" | tr -d '"')" LATEST_TAG_RAWFILE=${WORKDIR}/latest_tag.json -curl --silent -f ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \ - https://api.github.com/repos/k3s-io/k3s/releases > ${LATEST_TAG_RAWFILE} +$CURL https://api.github.com/repos/k3s-io/k3s/releases > ${LATEST_TAG_RAWFILE} LATEST_TAG_NAME=$(cat ${LATEST_TAG_RAWFILE} | \ jq -r 'map(select(.prerelease == false))' | \ @@ -23,8 +25,7 @@ LATEST_TAG_NAME=$(cat ${LATEST_TAG_RAWFILE} | \ K3S_VERSION=$(echo ${LATEST_TAG_NAME} | sed 's/^v//') -K3S_COMMIT=$(curl --silent -f ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"} \ - https://api.github.com/repos/k3s-io/k3s/git/refs/tags \ +K3S_COMMIT=$($CURL https://api.github.com/repos/k3s-io/k3s/git/refs/tags \ | jq -r "map(select(.ref == \"refs/tags/${LATEST_TAG_NAME}\")) | .[0] | .object.sha") PREFETCH_META=$(nix-prefetch-url --unpack --print-path https://github.com/k3s-io/k3s/archive/refs/tags/${LATEST_TAG_NAME}.tar.gz) @@ -77,13 +78,13 @@ mv chart-versions.nix.update chart-versions.nix # Concatenate all sha256sums, one entry per line SHA256_HASHES="\ -$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-amd64.txt") -$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm64.txt") -$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm.txt") -$(curl -L "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/k3s-images.txt" | sha256sum | cut -d' ' -f1) k3s-images.txt" +$($CURL "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-amd64.txt") +$($CURL "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm64.txt") +$($CURL "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/sha256sum-arm.txt") +$($CURL "https://github.com/k3s-io/k3s/releases/download/v${K3S_VERSION}/k3s-images.txt" | sha256sum | cut -d' ' -f1) k3s-images.txt" # Get all airgap images files associated with this release -IMAGES_ARCHIVES=$(curl "https://api.github.com/repos/k3s-io/k3s/releases/tags/v${K3S_VERSION}" | \ +IMAGES_ARCHIVES=$($CURL "https://api.github.com/repos/k3s-io/k3s/releases/tags/v${K3S_VERSION}" | \ # Filter the assets so that only zstd archives and text files that have "images" in their name remain jq -r '.assets[] | select(.name | (contains("images") and (endswith(".tar.zst") or endswith("k3s-images.txt")))) | "\(.name) \(.browser_download_url)"') From 6784591591dbe49e8ea338823afd19c17448ea2d Mon Sep 17 00:00:00 2001 From: superherointj <5861043+superherointj@users.noreply.github.com> Date: Sun, 3 Aug 2025 16:47:52 -0300 Subject: [PATCH 3/3] k3s: parametrize major version in update script --- .../networking/cluster/k3s/update-script.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkgs/applications/networking/cluster/k3s/update-script.sh b/pkgs/applications/networking/cluster/k3s/update-script.sh index 4c9889c18170..b1c7c2915d3c 100755 --- a/pkgs/applications/networking/cluster/k3s/update-script.sh +++ b/pkgs/applications/networking/cluster/k3s/update-script.sh @@ -3,6 +3,7 @@ set -x -eu -o pipefail +MAJOR_VERSION=1 MINOR_VERSION="${1:?Must provide a minor version number, like '26', as the only argument}" WORKDIR=$(mktemp -d) @@ -13,7 +14,7 @@ CURL="curl --silent --fail --location ${GITHUB_TOKEN:+-u ":$GITHUB_TOKEN"}" NIXPKGS_ROOT="$(git rev-parse --show-toplevel)"/ NIXPKGS_K3S_PATH=$(cd $(dirname ${BASH_SOURCE[0]}); pwd -P)/ -OLD_VERSION="$(nix-instantiate --eval -E "with import $NIXPKGS_ROOT. {}; k3s_1_${MINOR_VERSION}.version or (builtins.parseDrvName k3s_1_${MINOR_VERSION}.name).version" | tr -d '"')" +OLD_VERSION="$(nix-instantiate --eval -E "with import $NIXPKGS_ROOT. {}; k3s_${MAJOR_VERSION}_${MINOR_VERSION}.version or (builtins.parseDrvName k3s_${MAJOR_VERSION}_${MINOR_VERSION}.name).version" | tr -d '"')" LATEST_TAG_RAWFILE=${WORKDIR}/latest_tag.json $CURL https://api.github.com/repos/k3s-io/k3s/releases > ${LATEST_TAG_RAWFILE} @@ -21,7 +22,7 @@ $CURL https://api.github.com/repos/k3s-io/k3s/releases > ${LATEST_TAG_RAWFILE} LATEST_TAG_NAME=$(cat ${LATEST_TAG_RAWFILE} | \ jq -r 'map(select(.prerelease == false))' | \ jq 'map(.tag_name)' | \ - grep -v -e rc -e engine | tail -n +2 | head -n -1 | sed 's|[", ]||g' | sort -rV | grep -E "^v1\.${MINOR_VERSION}\." | head -n1) + grep -v -e rc -e engine | tail -n +2 | head -n -1 | sed 's|[", ]||g' | sort -rV | grep -E "^v${MAJOR_VERSION}\.${MINOR_VERSION}\." | head -n1) K3S_VERSION=$(echo ${LATEST_TAG_NAME} | sed 's/^v//') @@ -57,7 +58,7 @@ if [[ "${#CHART_FILES[@]}" != "2" ]]; then exit 1 fi -cd "${NIXPKGS_K3S_PATH}/1_${MINOR_VERSION}" +cd "${NIXPKGS_K3S_PATH}/${MAJOR_VERSION}_${MINOR_VERSION}" CHARTS_URL=https://k3s.io/k3s-charts/assets # Get metadata for both files @@ -123,7 +124,7 @@ cat >versions.nix <