refactor(update_cached_hashes.sh): modularize and update hash handling
This commit is contained in:
parent
c47c8a42ee
commit
63a6642f8c
@ -1,22 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# this guy updates the hash of the last
|
||||
# successful build of nixpkgs on hydra
|
||||
# (so we don't have to rebuild EVERYTHING)
|
||||
RELEASE=24.11
|
||||
|
||||
set -e
|
||||
update_channel() {
|
||||
local channel_name="$1" # Hydra channel name (e.g., nixos-24.11)
|
||||
local flake_input_name="$2" # Flake input name (e.g., nixpkgs)
|
||||
local new old
|
||||
|
||||
new=$(curl -sL "https://monitoring.nixos.org/prometheus/api/v1/query?query=channel_revision" | jq -r ".data.result[] | select(.metric.channel==\"nixos-${RELEASE}\") | .metric.revision")
|
||||
old=$(jq -r '.nodes as $nodes | .nodes.root.inputs.nixpkgs as $tgt_nixpkgs | $nodes | to_entries[] | select(.key == $tgt_nixpkgs) | .value.locked.rev' flake.lock)
|
||||
# Get latest revision from Hydra
|
||||
new=$(curl -sL "https://monitoring.nixos.org/prometheus/api/v1/query?query=channel_revision" |
|
||||
jq -r ".data.result[] | select(.metric.channel==\"${channel_name}\") | .metric.revision")
|
||||
|
||||
if [ "${old}" != "${new}" ]; then
|
||||
echo "Old hash: ${old}"
|
||||
echo "New hash: ${new}"
|
||||
# Get current revision from flake.lock using input name
|
||||
old=$(jq -r ".nodes as \$nodes |
|
||||
.nodes.root.inputs.[\"${flake_input_name}\"] as \$target_input |
|
||||
\$nodes | to_entries[] |
|
||||
select(.key == \$target_input) |
|
||||
.value.locked.rev" flake.lock)
|
||||
|
||||
sed -i s/"${old}"/"${new}"/ flake.nix
|
||||
if [ "${old}" == "${new}" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
exit
|
||||
fi
|
||||
replace_hash "${flake_input_name}" "${new}"
|
||||
|
||||
echo "No updates available."
|
||||
echo "${new}"
|
||||
}
|
||||
|
||||
replace_hash() {
|
||||
local name="$1" hash="$2"
|
||||
|
||||
sed -i "s|\(${name}\.url = \"github:NixOS/nixpkgs/\)[^\"]*|\1${hash}|" flake.nix
|
||||
# sed -i "s|${name}/${old}|${name}/${new}|" flake.nix
|
||||
}
|
||||
|
||||
update_stable() {
|
||||
echo "Checking NixOS ${RELEASE}..."
|
||||
|
||||
new_hash=$(update_channel "nixos-${RELEASE}" "nixpkgs")
|
||||
|
||||
if [ -z "$new_hash" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Updated stable to: ${new_hash}"
|
||||
}
|
||||
|
||||
update_unstable() {
|
||||
echo "Checking unstable..."
|
||||
|
||||
new_hash=$(update_channel "nixpkgs-unstable" "nixpkgs-unstable")
|
||||
|
||||
if [ -z "$new_hash" ]; then
|
||||
return
|
||||
fi
|
||||
|
||||
echo "Updated unstable to: ${new_hash}"
|
||||
}
|
||||
|
||||
update_stable
|
||||
update_unstable
|
||||
|
Loading…
x
Reference in New Issue
Block a user