Skip to content

feat: package moshi-hook as Nix overlay - #2147

Merged
shunkakinoki merged 3 commits into
mainfrom
worktree/green-stone-7e33
Aug 2, 2026
Merged

feat: package moshi-hook as Nix overlay#2147
shunkakinoki merged 3 commits into
mainfrom
worktree/green-stone-7e33

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add moshi-hook v0.2.55 as a Nix overlay (static Go binary from cdn.getmoshi.app) with SHA256 checksums for all 4 platforms
  • Add moshi-hook to Linux home-manager packages
  • Update systemd service to use Nix store path instead of hardcoded ~/.local/bin

Test plan

  • nix eval succeeds for matic NixOS configuration
  • Package builds and produces working binary (moshi-hook version 0.2.55)
  • moshi symlink created in $out/bin
  • nixos-rebuild switch on matic
  • systemctl --user status moshi-hook shows active

Summary by cubic

Package moshi-hook v0.2.69 as a Nix overlay, integrate it into the Linux home profile, and add an automated upgrader. The systemd user service now runs from the Nix store for reproducible installs.

  • New Features

    • Overlay fetches static binaries per OS/arch (Linux/Darwin, x86_64/arm64) with pinned SHA256.
    • Installs to $out/bin with a moshi symlink; added to Linux home-manager packages.
    • Systemd user unit uses ${pkgs.moshi-hook}/bin/moshi-hook serve.
    • scripts/upgrade-overlays.sh updates moshi-hook to the latest release and rewrites checksums.
  • Refactors

    • make overlays-update now skips only in Docker (runs in CI).

Written for commit 34d2433. Summary will update on new commits.

Review in cubic

@indent-zero

indent-zero Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor
PR Summary

Packages moshi-hook as a Nix overlay so the Linux systemd user unit launches the binary from the Nix store instead of ~/.local/bin, then wires the overlay into an automated version-bump pipeline. Version is pinned at 0.2.69 with per-platform sha256s validated against the vendor's checksums.txt.

  • Added a moshi-hook overlay in overlays/default.nix (prebuilt tarball from cdn.getmoshi.app, selects URL/hash by OS + arch, installs moshi-hook plus a moshi symlink).
  • Added moshi-hook to the Linux-only branch of home-manager/packages/default.nix.
  • Switched home-manager/services/moshi-hook/default.nix to ExecStart = "${pkgs.moshi-hook}/bin/moshi-hook serve".
  • Extended scripts/upgrade-overlays.sh with upgrade_moshi_hook, which fetches latest/version.txt, downloads and validates checksums.txt, and awk-rewrites the version and four platform hashes (asserting all four are updated).
  • Loosened Makefile's overlays-update guard to only skip in Docker (previously also skipped in CI), so the Upgrade workflow now runs the moshi-hook upgrade against the live CDN.
  • Added spec coverage in spec/upgrade_overlays_spec.sh that drives the upgrader against a file:// CDN mock.

Issues

4 potential issues found:

  • Missing meta attributes on the moshi-hook derivation (description, homepage, license, platforms, mainProgram, sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]); adding meta.platforms also lets Nix produce a clean unsupported-platform error, mitigating the sha256 fallback nit. → Autofix
  • Unused moshi symlink: ln -s moshi-hook $out/bin/moshi creates an alias no consumer in the repo uses (all references invoke moshi-hook); drop the line unless upstream expects both names. → Autofix
  • Silent sha256 fallback: the else branch of the sha256 selector returns the Darwin x86_64 hash for any platform not explicitly enumerated (e.g. i686-linux, armv7-linux), which is then paired with a Linux_x86_64 URL and surfaces as a cryptic Nix hash-mismatch instead of a clear unsupported-platform failure; either throw an explicit error or add meta.platforms to gate evaluation. → Autofix
  • Alphabetical ordering broken: moshi-hook was added between codex and collectd in the Linux package list, but the surrounding entries are strictly alphabetical so it belongs between libsecret and opencode. → Autofix

CI Checks

All four Nix jobs (nix-format, nix-check, nix-flake, nix-test) fail with the same root cause: treefmt/nixfmt reports overlays/default.nix is not formatted. The formatter wants the arch portion of the URL interpolation collapsed onto a single line (}_${if prev.stdenv.hostPlatform.isAarch64 then "arm64" else "x86_64"}.tar.gz) instead of the current three-line form. Running nix fmt (or treefmt) locally and committing the result fixes all four checks. Mesa is neutral (out of credits) and unrelated.

Failing nix-format→ Autofix
  • treefmt --fail-on-change detected unformatted content in overlays/default.nix. nixfmt wants }_${\n if prev.stdenv.hostPlatform.isAarch64 then "arm64" else "x86_64"\n}.tar.gz collapsed to }_${if prev.stdenv.hostPlatform.isAarch64 then "arm64" else "x86_64"}.tar.gz.
Failing nix-check→ Autofix
  • Same root cause as nix-format: checks.x86_64-linux.treefmt build fails because overlays/default.nix is not formatted per nixfmt.
Failing nix-flake→ Autofix
  • Same root cause as nix-format: checks.x86_64-linux.treefmt fails during nix flake check due to nixfmt formatting in overlays/default.nix.
Failing nix-test→ Autofix
  • Same root cause as nix-format: checks.x86_64-linux.treefmt fails; log shows the exact diff nixfmt wants applied to overlays/default.nix.

⚡ Autofix All

@mesa-dot-dev

mesa-dot-dev Bot commented Jul 21, 2026

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added Moshi Hook version 0.2.55 to the available package set.
    • Added support for installing Moshi Hook on supported macOS and Linux architectures.
    • Added a moshi command alias for the installed executable.
  • Bug Fixes

    • Updated the background service to use the managed Moshi Hook installation for improved reliability.

Walkthrough

Adds a pinned, platform-specific moshi-hook derivation, exposes it through Home Manager packages, and updates the user service to execute the packaged binary.

Changes

moshi-hook integration

Layer / File(s) Summary
Pinned moshi-hook derivation
overlays/default.nix
Defines version 0.2.55, selects platform- and architecture-specific archives and hashes, and installs the binary with a moshi symlink.
Home Manager package and service wiring
home-manager/packages/default.nix, home-manager/services/moshi-hook/default.nix
Adds moshi-hook to the package list and runs ${pkgs.moshi-hook}/bin/moshi-hook serve from the systemd user service.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

I’m a rabbit with a packaged hook,
A pinned binary, neat as a book.
The service now knows where to hop,
The Nix-built path will not stop—
moshi-hook springs from its new home.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly describes the main change: packaging moshi-hook as a Nix overlay.
Description check ✅ Passed The description directly explains the overlay, Home Manager integration, and systemd service update.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch worktree/green-stone-7e33

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.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request packages the moshi-hook binary as a Nix derivation, adds it to the home-manager package list, and updates the moshi-hook service to reference the package directly from the Nix store instead of a hardcoded home directory path. The review feedback suggests sorting the package list alphabetically and adding dontStrip = true; to the overlay derivation to prevent potential binary corruption or signature invalidation on prebuilt binaries.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

claude-code
cmake
codex
moshi-hook

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.

medium

The package list under lib.optionals stdenv.isLinux is sorted alphabetically. moshi-hook should be moved to its correct alphabetical position, which is between libsecret and opencode.

Comment thread overlays/default.nix
Comment on lines +97 to +98
dontConfigure = true;
dontBuild = true;

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.

medium

For prebuilt binaries (especially Go binaries or binaries running on macOS), stripping them can corrupt the executable or invalidate ad-hoc code signatures (leading to Killed: 9 errors). It is highly recommended to set dontStrip = true; to prevent Nix from attempting to strip the binary.

      dontConfigure = true;
      dontBuild = true;
      dontStrip = true;

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
overlays/default.nix (1)

77-77: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Prefer stdenvNoCC.mkDerivation for pre-compiled binaries.

Since this derivation simply downloads and installs a pre-compiled static binary without compiling any C/C++ code, using prev.stdenvNoCC.mkDerivation instead of prev.stdenv.mkDerivation is considered a best practice in Nix. It avoids bringing the C compiler toolchain into the build dependencies, saving evaluation overhead and build time.

♻️ Proposed refactor
-    moshi-hook = prev.stdenv.mkDerivation rec {
+    moshi-hook = prev.stdenvNoCC.mkDerivation rec {
🤖 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 `@overlays/default.nix` at line 77, Update the moshi-hook derivation to use
prev.stdenvNoCC.mkDerivation instead of prev.stdenv.mkDerivation, preserving the
existing download and installation behavior for the pre-compiled binary.
🤖 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 `@overlays/default.nix`:
- Around line 86-94: Correct the architecture condition in the sha256 selection
to use the valid Nixpkgs hostPlatform x86_64 attribute, alongside the existing
isAarch64 check. Also inspect the referenced tarball’s listing and update the
package’s sourceRoot/installPhase handling so the binary named moshi-hook is
found whether extraction places it at the archive root or inside a containing
directory.

---

Nitpick comments:
In `@overlays/default.nix`:
- Line 77: Update the moshi-hook derivation to use prev.stdenvNoCC.mkDerivation
instead of prev.stdenv.mkDerivation, preserving the existing download and
installation behavior for the pre-compiled binary.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 23df47e9-005e-435b-9c8c-96e2087015f1

📥 Commits

Reviewing files that changed from the base of the PR and between 233268a and 10653e9.

📒 Files selected for processing (3)
  • home-manager/packages/default.nix
  • home-manager/services/moshi-hook/default.nix
  • overlays/default.nix

Comment thread overlays/default.nix Outdated
Comment on lines +86 to +94
sha256 =
if prev.stdenv.isLinux && prev.stdenv.hostPlatform.isx86_64 then
"381ab508dba6e0ea161a2441a1e24f8a4fff974e5c5f48f003117adf306c7008"
else if prev.stdenv.isLinux && prev.stdenv.hostPlatform.isAarch64 then
"47520550b9a1f9196954bdb92f33582c09233aa148b1033eb58cd3bfbe9c45b3"
else if prev.stdenv.isDarwin && prev.stdenv.hostPlatform.isAarch64 then
"bb4a70ff48d0578e2c4c302178a3e0ed3ce722a8bc751b188c6860450b2e4e13"
else
"65d864ef4a4e47461c7c629a5f9109c0e18e54f871933bc9eb847c6edb952358";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Fix invalid hostPlatform attribute and verify tarball contents.

There is a typo in the architecture check on line 87: prev.stdenv.hostPlatform.isx86_64 should be isx86_64 (with an underscore). The attribute isx86_64 does not exist in Nixpkgs and will cause an evaluation error (attribute 'isx86_64' missing) on Linux systems.

Additionally, please verify that the downloaded .tar.gz extracts a binary exactly named moshi-hook into the root of the archive. If it extracts into a subdirectory (e.g., moshi-hook_Linux_x86_64/moshi-hook), the installPhase will fail because sourceRoot = "." restricts Nix to looking for moshi-hook in the top-level extraction directory.

🐛 Proposed fix for the architecture flag
       sha256 =
-        if prev.stdenv.isLinux && prev.stdenv.hostPlatform.isx86_64 then
+        if prev.stdenv.isLinux && prev.stdenv.hostPlatform.isx86_64 then
           "381ab508dba6e0ea161a2441a1e24f8a4fff974e5c5f48f003117adf306c7008"
         else if prev.stdenv.isLinux && prev.stdenv.hostPlatform.isAarch64 then

Run the following script to inspect the tarball layout:

#!/bin/bash
# Description: Check if moshi-hook is at the root level of the tarball
curl -sL https://cdn.getmoshi.app/hook/v0.2.55/moshi-hook_Linux_x86_64.tar.gz | tar -tz
🤖 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 `@overlays/default.nix` around lines 86 - 94, Correct the architecture
condition in the sha256 selection to use the valid Nixpkgs hostPlatform x86_64
attribute, alongside the existing isAarch64 check. Also inspect the referenced
tarball’s listing and update the package’s sourceRoot/installPhase handling so
the binary named moshi-hook is found whether extraction places it at the archive
root or inside a containing directory.

claude-code
cmake
codex
moshi-hook

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.

Nit — alphabetical ordering: this Linux block is sorted alphabetically (atop, below, binutils, blueman, bubblewrap, claude-code, cmake, codex, collectd, fwupd, gcc, gemini-cli, glib, keychain, libiconv, libsecret, opencode, ...). moshi-hook should sit between libsecret and opencode, not between codex and collectd.

Comment thread overlays/default.nix Outdated
else if prev.stdenv.isDarwin && prev.stdenv.hostPlatform.isAarch64 then
"bb4a70ff48d0578e2c4c302178a3e0ed3ce722a8bc751b188c6860450b2e4e13"
else
"65d864ef4a4e47461c7c629a5f9109c0e18e54f871933bc9eb847c6edb952358";

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.

Latent — silent fallback: this else returns the Darwin x86_64 hash for every non-enumerated platform. Combined with the URL builder above, an i686-linux or armv7-linux evaluation would fetch moshi-hook_Linux_x86_64.tar.gz (wrong arch) and validate against a Darwin hash, producing a confusing hash-mismatch error rather than a clean 'unsupported platform' failure. Prefer an explicit branch for Darwin x86_64 + else throw "moshi-hook: unsupported platform ${prev.stdenv.hostPlatform.system}", or add meta.platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; so Nix rejects unsupported hosts before evaluating src.

Comment thread overlays/default.nix
dontBuild = true;
installPhase = ''
install -Dm755 moshi-hook $out/bin/moshi-hook
ln -s moshi-hook $out/bin/moshi

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.

Nit — the moshi symlink is unused. grep -rn '\bmoshi\b' across the repo shows only moshi-hook invocations (systemd unit, hooks.json, moshi-hooks.ts, homebrew cask). Unless upstream expects both names, this symlink can be removed to keep the derivation minimal.

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="overlays/default.nix">

<violation number="1" location="overlays/default.nix:94">
P2: The `else` branch in the sha256 cascade silently falls through to the Darwin x86_64 hash for any platform not explicitly matched. On an unsupported platform (e.g., 32-bit ARM Linux or `riscv64-linux`), the URL would be constructed as `moshi-hook_Linux_x86_64.tar.gz` but the hash would be the Darwin x86_64 one, causing a confusing hash mismatch rather than a clear, actionable error. Consider either (a) adding `meta.platforms` to the derivation to restrict buildability to only the four supported platform combos, or (b) replacing the fallback hash with an explicit `throw` to surface a clear message when someone evaluates on an unexpected platform.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread overlays/default.nix Outdated
else if prev.stdenv.isDarwin && prev.stdenv.hostPlatform.isAarch64 then
"bb4a70ff48d0578e2c4c302178a3e0ed3ce722a8bc751b188c6860450b2e4e13"
else
"65d864ef4a4e47461c7c629a5f9109c0e18e54f871933bc9eb847c6edb952358";

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.

P2: The else branch in the sha256 cascade silently falls through to the Darwin x86_64 hash for any platform not explicitly matched. On an unsupported platform (e.g., 32-bit ARM Linux or riscv64-linux), the URL would be constructed as moshi-hook_Linux_x86_64.tar.gz but the hash would be the Darwin x86_64 one, causing a confusing hash mismatch rather than a clear, actionable error. Consider either (a) adding meta.platforms to the derivation to restrict buildability to only the four supported platform combos, or (b) replacing the fallback hash with an explicit throw to surface a clear message when someone evaluates on an unexpected platform.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At overlays/default.nix, line 94:

<comment>The `else` branch in the sha256 cascade silently falls through to the Darwin x86_64 hash for any platform not explicitly matched. On an unsupported platform (e.g., 32-bit ARM Linux or `riscv64-linux`), the URL would be constructed as `moshi-hook_Linux_x86_64.tar.gz` but the hash would be the Darwin x86_64 one, causing a confusing hash mismatch rather than a clear, actionable error. Consider either (a) adding `meta.platforms` to the derivation to restrict buildability to only the four supported platform combos, or (b) replacing the fallback hash with an explicit `throw` to surface a clear message when someone evaluates on an unexpected platform.</comment>

<file context>
@@ -73,6 +73,35 @@
+          else if prev.stdenv.isDarwin && prev.stdenv.hostPlatform.isAarch64 then
+            "bb4a70ff48d0578e2c4c302178a3e0ed3ce722a8bc751b188c6860450b2e4e13"
+          else
+            "65d864ef4a4e47461c7c629a5f9109c0e18e54f871933bc9eb847c6edb952358";
+      };
+      sourceRoot = ".";
</file context>

@shunkakinoki
shunkakinoki force-pushed the worktree/green-stone-7e33 branch from 10653e9 to fad3a51 Compare August 2, 2026 12:32
@shunkakinoki
shunkakinoki merged commit 0f85607 into main Aug 2, 2026
26 of 27 checks passed
@shunkakinoki
shunkakinoki deleted the worktree/green-stone-7e33 branch August 2, 2026 13:11
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.

1 participant