···9292 echo "base=$base" >> "$GITHUB_ENV"
9393 - uses: cachix/install-nix-action@7ac1ec25491415c381d9b62f0657c7a028df52a7 # v24
9494 - name: Fetching the tool
9595- run: pkgs/test/nixpkgs-check-by-name/scripts/fetch-tool.sh "$GITHUB_BASE_REF" result
9595+ run: pkgs/test/nixpkgs-check-by-name/scripts/fetch-pinned-tool.sh result
9696 - name: Running nixpkgs-check-by-name
9797 run: |
9898 if result/bin/nixpkgs-check-by-name --base "$base" .; then
+11-4
pkgs/test/nixpkgs-check-by-name/scripts/README.md
···11# CI-related Scripts
2233-This directory contains scripts used and related to the CI running the `pkgs/by-name` checks in Nixpkgs. See also the [CI GitHub Action](../../../../.github/workflows/check-by-name.yml).
33+This directory contains scripts and files used and related to the CI running the `pkgs/by-name` checks in Nixpkgs.
44+See also the [CI GitHub Action](../../../../.github/workflows/check-by-name.yml).
4556## `./run-local.sh BASE_BRANCH [REPOSITORY]`
67···1516- `BASE_BRANCH`: The base branch to use, e.g. master or release-23.11
1617- `REPOSITORY`: The repository to fetch the base branch from, defaults to https://github.com/NixOS/nixpkgs.git
17181818-## `./fetch-tool.sh BASE_BRANCH OUTPUT_PATH`
1919+## `./update-pinned-tool.sh`
2020+2121+Updates the pinned CI tool in [`./pinned-tool.json`](./pinned-tool.json) to the
2222+[latest version from the `nixos-unstable` channel](https://hydra.nixos.org/job/nixos/trunk-combined/nixpkgs.tests.nixpkgs-check-by-name.x86_64-linux)
2323+2424+This script is called manually once the CI tooling needs to be updated.
2525+2626+## `./fetch-pinned-tool.sh OUTPUT_PATH`
19272020-Fetches the Hydra-prebuilt nixpkgs-check-by-name to use from the NixOS channel corresponding to the given base branch.
2828+Fetches the pinned tooling specified in [`./pinned-tool.json`](./pinned-tool.json).
21292230This script is used both by [`./run-local.sh`](#run-local-sh-base-branch-repository) and CI.
23312432Arguments:
2525-- `BASE_BRANCH`: The base branch to use, e.g. master or release-23.11
2633- `OUTPUT_PATH`: The output symlink path for the tool
···11+#!/usr/bin/env bash
22+# Try to not use nix-shell here to avoid fetching Nixpkgs,
33+# especially since this is used in CI
44+# The only dependency is `jq`, which in CI is implicitly available
55+# And when run from ./run-local.sh is provided by that parent script
66+77+set -o pipefail -o errexit -o nounset
88+99+trace() { echo >&2 "$@"; }
1010+1111+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
1212+1313+pin_file=$SCRIPT_DIR/pinned-tool.json
1414+1515+if (( $# < 1 )); then
1616+ trace "Usage: $0 fetch OUTPUT_PATH"
1717+ trace "OUTPUT_PATH: The output symlink path for the tool"
1818+ exit 1
1919+fi
2020+output=$1
2121+2222+trace "Reading $pin_file.. "
2323+rev=$(jq -r .rev "$SCRIPT_DIR"/pinned-tool.json)
2424+trace -e "Git revision is \e[34m$rev\e[0m"
2525+path=$(jq -r .path "$SCRIPT_DIR"/pinned-tool.json)
2626+trace "Tooling path is $path"
2727+2828+trace -n "Fetching the prebuilt version of nixpkgs-check-by-name.. "
2929+nix-store --add-root "$output" -r "$path" >/dev/null
3030+realpath "$output"
···11#!/usr/bin/env bash
22-# Fetches the prebuilt nixpkgs-check-by-name to use from
33-# the NixOS channel corresponding to the given base branch
44-55-set -o pipefail -o errexit -o nounset
22+# Legacy script to make CI work for the PR that replaces this
33+# Needed due to `.github/workflows/check-by-name.yml` using `pull_request_target`,
44+# which uses the workflow from the base branch, which still uses this script.
55+# This file can be removed after the PR replacing it is merged.
6677trace() { echo >&2 "$@"; }
8899if (( $# < 2 )); then
1010 trace "Usage: $0 BASE_BRANCH OUTPUT_PATH"
1111- trace "BASE_BRANCH: The base branch to use, e.g. master or release-23.11"
1111+ trace "BASE_BRANCH (unused): The base branch to use, e.g. master or release-23.11"
1212 trace "OUTPUT_PATH: The output symlink path for the tool"
1313 exit 1
1414fi
1515-baseBranch=$1
1615output=$2
17161818-trace -n "Determining the channel to use for PR base branch $baseBranch.. "
1919-if [[ "$baseBranch" =~ ^(release|staging|staging-next)-([0-9][0-9]\.[0-9][0-9])$ ]]; then
2020- # Use the release channel for all PRs to release-XX.YY, staging-XX.YY and staging-next-XX.YY
2121- preferredChannel=nixos-${BASH_REMATCH[2]}
2222-else
2323- # Use the nixos-unstable channel for all other PRs
2424- preferredChannel=nixos-unstable
2525-fi
2626-2727-# Check that the channel exists. It doesn't exist for fresh release branches
2828-if curl -fSs "https://channels.nixos.org/$preferredChannel"; then
2929- channel=$preferredChannel
3030- trace "$channel"
3131-else
3232- # Fall back to nixos-unstable, makes sense for fresh release branches
3333- channel=nixos-unstable
3434- trace -e "\e[33mWarning: Preferred channel $preferredChannel could not be fetched, using fallback: $channel\e[0m"
3535-fi
1717+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
36183737-trace -n "Fetching latest version of channel $channel.. "
3838-# This is probably the easiest way to get Nix to output the path to a downloaded channel!
3939-nixpkgs=$(nix-instantiate --find-file nixpkgs -I nixpkgs=channel:"$channel")
4040-trace "$nixpkgs"
4141-4242-# This file only exists in channels
4343-trace -e "Git revision of channel $channel is \e[34m$(<"$nixpkgs/.git-revision")\e[0m"
4444-4545-trace -n "Fetching the prebuilt version of nixpkgs-check-by-name.. "
4646-nix-build -o "$output" "$nixpkgs" -A tests.nixpkgs-check-by-name -j 0 >/dev/null
4747-realpath "$output" >&2
1919+"$SCRIPT_DIR"/fetch-pinned-tool.sh "$output"