Skip to content

ci(nix): automate npmDeps hash and verify Nix builds on release tags#235

Merged
matheusfillipe merged 7 commits into
obbyworld:mainfrom
unle4rn:main
May 24, 2026
Merged

ci(nix): automate npmDeps hash and verify Nix builds on release tags#235
matheusfillipe merged 7 commits into
obbyworld:mainfrom
unle4rn:main

Conversation

@unle4rn
Copy link
Copy Markdown
Contributor

@unle4rn unle4rn commented May 19, 2026

Summary

  • Add nix run .#update-npm-deps-hash to recompute fetchNpmDeps from package-lock.json and patch nix/obsidianirc.nix
  • Add a lefthook pre-commit hook (runs when Nix is installed) so lockfile changes fix the hash before push
  • Remove the nix-linux job from daily CI — Dependabot PRs no longer need to pass a 60-minute Nix build
  • Add publish-nix to the release workflow: on version tags, verify the Nix package builds and commit any hash fix back to main

Motivation

When package-lock.json changes (weekly Dependabot updates, new features, etc.), the npmDeps hash in nix/obsidianirc.nix must stay in sync or Nix builds fail. That was easy to miss and blocked CI.

This follows the approach discussed with @mattf:

  • Fix before push locally via lefthook (optional if Nix is installed)
  • Don't gate every push/PR on Nix — too slow for a young node project with frequent dep changes
  • Sync at release time — tag pushes verify the Nix package and push hash fixes to main with [skip ci]

Changes

Area What
nix/update-npm-deps-hash.nix Flake app using prefetch-npm-deps + sed
flake.nix Expose packages.update-npm-deps-hash
lefthook.yml npm-deps-hash command on staged package-lock.json changes
.github/workflows/workflow.yaml Remove nix-linux job
.github/workflows/publish.yaml New publish-nix job (if: github.ref_type == 'tag')
AGENTS.md, BUILD.md Updated maintenance docs

Test plan

  • nix flake check
  • nix build .#obsidianirc (~3.4 min, passes)
  • nix run .#update-npm-deps-hash (idempotent on current lockfile)
  • Lefthook npm-deps-hash with stale hash → fixes, stages, aborts commit
  • statix / deadnix / nixfmt on Nix files
  • actionlint on workflows (syntax clean)
  • npm run format / fix:unsafe / test / build
  • After merge: confirm next version tag runs publish-nix and syncs hash to main if needed

Notes

  • Devs without Nix can still commit lockfile changes; hash sync happens at the next tag release (or they ask someone with Nix to run nix run .#update-npm-deps-hash)
  • publish-nix runs in parallel with Tauri release builds, not in the lint/test workflow

Summary by CodeRabbit

  • Chores

    • Reorganized CI/CD pipeline—moved Nix package verification to tag-triggered release builds.
    • Automated NPM dependency hash synchronization during version releases.
  • Documentation

    • Updated build maintenance instructions to reflect changes in dependency handling workflow.

Review Change Stack

Add nix run .#update-npm-deps-hash plus a lefthook hook for local lockfile
changes, drop the daily nix-linux CI job, and sync the hash from publish-nix
when version tags are pushed so Dependabot PRs are not blocked by Nix.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

📝 Walkthrough

Walkthrough

This PR automates npm dependencies hash synchronization in the Nix build system. A new shell utility script recalculates hashes from package-lock.json and updates nix/obsidianirc.nix. The utility is exposed as a flake package, called by a new GitHub Actions job on version tag releases to verify and commit hash updates to main. The previous nix-linux workflow job is removed. Documentation is updated to reflect the new workflow.

Changes

NPM Hash Synchronization Automation

Layer / File(s) Summary
NPM hash update utility script
nix/update-npm-deps-hash.nix
Creates a shell application that recalculates the npm dependencies hash from package-lock.json using prefetch-npm-deps and updates nix/obsidianirc.nix in-place via sed.
Flake package exposure
flake.nix
Adds update-npm-deps-hash as a callable Nix package output alongside the existing obsidianirc package.
GitHub Actions CI job updates
.github/workflows/publish.yaml, .github/workflows/workflow.yaml
Introduces a new tag-triggered update-linux-nix job that runs the hash utility and commits changes to main. Removes the redundant nix-linux job from the standard workflow.
Developer documentation updates
AGENTS.md, BUILD.md
Updates build instructions to document the automated hash synchronization workflow triggered by package-lock.json changes and release tag builds.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A script to sync those hashes clean,
From package-lock's npm scene,
On tags it flows to main with care,
No manual bumps—automation's fair!
One job removed, one workflow gained,
Our Nix builds now perfectly ordained. 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main changes: automating npmDeps hash updates and verifying Nix builds on release tags, which aligns with the core objectives and all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/publish.yaml:
- Around line 105-116: The "Commit npmDeps hash to main" step can fail to
checkout main if the workspace is dirty (e.g., nix/obsidianirc.nix modified by
the prior "Verify tagged release builds" step); update the step to detect and
preserve local changes by stashing before switching branches and restoring
afterward (use git stash --include-untracked before git fetch/checkout/pull and
git stash pop after the sync) or, alternatively, reset only the generated file
(e.g., git checkout -- nix/obsidianirc.nix) before checkout; modify the script
in the "Commit npmDeps hash to main" run block to perform the stash/reset/pop
around git fetch/checkout/pull to avoid checkout failures.
- Around line 95-100: The workflow uses mutable action tags (actions/checkout@v6
and cachix/install-nix-action@v31) which must be pinned to immutable
40-character commit SHAs; update those two occurrences (and any other actions in
the same file) to their corresponding full commit SHAs (e.g.,
actions/checkout@<40-char-sha>, cachix/install-nix-action@<40-char-sha>) so the
workflow references exact commits for reproducibility and security.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a77d2d9c-1a9d-4941-a18a-af17114e8ffa

📥 Commits

Reviewing files that changed from the base of the PR and between 2257f1c and eada88f.

📒 Files selected for processing (7)
  • .github/workflows/publish.yaml
  • .github/workflows/workflow.yaml
  • AGENTS.md
  • BUILD.md
  • flake.nix
  • lefthook.yml
  • nix/update-npm-deps-hash.nix
💤 Files with no reviewable changes (1)
  • .github/workflows/workflow.yaml

Comment on lines +95 to +100
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Install Nix
uses: cachix/install-nix-action@v31
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot May 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify unpinned action references in this workflow.
rg -nP '^\s*uses:\s*[^@]+@(?!(?:[a-f0-9]{40})$).+' .github/workflows/publish.yaml

Repository: ObsidianIRC/ObsidianIRC

Length of output: 1549


Pin all GitHub Actions to full commit SHAs.

Lines 95 and 100 use mutable tags (@v6, @v31), which presents a supply-chain security risk. This pattern appears across the entire workflow. Replace version tags with 40-character commit SHAs to ensure build reproducibility and prevent unexpected action updates.

Example pinning pattern
-      - name: Checkout tag
-        uses: actions/checkout@v6
+      - name: Checkout tag
+        uses: actions/checkout@<40-char-commit-sha> # v6

-      - name: Install Nix
-        uses: cachix/install-nix-action@v31
+      - name: Install Nix
+        uses: cachix/install-nix-action@<40-char-commit-sha> # v31
🧰 Tools
🪛 zizmor (1.25.2)

[error] 95-95: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)


[error] 100-100: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/publish.yaml around lines 95 - 100, The workflow uses
mutable action tags (actions/checkout@v6 and cachix/install-nix-action@v31)
which must be pinned to immutable 40-character commit SHAs; update those two
occurrences (and any other actions in the same file) to their corresponding full
commit SHAs (e.g., actions/checkout@<40-char-sha>,
cachix/install-nix-action@<40-char-sha>) so the workflow references exact
commits for reproducibility and security.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will hold off on this and let dependabot handle it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unle4rn, understood! Dependabot is a perfectly reasonable way to manage this — just make sure your Dependabot config covers the github-actions ecosystem so it picks up these actions automatically. No further action needed from me here.

(∪・ω・∪)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same argument can be used for any shared workflow we already have @ValwareIRC

Again, the only way is to copy the source and checksum to a usb stick and go to an offline machine in the woods at night to compile this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah maybe pinning all to hashes isnt a bad idea

Copy link
Copy Markdown
Contributor

@matheusfillipe matheusfillipe May 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of scope for this PR anyway (dependabot needs to manage this)

Comment thread .github/workflows/publish.yaml Outdated
unle4rn added 3 commits May 19, 2026 13:38
The job verifies the Nix build and syncs npmDeps hash to main; it does not
upload release assets like the other publish-* jobs.
The verify step can patch npmDeps in the working tree; discard that change
before checkout so git switch to main does not fail on a dirty file.
Match publish-linux-arm job id style and drop a custom display name so the
check list uses the same job-id format as the other publish workflow jobs.
Comment thread .github/workflows/publish.yaml Outdated
Comment thread lefthook.yml Outdated
unle4rn added 2 commits May 19, 2026 14:17
Nobody runs Nix locally; verify-linux-nix on version tags syncs the hash
to main. Keep nix run .#update-npm-deps-hash for optional manual use.
The job verifies the tagged Nix build and commits npmDeps hash fixes to
main, not verify-only.
Comment thread .github/workflows/publish.yaml Outdated
Comment on lines +104 to +107
- name: Verify tagged release builds
run: |
nix run .#update-npm-deps-hash
nix flake check && nix build .#obsidianirc --no-link --print-build-logs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need this step? the step bellow is doing it again

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like so? a6b6b21

The commit-to-main step already prefetches the hash and runs nix build on
main; building at the tag first duplicated that work (PR obbyworld#235 review).
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.github/workflows/publish.yaml (1)

114-120: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Build verification is skipped when the npmDeps hash hasn't changed.

The early exit at lines 114-117 prevents the Nix build verification at line 119 from running unless nix/obsidianirc.nix was modified. In a release workflow, the build should be verified on every release regardless of whether dependencies changed.

Reorder the build verification before the hash change check to ensure every release-tag run confirms the build works:

Suggested fix
-          if git diff --exit-code --quiet -- nix/obsidianirc.nix; then
-            echo "npmDeps hash on main is already up to date."
-            exit 0
-          fi
-
-          nix flake check && nix build .#obsidianirc --no-link --print-build-logs
+          nix flake check && nix build .#obsidianirc --no-link --print-build-logs
+
+          if git diff --exit-code --quiet -- nix/obsidianirc.nix; then
+            echo "npmDeps hash on main is already up to date."
+            exit 0
+          fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/publish.yaml around lines 114 - 120, The current early
exit (the if git diff --exit-code --quiet -- nix/obsidianirc.nix; then echo ...;
exit 0) skips the subsequent build verification; move the build verification
command (nix flake check && nix build .#obsidianirc --no-link
--print-build-logs) to run before that git-diff/hash check so the Nix build is
always verified on release runs, then keep the git diff check afterwards to
still allow an early exit when the npmDeps hash truly hasn't changed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In @.github/workflows/publish.yaml:
- Around line 114-120: The current early exit (the if git diff --exit-code
--quiet -- nix/obsidianirc.nix; then echo ...; exit 0) skips the subsequent
build verification; move the build verification command (nix flake check && nix
build .#obsidianirc --no-link --print-build-logs) to run before that
git-diff/hash check so the Nix build is always verified on release runs, then
keep the git diff check afterwards to still allow an early exit when the npmDeps
hash truly hasn't changed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c652fa76-41f7-4a00-afd8-c5c72768840c

📥 Commits

Reviewing files that changed from the base of the PR and between eada88f and a6b6b21.

📒 Files selected for processing (3)
  • .github/workflows/publish.yaml
  • AGENTS.md
  • BUILD.md

@matheusfillipe matheusfillipe merged commit f1a3dee into obbyworld:main May 24, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants