Skip to content

chore(deps): bump nixpkgs from 2c423e0 to 56c02bc (#23125) #86

chore(deps): bump nixpkgs from 2c423e0 to 56c02bc (#23125)

chore(deps): bump nixpkgs from 2c423e0 to 56c02bc (#23125) #86

name: Update Nix Hash
on:
push:
branches:
- master
paths:
- 'flake.lock'
permissions:
contents: write
jobs:
update-hash:
# Only run on the upstream repo, not forks
if: github.repository_owner == 'DIYgod'
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Nix
uses: cachix/install-nix-action@13d8dd58da0234aa297dedd986986ccb8e7f3e24 # v31.11.1
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Cache Nix store
uses: DeterminateSystems/magic-nix-cache-action@908b263ff629f4cc17666315b7fd3ec127c6244d # v14
- name: Update Nix flake hash
id: update-hash
run: |
set -e
# Extract current hash
CURRENT_HASH=$(grep -oP 'hash = "sha256-\K[^"]+' flake.nix || echo "")
echo "Current hash: sha256-$CURRENT_HASH"
# Set temporary invalid hash to trigger error
sed -i 's/hash = "sha256-[^"]*";/hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";/' flake.nix
# Build and capture the correct hash from error message
NEW_HASH=$(nix build .# 2>&1 | grep "got:" | awk '{print $2}' | sed 's/sha256-//' || echo "")
if [ -z "$NEW_HASH" ]; then
echo "Failed to get new hash, hash may already be correct"
git checkout flake.nix
echo "hash_changed=false" >> $GITHUB_OUTPUT
exit 0
fi
# Update with correct hash
sed -i "s#hash = \"sha256-[^\"]*\";#hash = \"sha256-$NEW_HASH\";#" flake.nix
if [ "$CURRENT_HASH" = "$NEW_HASH" ]; then
echo "Hash unchanged"
echo "hash_changed=false" >> $GITHUB_OUTPUT
else
echo "Hash updated from sha256-$CURRENT_HASH to sha256-$NEW_HASH"
echo "hash_changed=true" >> $GITHUB_OUTPUT
echo "new_hash=sha256-$NEW_HASH" >> $GITHUB_OUTPUT
fi
- name: Commit and push if changed
if: steps.update-hash.outputs.hash_changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add flake.nix
git commit -m "chore(nix): update dependencies hash to ${{ steps.update-hash.outputs.new_hash }}"
git push