Skip to content

Commit 8b63e90

Browse files
committed
Automatically fix flake.nix hashes from dependabot PRs
I recently made this change in our fork of golinks, and thought I'd upstream it. This patch uses Determinate Nix 3.3's feature of being able to automatically fix invalid Nix hashes in CI. More context: https://determinate.systems/posts/changelog-determinate-nix-331/#automatic-hash-mismatches-fixes-in-github-actions Signed-off-by: Graham Christensen <[email protected]>
1 parent 7646755 commit 8b63e90

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

.github/workflows/nix.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,39 @@ on:
1010

1111
jobs:
1212
build:
13+
permissions:
14+
contents: write
1315
runs-on: ubuntu-latest
1416

1517
steps:
1618
- uses: actions/checkout@v3
1719
with:
1820
fetch-depth: 2
1921

20-
- uses: cachix/install-nix-action@v16
22+
- uses: DeterminateSystems/nix-installer-action@main
23+
with:
24+
determinate: true
2125

2226
- name: Run build
2327
run: nix build
28+
29+
- name: Fix hash mismatches
30+
if: failure() && github.event_name == 'pull_request'
31+
id: fix-hashes
32+
run: |
33+
git stash --include-untracked
34+
git fetch --depth=1 origin "$GITHUB_HEAD_REF"
35+
git checkout -B "$GITHUB_HEAD_REF" "${{ github.event.pull_request.head.sha }}"
36+
37+
determinate-nixd fix hashes --auto-apply
38+
39+
if ! git diff --quiet; then
40+
git config user.name "github-actions[bot]"
41+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
42+
git add --update --ignore-removal .
43+
git commit -m "[dependabot skip] Automatically fix Nix hashes"
44+
git push origin "$GITHUB_HEAD_REF"
45+
fi
46+
47+
git checkout -
48+
git stash pop || true

0 commit comments

Comments
 (0)