Skip to content

feat(nix): add Nix flake for reproducible builds and demos#34

Open
randomizedcoder wants to merge 1 commit intochrishayuk:mainfrom
randomizedcoder:nix
Open

feat(nix): add Nix flake for reproducible builds and demos#34
randomizedcoder wants to merge 1 commit intochrishayuk:mainfrom
randomizedcoder:nix

Conversation

@randomizedcoder
Copy link
Copy Markdown

G'day Chris,

Thanks for your great YouTube videos and this project. This kinda blew my mind, and so I wanted to try it out on NixOS. Not sure if you've used Nix, but you might be interested if you haven't. I don't expect you to actually maintain the Nix, but it will make it easy to use for people using Nix. Please see the ./nix/README.md for full details.

What this adds

A modular Nix flake (flake.nix + nix/ directory) that provides:

  • nix develop — reproducible dev shell with Rust toolchain, OpenBLAS, protobuf, Python/maturin, debuggers, and all build dependencies pre-configured
  • nix build — builds the larql CLI binary (workspace minus larql-python)
  • Pre-fetched model catalog — 8 models (Qwen, Phi, TinyLlama, StableLM, Gemma 4) as fixed-output derivations cached in /nix/store
  • nix run .#demo — one-command walk of the default model (gemma4-4b)
  • nix run .#repl / nix run .#repl-<key> — interactive REPL with a model auto-loaded
  • nix run .#container — OCI container image via dockerTools
  • Cross-platform — Linux (OpenBLAS) and macOS (Accelerate + Metal) support

Remote usage (no clone needed)

# From this fork (nix branch)
nix run github:randomizedcoder/larql/nix#demo

# Once merged to main
nix run github:chrishayuk/larql#demo
nix develop github:chrishayuk/larql

Files added/changed

File Purpose
flake.nix Small orchestrator (~73 lines)
flake.lock Pins nixpkgs + flake-utils
nix/package.nix Rust package derivation
nix/shell.nix Dev shell config
nix/models.nix 8-model catalog with pre-computed hashes
nix/demo.nix Demo/REPL run targets
nix/container.nix OCI container image
nix/banner.nix Dev shell welcome (uses your LARQL ASCII art)
nix/patches/use-system-protoc.patch Uses nixpkgs protoc instead of bundled protobuf-src
nix/README.md Full documentation
nix/example-queries.md Example LQL queries
.gitignore Un-ignores Cargo.lock, adds result
Cargo.lock Now committed (required by Nix, recommended for binaries)

Non-invasive

  • Zero changes to Rust source code — all platform fixes are applied via cargoPatches at Nix build time only
  • The patch removes protobuf-src (uses system protoc), disables the metal default feature (re-enabled on Darwin via build flags), and adds #[cfg(feature = "metal")] guards — none of this touches your repo's actual source files
  • Cargo.lock is now committed per Cargo's recommendation for applications/binaries

Test plan

  • nix flake check passes
  • nix build produces working ./result/bin/larql
  • nix develop drops into dev shell with correct tools
  • nix run .#demo walks gemma4-4b model
  • nix run .#repl opens interactive REPL with model loaded
  • Tested on NixOS Linux (x86_64)

Cheers! 🍻

🤖 Generated with Claude Code

…l catalog

Add reproducible Nix packaging for larql:

- flake.nix orchestrator importing modular files from nix/
- package.nix: Rust derivation with cargoHash, system protoc via patch
- shell.nix: dev shell with Rust tools, Python/maturin, debuggers
- container.nix: OCI images for larql-server and larql CLI (Linux)
- models.nix: 8-model HuggingFace catalog (SmolLM2, Qwen, TinyLlama,
  StableLM, Phi-3.5, Gemma 4 E2B/E4B) fetched as fixed-output derivations
- demo.nix: per-model walk demos and interactive REPL targets
- Patches: remove protobuf-src (use nixpkgs protoc), disable default
  metal feature (macOS-only), add cfg guard to bench_cmd.rs
- README.md: install guide, remote usage from GitHub, model docs
- Commit Cargo.lock (required by buildRustPackage)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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