Skip to content

Instantly share code, notes, and snippets.

@steshaw
Forked from simonmichael/a.bash
Last active December 4, 2019 13:44
Show Gist options
  • Save steshaw/d658fef0d85954df35d1ef97ff6fce5c to your computer and use it in GitHub Desktop.
Save steshaw/d658fef0d85954df35d1ef97ff6fce5c to your computer and use it in GitHub Desktop.
scripts for finding available versions in nixpkgs
#!/usr/bin/env bash
set -euo pipefail
#
# Some nixpkgs query scripts inspired by #nixos chat.
# Goal: find the HASH that will let an install command like:
# nix-env -i -f https://github.com/NixOS/nixpkgs/archive/HASH.tar.gz -A hledger hledger-web hledger-ui
# install the latest available build of the packages, on all platforms of interest.
# These scripts don't seem to quite do that but they help.
# #
NIXARCHS="darwin linux"
HLEDGERPKGS=$(nix-env --query | perl -pe 's/-[0-9].*$//')
# show help for the following commands
nix-latest-help() {
grep -E '^# nix-latest' ~/.bashrc.local # <- this file
}
# show nixpkgs latest successful build id on the given architecture for PKG
# nix-latest-build-on (linux|darwin) PKG
nix-latest-build-on() {
curl -sLH "accept: application/json" https://hydra.nixos.org/job/nixpkgs/trunk/"$2".x86_64-"$1"/latest | jq .id
}
# show nixpkgs latest successful build ids on all architectures for PKG
# nix-latest-build PKG
nix-latest-builds() {
for ARCH in $NIXARCHS; do
printf "latest build of %-11s on %-6s: $(nix-latest-build-on $ARCH $1)\n" $1 $ARCH
done
}
# show nixpkgs latest successful build ids on all architectures for the main hledger packages
# nix-latest-builds-hledger
nix-latest-builds-hledger() {
for PKG in $HLEDGERPKGS; do
nix-latest-builds $PKG
done
}
# show nixpkgs latest successful build urls on all architectures for PKG
# nix-latest-build-url PKG
nix-latest-build-urls() {
for ARCH in $NIXARCHS; do
printf "latest build of %-11s on %-6s: https://hydra.nixos.org/build/$(nix-latest-build-on $ARCH $1)\n" $1 $ARCH
done
}
# show nixpkgs latest successful build ids on all architectures for the main hledger packages
# nix-latest-build-urls-hledger
nix-latest-build-urls-hledger() {
for PKG in $HLEDGERPKGS; do
nix-latest-build-urls $PKG
done
}
# nix-hash-from-build: BUILD
nix-hash-from-build() {
build=$1
curl -sL https://hydra.nixos.org/build/$build |
pup 'div#tabs-buildinputs tbody tr:nth-child(1) td:nth-child(4) text{}'
}
# show nixpkgs github archive hash for latest successful build on the given architecture of PKG
# nix-latest-archive-on (linux|darwin) PKG
nix-latest-archive-on() {
BUILD=$(nix-latest-build-on $1 $2)
nix-hash-from-build $BUILD
}
# show nixpkgs github archive hashes for the latest successful builds on all architectures of PKG
# nix-latest-archives PKG
nix-latest-archives() {
for ARCH in $NIXARCHS; do
printf "latest archive containing %-11s on %-6s: $(nix-latest-archive-on $ARCH $1)\n" $1 $ARCH
done
}
# show nixpkgs github archive hashes for the latest successful builds on all architectures of the main hledger packages
# nix-latest-archives-hledger
nix-latest-archives-hledger() {
for PKG in $HLEDGERPKGS; do
nix-latest-archives $PKG
done
}
#
# evaluations containing a build: https://hydra.nixos.org/build/99757008/evals
# hledger jobs within an evaluation:
# https://hydra.nixos.org/eval/EVAL?filter=hledger&compare=PREVEVAL
# succeeded: https://hydra.nixos.org/eval/1540383?filter=hledger&compare=1540357
# queued: https://hydra.nixos.org/eval/1540383?filter=hledger&compare=1540357&full=#tabs-unfinished
# archive rev: https://hydra.nixos.org/eval/1540383?filter=hledger&compare=1540357&full=#tabs-inputs -> Revision
#
nix-latest-archives-hledger
exit
BUILD=107785925
curl -sL https://hydra.nixos.org/build/$BUILD | grep -E '<td>........................................</td>' | cut -c 15-20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment