Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 47 lines 2.0 kB view raw
1#! /usr/bin/env nix-shell 2#! nix-shell -i bash -p coreutils gnused curl jq 3set -euo pipefail 4cd "$(dirname "${BASH_SOURCE[0]}")" 5 6DRV_DIR="$PWD" 7 8OLD_VERSION="$(sed -nE 's/\s*version = "(.*)".*/\1/p' ./default.nix)" 9 10NEW_VERSION="$(curl https://api.github.com/repos/p7zip-project/p7zip/releases/latest | jq .tag_name -r | tr -d 'v')" 11 12echo "comparing versions $OLD_VERSION => $NEW_VERSION" 13if [[ "$OLD_VERSION" == "$NEW_VERSION" ]]; then 14 echo "Already up to date! Doing nothing" 15 exit 0 16fi 17 18NIXPKGS_ROOT="$(realpath "$DRV_DIR/../../../..")" 19 20echo "getting free source hash" 21OLD_FREE_HASH="$(nix-instantiate --eval --strict -E "with import $NIXPKGS_ROOT {}; p7zip.src.drvAttrs.outputHash" | tr -d '"')" 22echo "getting unfree source hash" 23OLD_UNFREE_HASH="$(nix-instantiate --eval --strict -E "with import $NIXPKGS_ROOT {}; (p7zip.override { enableUnfree = true; }).src.drvAttrs.outputHash" | tr -d '"')" 24 25 26NEW_FREE_HASH=$(nix-prefetch -f "$NIXPKGS_ROOT" -E "p7zip.src" --rev "v$NEW_VERSION") 27 28NEW_UNFREE_OUT=$(nix-prefetch -f "$NIXPKGS_ROOT" -E "(p7zip.override { enableUnfree = true; }).src" --rev "v$NEW_VERSION" --output raw --print-path) 29# first line of raw output is the hash 30NEW_UNFREE_HASH="$(echo "$NEW_UNFREE_OUT" | sed -n 1p)" 31# second line of raw output is the src path 32NEW_UNFREE_SRC="$(echo "$NEW_UNFREE_OUT" | sed -n 2p)" 33# make sure to nuke the unfree src from the updater's machine 34# > the license requires that you agree to these use restrictions, or you must remove the software (source and binary) from your hard disks 35# https://fedoraproject.org/wiki/Licensing:Unrar 36nix-store --delete "$NEW_UNFREE_SRC" 37 38 39echo "updating version" 40sed -i "s/version = \"$OLD_VERSION\";/version = \"$NEW_VERSION\";/" "$DRV_DIR/default.nix" 41 42echo "updating free hash" 43sed -i "s@free = \"$OLD_FREE_HASH\";@free = \"$NEW_FREE_HASH\";@" "$DRV_DIR/default.nix" 44echo "updating unfree hash" 45sed -i "s@unfree = \"$OLD_UNFREE_HASH\";@unfree = \"$NEW_UNFREE_HASH\";@" "$DRV_DIR/default.nix" 46 47echo "done"