add src url fixer; tail of nix build failures

This commit is contained in:
Ryan Mulligan 2018-03-29 06:39:34 -07:00
parent 6de0466d29
commit 08de2bff36
2 changed files with 62 additions and 4 deletions

54
fix-src-url.sh Executable file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GITHUB_TOKEN="$(cat "$SCRIPT_DIR"/github_token.txt)"
export GITHUB_TOKEN
# shellcheck source=setup-nixpkgs.sh
source "$SCRIPT_DIR/setup-nixpkgs.sh"
PACKAGE_NAME=$1
OLD_VERSION=$2
NEW_VERSION=$3
DERIVATION_FILE=$4
ATTR_PATH=$5
OLD_SRC_URL=$6
DOWNLOADS=$(curl "https://repology.org/api/v1/metapackage/$PACKAGE_NAME" | jq '.[].downloads | select(values) | .[] ' | grep "$NEW_VERSION" | sed 's|"||g')
# if [ -z "$DOWNLOADS" ]
# then
# exit 1
# fi
OLD_DERIVATION_NAME=$(nix eval -f ~/p/nixpkgs --raw "pkgs.$ATTR_PATH.name")
NEW_DERIVATION_NAME=$(sed "s|$OLD_VERSION|$NEW_VERSION|" <<< "$OLD_DERIVATION_NAME")
NAME=$(nix eval --raw "(let pkgs = import ./. {}; in (builtins.parseDrvName pkgs.$ATTR_PATH.name).name)")
if grep -q "name = \"$NEW_DERIVATION_NAME\"" "$DERIVATION_FILE"
then
# Separate name and version
sed -i "s|$NEW_DERIVATION_NAME|$NAME-\${version}|" "$DERIVATION_FILE"
grep -q "name = \"$NAME-\${version}\"" "$DERIVATION_FILE"
# shellcheck disable=SC2016
sed -i 's|^\([ ]*\)\(name = "'"$NAME"'-\${version}";\)|\1\2\n\1version = "'"$NEW_VERSION"'";|' "$DERIVATION_FILE"
grep -q "version = \"$NEW_VERSION\";" "$DERIVATION_FILE"
fi
for d in $DOWNLOADS
do
OLD_URL="$OLD_SRC_URL"
OLD_URL=$(sed "s|$OLD_DERIVATION_NAME|\${name}|" <<< "$OLD_URL")
OLD_URL=$(sed "s|$OLD_VERSION|\${version}|" <<< "$OLD_URL")
NEW_URL=$(sed "s|$NEW_DERIVATION_NAME|\${name}|" <<< "$d" | sed "s|$NEW_VERSION|\${version}|")
sed -i "s|$OLD_URL|$NEW_URL|" "$DERIVATION_FILE"
grep -q 'url = "'"$NEW_URL"'";' "$DERIVATION_FILE" || continue
nix-prefetch-url -A "$ATTR_PATH.src" && exit 0
done
exit 1

12
up.sh
View File

@ -160,18 +160,21 @@ git checkout "$(git merge-base upstream/master upstream/staging)"
git checkout -B "$BRANCH_NAME"
OLD_HASH=$(nix eval -f . --raw "pkgs.$ATTR_PATH.src.drvAttrs.outputHash" || error_exit "Couldn't find old output hash at ATTR_PATH.src.drvAttrs.outputHash.")
OLD_SRC_URL=$(nix eval -f . '(let pkgs = import ./. {}; in builtins.elemAt pkgs.'"$ATTR_PATH"'.src.drvAttrs.urls 0)')
OLD_SRC_URL=$(nix eval -f . --raw '(let pkgs = import ./. {}; in builtins.elemAt pkgs.'"$ATTR_PATH"'.src.drvAttrs.urls 0)')
sed -i "s/${OLD_VERSION//\./\\.}/$NEW_VERSION/g" "$DERIVATION_FILE" || error_exit "Could not replace OLD_VERSION with NEW_VERSION."
NEW_SRC_URL=$(nix eval -f . '(let pkgs = import ./. {}; in builtins.elemAt pkgs.'"$ATTR_PATH"'.src.drvAttrs.urls 0)')
NEW_SRC_URL=$(nix eval -f . --raw '(let pkgs = import ./. {}; in builtins.elemAt pkgs.'"$ATTR_PATH"'.src.drvAttrs.urls 0)')
if [ "$OLD_SRC_URL" == "$NEW_SRC_URL" ]
then
error_exit "Source url did not change."
fi
NEW_HASH=$(nix-prefetch-url -A "$ATTR_PATH.src" || error_exit "Could not prefetch new version URL.")
NEW_HASH=$(
nix-prefetch-url -A "$ATTR_PATH.src" || \
"$SCRIPT_DIR"/fix-src-url.sh "$PACKAGE_NAME" "$OLD_VERSION" "$NEW_VERSION" "$DERIVATION_FILE" "$ATTR_PATH" "$OLD_SRC_URL" || \
error_exit "Could not prefetch new version URL.")
if [ "$OLD_HASH" = "$NEW_HASH" ]
then
@ -182,7 +185,8 @@ sed -i "s/$OLD_HASH/$NEW_HASH/g" "$DERIVATION_FILE" || error_exit "Could not rep
rm -f result*
nix build -f . "$ATTR_PATH" || error_exit "nix build failed."
nix build -f . "$ATTR_PATH" || error_exit "nix build failed.
$(nix log -f . "$ATTR_PATH" | tail -n 30)"
RESULT=$(readlink ./result || readlink ./result-bin || error_exit "Couldn't find result link.")