#!/usr/bin/env bash RELEASE=25.05 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 # 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") # 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) if [ "${old}" == "${new}" ]; then return fi replace_hash "${flake_input_name}" "${new}" 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 "nixos-unstable" "nixos-unstable") if [ -z "$new_hash" ]; then return fi echo "Updated unstable to: ${new_hash}" } update_stable update_unstable