nixpkgs/pkgs/test/nixpkgs-check-by-name/scripts/update-pinned-tool.sh
Silvan Mosberger 142922295d check-by-name: Don't use -I in shebang
Original commit from https://github.com/NixOS/nixpkgs/pull/282226,
message:

Running CI locally is broken becauses the `-I` argument:

- Clobbers $NIX_PATH
- Is wrong for two reasons:
  - Has too many `..` elements, relative to the script's location
  - Isn't relative to the script's location (as with *.nix files),
    since shell scripts and POSIX in general interpret paths
    relative to the current working directory, not the canonical
    path of argv[0]
- Is inconsistent, since this script has symlinks pointing at it
  from different depths in the repository

There is no way to set this flag statically in a way that will work
everywhere.  The caller needs to use $NIX_PATH, or the script needs
to take the `-I` value as an argument.

This commit deletes the static `-I` flag.
2024-01-29 13:39:26 +01:00

41 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p jq
set -o pipefail -o errexit -o nounset
trace() { echo >&2 "$@"; }
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
# Determined by `runs-on: ubuntu-latest` in .github/workflows/check-by-name.yml
CI_SYSTEM=x86_64-linux
channel=nixos-unstable
pin_file=$SCRIPT_DIR/pinned-tool.json
trace -n "Fetching latest version of channel $channel.. "
# This is probably the easiest way to get Nix to output the path to a downloaded channel!
nixpkgs=$(nix-instantiate --find-file nixpkgs -I nixpkgs=channel:"$channel")
trace "$nixpkgs"
# This file only exists in channels
rev=$(<"$nixpkgs/.git-revision")
trace -e "Git revision of channel $channel is \e[34m$rev\e[0m"
trace -n "Fetching the prebuilt version of nixpkgs-check-by-name for $CI_SYSTEM.. "
# This is the architecture used by CI, we want to prefetch the exact path to avoid having to evaluate Nixpkgs
ci_path=$(nix-build --no-out-link "$nixpkgs" \
-A tests.nixpkgs-check-by-name \
--arg config '{}' \
--argstr system "$CI_SYSTEM" \
--arg overlays '[]' \
-j 0 \
| tee /dev/stderr)
trace "Updating $pin_file"
jq -n \
--arg rev "$rev" \
--arg ci-path "$ci_path" \
'$ARGS.named' \
> "$pin_file"