Skip to content

Commit c6f2162

Browse files
authored
Merge pull request #2271 from tweag/cb/use-nixpkgs-rev-in-start
Use the same nixpkgs revision on CI
2 parents 8582df6 + afa7cfc commit c6f2162

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

rules_haskell_tests/tests/run-start-script.sh

+28
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ mkdir $workdir
1515
cd $workdir
1616
cp "$rules_haskell_dir/.bazelversion" .
1717

18+
function getattr_value() {
19+
local nix_file="$rules_haskell_dir/nixpkgs/default.nix"
20+
while IFS=$' \t;' read -r key eq value rest ; do
21+
if [ "$key" == "$1" ] && [ "$eq" == '=' ]; then
22+
value="${value%\"}"
23+
value="${value#\"}"
24+
25+
echo "$value"
26+
return
27+
fi
28+
done < "$nix_file"
29+
echo "could not lookup ${1} in $nix_file" >&2
30+
exit 1
31+
}
32+
33+
function have() {
34+
command -v "$1" &> /dev/null
35+
}
36+
37+
if have nix; then
38+
NIXPKGS_REVISION=$( getattr_value "rev" )
39+
# N.B. the sha256 hash attribute given to `builtins.fetchTarball` is computed after unpacking
40+
# the archive, it is not the hash of the downloaded artifact
41+
#NIXPKGS_HASH=$( nix hash to-sri "$(getattr_value "sha256")" )
42+
fi
43+
44+
export NIXPKGS_REVISION NIXPKGS_HASH
45+
1846
# specify version for bazelisk via `USE_BAZEL_VERSION`, since it does not read the .bazelversion when there is no WORKSPACE file
1947
USE_BAZEL_VERSION=$( cat .bazelversion )
2048
export USE_BAZEL_VERSION

start

+22-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ set -eu
99
# we use the default version (currently "9.4.6").
1010
GHC_VERSION=${GHC_VERSION:="9.4.6"}
1111

12+
NIXPKGS_REVISION=${NIXPKGS_REVISION:-nixos-24.05}
13+
1214
readonly MIN_BAZEL_MAJOR=6
1315
readonly MIN_BAZEL_MINOR=0
1416

@@ -117,13 +119,29 @@ check_files_dont_exist () {
117119
done
118120
}
119121

122+
have () {
123+
command -v "$1" > /dev/null 2>&1
124+
}
125+
120126
check_bazel_version () {
121-
actual_raw=$(bazel version | grep -E '^Build label:' | grep -Eo '[0-9.]+')
127+
if ! have bazel; then
128+
# shellcheck disable=SC2016
129+
stderr 'Warning: cannot find `bazel` executable in $PATH (skipping version check)'
130+
return
131+
fi
132+
if ! actual_raw=$(bazel version | grep -E '^Build label:' | grep -Eo '[0-9.]+'); then
133+
stderr 'Warning: cannot determine bazel version (skipping version check)'
134+
return
135+
fi
122136

123137
# shellcheck disable=SC2034
124-
IFS=. read -r actual_major actual_minor actual_patch <<-EOF
138+
if ! IFS=. read -r actual_major actual_minor actual_patch <<-EOF
125139
${actual_raw}
126140
EOF
141+
then
142+
stderr "Warning: cannot parse version from bazel output (skipping version check)"
143+
return
144+
fi
127145

128146
expected_min="${MIN_BAZEL_MAJOR}.${MIN_BAZEL_MINOR}.0"
129147
expected_max="${MAX_BAZEL_MAJOR}.${MAX_BAZEL_MINOR}.x"
@@ -328,7 +346,8 @@ EOF
328346
# https://github.com/tweag/rules_nixpkgs/blob/master/README.md
329347
nixpkgs_git_repository(
330348
name = "nixpkgs",
331-
revision = "nixos-24.05",
349+
revision = "${NIXPKGS_REVISION}",${NIXPKGS_HASH:+
350+
integrity = \"$NIXPKGS_HASH\",}
332351
)
333352
334353
nixpkgs_cc_configure(

0 commit comments

Comments
 (0)