Skip to content

Add nix flake with automated vendorHash maintenance#74

Merged
wesm merged 9 commits intowesm:mainfrom
socksy:add-nix-flake
Feb 8, 2026
Merged

Add nix flake with automated vendorHash maintenance#74
wesm merged 9 commits intowesm:mainfrom
socksy:add-nix-flake

Conversation

@socksy
Copy link
Contributor

@socksy socksy commented Feb 5, 2026

Summary

  • flake.nix: Nix build support with buildGoModule, FTS5 build tag, dev shell with Go + golangci-lint + gcc. Targets all 4 platforms (x86_64/aarch64 linux/darwin).
  • scripts/update-nix-flake.sh: Automates vendorHash updates — computes the correct hash via nix build, verifies the build, and opens a PR. Supports optional version tag for release bumps.
  • scripts/release.sh: Prompts to update the nix flake after tagging a release.
  • CI: Adds nix-build job to verify the flake builds on every push/PR.
  • Uses go instead of go_1_25 in devShell to avoid manual bumps on Go version upgrades.

Test plan

  • Rebased on latest main (resolved CI workflow conflict)
  • nix build produces working binary
  • nix develop provides Go + lint toolchain
  • CI nix-build job passes

🤖 Generated with Claude Code

@wesm
Copy link
Owner

wesm commented Feb 5, 2026

Thanks for adding this — we also have a nix flake in roborev that I've been maintaining. I laugh because the irony is that using Go to make static application binaries is supposed to make things easy for users to install and upgrade, but the whole Nix way of doing things just gets in the way and from what I can see it is simply making it harder for Nix users to engage with new projects.

I've been watching Nix users struggle to deal with AI tools and their upgrade cycles (beads, claude, codex, roborev) and I can honestly say I have no interest in becoming a Nix user.

@socksy
Copy link
Contributor Author

socksy commented Feb 5, 2026

That's understandable for sure. And FWIW I don't think Go is the limiting factor here. If it were pure go it would be statically linked and would Just Work™. It's the CGO bindings in go-sqlite3 and go-duckdb.

What I personally like about it is being able to declaratively specify my entire system and being sure that it'll be the same everywhere. I just ported two VPSes from vultr to hetzner with a combination of terraform and a nix configuration that made it pretty painless, and I set up each new laptop of mine with the same software and settings and can be pretty sure it Just Works.

You can always escape hatch out of nix land and get the same imperative experience as on any other system. But then it won't be declaratively specified in my setup (I'm hoping to set up msgvault on my server to be able to access it from everywhere so it'd be nice if it's setup correctly when I provision it).

socksy and others added 2 commits February 8, 2026 08:15
Since the sha depends on the go.mod file, it will break
each time the dependencies change. CI builds nix to flag
up when this happens (the error message should say what
the new sha should be).
- Add scripts/update-nix-flake.sh: computes correct vendorHash by
  running nix build with a fake hash, updates flake.nix, verifies
  the build, and opens a PR. Supports optional version tag argument.
- Hook into scripts/release.sh to offer nix flake update after
  tagging a release.
- Change devShell from go_1_25 to go (tracks latest stable, no
  manual bumps needed).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@wesm wesm self-requested a review as a code owner February 8, 2026 14:32
@wesm wesm changed the title Add flake.nix for nix build support Add nix flake with automated vendorHash maintenance Feb 8, 2026
wesm and others added 7 commits February 8, 2026 08:33
- Restrict nix-build CI job to non-fork PRs to prevent arbitrary code
  execution via malicious flake.nix. Add contents: read permission.
- Validate extracted vendorHash matches expected sha256 format (exactly
  44 base64 chars) before inserting into flake.nix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Reject VERSION_TAG values that don't match semver X.Y.Z format to
prevent sed metacharacter injection into flake.nix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove wesm from trusted-contributors.json so the security review
bot runs on all PRs, not just external contributors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The if: condition was blocking the job because this PR originated from
a fork. The restriction is unnecessary — GitHub Actions already
sandboxes fork PRs with read-only tokens and no secrets access, and
nix build only compiles code without needing any secrets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The original SHA was incorrect (e50d5f73...1f848571), causing the
action download to 404. Corrected to the actual v16 tag SHA.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Go 1.25.7 was released on Feb 4 but nixpkgs-unstable still has 1.25.5.
Override go_1_25 with the 1.25.7 source hash from nixpkgs staging to
match go.mod's requirement. This can be simplified back to plain
pkgs.buildGoModule once nixpkgs-unstable catches up.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The vendor module hash changes with the Go version bump.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Feb 8, 2026

Security Review: 4 High/Medium Issues Found

Claude's automated security review identified potential security concerns. Please review each finding below.

Note: 1 low severity issue(s) were omitted to reduce noise.


🚨 Repository owner removed from trusted contributors list (high)

Location: .github/trusted-contributors.json:3

The repository owner 'wesm' has been removed from the trusted contributors list, which means their PRs will now undergo automated security review. This change could allow an attacker who compromises this file to force security reviews on maintainer PRs while bypassing their own. This is suspicious and should be rejected unless there is a legitimate operational reason documented in the PR description.


🚨 Insufficient input validation allows command injection (high)

Location: scripts/update-nix-flake.sh:44

The VERSION variable is validated with a regex check, but then used directly in a sed command without proper escaping. While the regex blocks most injection attempts, sed's replacement string has special characters (& \ /) that could be exploited if the regex is bypassed or modified. Use a safer approach like printf '%s\n' to safely substitute the version string, or escape all sed metacharacters.


⚠️ Insufficient validation of vendorHash from nix build output (medium)

Location: scripts/update-nix-flake.sh:66

The CORRECT_HASH is extracted from nix build error output using sed and validated with a regex, but this relies on trusting the format of nix's error messages. If nix's output format changes or an attacker can influence the build output, a malicious hash could be extracted and committed. Consider adding additional validation or checksums to verify the hash matches expected go.sum content.


⚠️ Suspicious timestamp in flake.lock (year 2026) (medium)

Location: flake.lock:5

The lastModified field contains timestamp 1770141374 which corresponds to a date in early 2026, approximately 2 years in the future. This is impossible and suggests the flake.lock file may be maliciously crafted or corrupted. Nix flakes should reference real, historical commits. Verify the nixpkgs commit hash 41965737c1797c1d83cfb0b644ed0840a6220bd1 exists and regenerate flake.lock from a known-good nixpkgs revision.


Powered by Claude 4.5 Sonnet — this is an automated review, false positives are possible.

@wesm
Copy link
Owner

wesm commented Feb 8, 2026

The lastModified field contains timestamp 1770141374 which corresponds to a date in early 2026, approximately 2 years in the future. This is impossible and suggests the flake.lock file may be maliciously crafted or corrupted. Nix flakes should reference real, historical commits. Verify the nixpkgs commit hash 41965737c1797c1d83cfb0b644ed0840a6220bd1 exists and regenerate flake.lock from a known-good nixpkgs revision.

😆 I guess maybe I should move the security review onto Opus 4.6, I'll work on that

@wesm wesm merged commit 4d99b6d into wesm:main Feb 8, 2026
4 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.

2 participants