Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 50 lines 2.0 kB view raw
1#!/usr/bin/env nix-shell 2#!nix-shell -i bash -p nix jq common-updater-scripts 3 4set -euo pipefail 5 6nixpkgs="$(git rev-parse --show-toplevel || (printf 'Could not find root of nixpkgs repo\nAre we running from within the nixpkgs git repo?\n' >&2; exit 1))" 7 8stripwhitespace() { 9 sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' 10} 11 12nixeval() { 13 nix --extra-experimental-features nix-command eval --json --impure -f "$nixpkgs" "$1" | jq -r . 14} 15 16vendorhash() { 17 (nix --extra-experimental-features nix-command build --impure --argstr nixpkgs "$nixpkgs" --argstr attr "$1" --expr '{ nixpkgs, attr }: let pkgs = import nixpkgs {}; in with pkgs.lib; (getAttrFromPath (splitString "." attr) pkgs).overrideAttrs (attrs: { outputHash = fakeHash; })' --no-link 2>&1 >/dev/null | tail -n3 | grep -F got: | cut -d: -f2- | stripwhitespace) 2>/dev/null || true 18} 19 20findpath() { 21 path="$(nix --extra-experimental-features nix-command eval --json --impure -f "$nixpkgs" "$1.meta.position" | jq -r . | cut -d: -f1)" 22 outpath="$(nix --extra-experimental-features nix-command eval --json --impure --expr "builtins.fetchGit \"$nixpkgs\"")" 23 24 if [ -n "$outpath" ]; then 25 path="${path/$(echo "$outpath" | jq -r .)/$nixpkgs}" 26 fi 27 28 echo "$path" 29} 30 31attr="${UPDATE_NIX_ATTR_PATH:-sonic-pi}" 32version="$(cd "$nixpkgs" && list-git-tags --pname="$(nixeval "$attr".pname)" --attr-path="$attr" | grep '^v' | sed -e 's|^v||' | sort -V | tail -n1)" 33 34pkgpath="$(findpath "$attr")" 35 36updated="$(cd "$nixpkgs" && update-source-version "$attr" "$version" --file="$pkgpath" --print-changes | jq -r length)" 37 38if [ "$updated" -eq 0 ]; then 39 echo 'update.sh: Package version not updated, nothing to do.' 40 exit 0 41fi 42 43curhash="$(nixeval "$attr.mixFodDeps.outputHash")" 44newhash="$(vendorhash "$attr.mixFodDeps")" 45 46if [ -n "$newhash" ] && [ "$curhash" != "$newhash" ]; then 47 sed -i -e "s|\"$curhash\"|\"$newhash\"|" "$pkgpath" 48else 49 echo 'update.sh: New vendorHash same as old vendorHash, nothing to do.' 50fi