2022-08-21 12:41:37 +00:00
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# The file that defines the derivation that should be updated
|
|
|
|
file=$1
|
|
|
|
# The name of the output of this flake that should be updated
|
|
|
|
flakeOutput=$2
|
|
|
|
# A pattern in a line preceding the hash that should be updated
|
|
|
|
patternPrecedingHash=$3
|
|
|
|
|
2022-08-16 19:00:00 +00:00
|
|
|
sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"\";|" "$file"
|
2022-08-21 12:41:37 +00:00
|
|
|
# Display stderr and capture it. stdbuf is required to disable output buffering.
|
|
|
|
stderr=$(
|
2022-08-16 19:00:00 +00:00
|
|
|
nix build --no-link -L ".#$flakeOutput" |&
|
2022-08-21 12:41:37 +00:00
|
|
|
stdbuf -oL grep -v '\berror:.*failed to build$' |
|
|
|
|
tee /dev/stderr || :
|
|
|
|
)
|
|
|
|
hash=$(echo "$stderr" | sed -nE 's/.*?\bgot: *?(sha256-.*)/\1/p')
|
|
|
|
if [[ ! $hash ]]; then
|
|
|
|
echo
|
|
|
|
echo "Error: No hash in build output."
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-08-16 19:00:00 +00:00
|
|
|
sed -i "/$patternPrecedingHash/,/hash/ s|hash = .*|hash = \"$hash\";|" "$file"
|
2022-08-21 12:41:37 +00:00
|
|
|
echo "(Note: The above hash mismatch message is not an error. It is part of the fetching process.)"
|