Skip to content

Commit

Permalink
Merge pull request #2271 from tweag/cb/use-nixpkgs-rev-in-start
Browse files Browse the repository at this point in the history
Use the same nixpkgs revision on CI
  • Loading branch information
mergify[bot] authored Dec 6, 2024
2 parents 8582df6 + afa7cfc commit c6f2162
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
28 changes: 28 additions & 0 deletions rules_haskell_tests/tests/run-start-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@ mkdir $workdir
cd $workdir
cp "$rules_haskell_dir/.bazelversion" .

function getattr_value() {
local nix_file="$rules_haskell_dir/nixpkgs/default.nix"
while IFS=$' \t;' read -r key eq value rest ; do
if [ "$key" == "$1" ] && [ "$eq" == '=' ]; then
value="${value%\"}"
value="${value#\"}"

echo "$value"
return
fi
done < "$nix_file"
echo "could not lookup ${1} in $nix_file" >&2
exit 1
}

function have() {
command -v "$1" &> /dev/null
}

if have nix; then
NIXPKGS_REVISION=$( getattr_value "rev" )
# N.B. the sha256 hash attribute given to `builtins.fetchTarball` is computed after unpacking
# the archive, it is not the hash of the downloaded artifact
#NIXPKGS_HASH=$( nix hash to-sri "$(getattr_value "sha256")" )
fi

export NIXPKGS_REVISION NIXPKGS_HASH

# specify version for bazelisk via `USE_BAZEL_VERSION`, since it does not read the .bazelversion when there is no WORKSPACE file
USE_BAZEL_VERSION=$( cat .bazelversion )
export USE_BAZEL_VERSION
Expand Down
25 changes: 22 additions & 3 deletions start
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set -eu
# we use the default version (currently "9.4.6").
GHC_VERSION=${GHC_VERSION:="9.4.6"}

NIXPKGS_REVISION=${NIXPKGS_REVISION:-nixos-24.05}

readonly MIN_BAZEL_MAJOR=6
readonly MIN_BAZEL_MINOR=0

Expand Down Expand Up @@ -117,13 +119,29 @@ check_files_dont_exist () {
done
}

have () {
command -v "$1" > /dev/null 2>&1
}

check_bazel_version () {
actual_raw=$(bazel version | grep -E '^Build label:' | grep -Eo '[0-9.]+')
if ! have bazel; then
# shellcheck disable=SC2016
stderr 'Warning: cannot find `bazel` executable in $PATH (skipping version check)'
return
fi
if ! actual_raw=$(bazel version | grep -E '^Build label:' | grep -Eo '[0-9.]+'); then
stderr 'Warning: cannot determine bazel version (skipping version check)'
return
fi

# shellcheck disable=SC2034
IFS=. read -r actual_major actual_minor actual_patch <<-EOF
if ! IFS=. read -r actual_major actual_minor actual_patch <<-EOF
${actual_raw}
EOF
then
stderr "Warning: cannot parse version from bazel output (skipping version check)"
return
fi

expected_min="${MIN_BAZEL_MAJOR}.${MIN_BAZEL_MINOR}.0"
expected_max="${MAX_BAZEL_MAJOR}.${MAX_BAZEL_MINOR}.x"
Expand Down Expand Up @@ -328,7 +346,8 @@ EOF
# https://github.com/tweag/rules_nixpkgs/blob/master/README.md
nixpkgs_git_repository(
name = "nixpkgs",
revision = "nixos-24.05",
revision = "${NIXPKGS_REVISION}",${NIXPKGS_HASH:+
integrity = \"$NIXPKGS_HASH\",}
)
nixpkgs_cc_configure(
Expand Down

0 comments on commit c6f2162

Please sign in to comment.