From 4a572fc588b4986cd28b5cba37405797a136a1e0 Mon Sep 17 00:00:00 2001 From: Eden Reich Date: Mon, 1 Dec 2025 11:46:20 +0200 Subject: [PATCH 1/6] ci(nix): Add NixOS package distribution Implement complete NixOS packaging support with automated workflows and improved documentation for distributing the Inference Gateway CLI as an official nixpkgs package. Signed-off-by: Eden Reich --- .github/workflows/nix-build.yml | 126 +++++++++ .github/workflows/nix-version-sync.yml | 147 ++++++++++ .gitignore | 5 + README.md | 47 ++++ docs/nix-distribution-overview.md | 360 +++++++++++++++++++++++++ docs/nixpkgs-submission.md | 345 ++++++++++++++++++++++++ nix/README.md | 206 ++++++++++++++ nix/infer.nix | 84 ++++++ nix/update-hashes.sh | 147 ++++++++++ 9 files changed, 1467 insertions(+) create mode 100644 .github/workflows/nix-build.yml create mode 100644 .github/workflows/nix-version-sync.yml create mode 100644 docs/nix-distribution-overview.md create mode 100644 docs/nixpkgs-submission.md create mode 100644 nix/README.md create mode 100644 nix/infer.nix create mode 100755 nix/update-hashes.sh diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml new file mode 100644 index 00000000..6e591284 --- /dev/null +++ b/.github/workflows/nix-build.yml @@ -0,0 +1,126 @@ +name: Nix Build Verification + +on: + pull_request: + branches: + - main + paths: + - 'nix/**' + - 'go.mod' + - 'go.sum' + - '**.go' + - '.github/workflows/nix-build.yml' + push: + branches: + - main + paths: + - 'nix/**' + - 'go.mod' + - 'go.sum' + - '**.go' + - '.github/workflows/nix-build.yml' + workflow_dispatch: + +jobs: + nix-build: + name: Build on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + platform: linux-amd64 + - os: ubuntu-latest + platform: linux-arm64 + - os: macos-15-intel + platform: darwin-amd64 + - os: macos-latest + platform: darwin-arm64 + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Install Nix + uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + experimental-features = nix-command flakes + accept-flake-config = true + + - name: Setup Cachix + uses: cachix/cachix-action@v15 + with: + name: inference-gateway + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + skipPush: ${{ github.event_name == 'pull_request' }} + + - name: Build with Nix + run: | + nix-build nix/infer.nix --show-trace + + - name: Verify binary + run: | + result/bin/infer version + result/bin/infer --help + + - name: Check binary size + run: | + ls -lh result/bin/infer + size=$(stat -c%s result/bin/infer 2>/dev/null || stat -f%z result/bin/infer) + echo "Binary size: $(numfmt --to=iec $size 2>/dev/null || echo $size bytes)" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: infer-${{ matrix.platform }} + path: result/bin/infer + retention-days: 7 + + nix-fmt-check: + name: Check Nix formatting + runs-on: ubuntu-24.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Install Nix + uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + experimental-features = nix-command flakes + + - name: Check Nix formatting + run: | + nix-shell -p nixpkgs-fmt --run "nixpkgs-fmt --check nix/" + + - name: Evaluate Nix expression + run: | + nix-instantiate --eval --strict nix/infer.nix --show-trace + + summary: + name: Build Summary + runs-on: ubuntu-latest + needs: + - nix-build + - nix-fmt-check + if: always() + + steps: + - name: Check build results + run: | + if [ "${{ needs.nix-build.result }}" != "success" ]; then + echo "::error::Nix build failed" + exit 1 + fi + + if [ "${{ needs.nix-fmt-check.result }}" != "success" ]; then + echo "::error::Nix formatting check failed" + exit 1 + fi + + echo "✅ All Nix build checks passed!" diff --git a/.github/workflows/nix-version-sync.yml b/.github/workflows/nix-version-sync.yml new file mode 100644 index 00000000..3fb374db --- /dev/null +++ b/.github/workflows/nix-version-sync.yml @@ -0,0 +1,147 @@ +name: Nix Version Sync + +on: + release: + types: + - published + workflow_dispatch: + inputs: + version: + description: 'Version to sync (e.g., 0.76.1)' + required: true + type: string + +permissions: + contents: write + pull-requests: write + +jobs: + update-nix-version: + name: Update Nix package version + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v31 + with: + nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + experimental-features = nix-command flakes + + - name: Determine version + id: version + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + VERSION="${{ inputs.version }}" + else + VERSION="${{ github.event.release.tag_name }}" + VERSION="${VERSION#v}" + fi + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Version to sync: $VERSION" + + - name: Calculate source hash + id: source-hash + run: | + VERSION="${{ steps.version.outputs.version }}" + URL="https://github.com/inference-gateway/cli/archive/refs/tags/v${VERSION}.tar.gz" + + echo "Downloading source from: $URL" + HASH=$(nix-prefetch-url --unpack "$URL") + echo "Source hash: $HASH" + echo "hash=$HASH" >> $GITHUB_OUTPUT + + - name: Update version in Nix expression + run: | + VERSION="${{ steps.version.outputs.version }}" + HASH="${{ steps.source-hash.outputs.hash }}" + sed -i "s/version = \"[0-9.]*\";/version = \"$VERSION\";/" nix/infer.nix + sed -i "s|hash = \"sha256-[A-Za-z0-9+/=]*\";|hash = \"sha256-$HASH\";|" nix/infer.nix + echo "Updated nix/infer.nix with version $VERSION" + cat nix/infer.nix | grep -A2 "version =" + + - name: Calculate vendor hash + id: vendor-hash + run: | + echo "Attempting build to calculate vendorHash..." + sed -i 's|vendorHash = "sha256-[A-Za-z0-9+/=]*";|vendorHash = "";|' nix/infer.nix + BUILD_OUTPUT=$(nix-build nix/infer.nix 2>&1 || true) + VENDOR_HASH=$(echo "$BUILD_OUTPUT" | grep -oP "got:\s+sha256-\K[A-Za-z0-9+/=]+" | head -1) + + if [ -z "$VENDOR_HASH" ]; then + echo "::error::Failed to calculate vendorHash" + echo "$BUILD_OUTPUT" + exit 1 + fi + + echo "Vendor hash: sha256-$VENDOR_HASH" + echo "hash=$VENDOR_HASH" >> $GITHUB_OUTPUT + + - name: Update vendor hash in Nix expression + run: | + VENDOR_HASH="${{ steps.vendor-hash.outputs.hash }}" + sed -i "s|vendorHash = \"[^\"]*\";|vendorHash = \"sha256-$VENDOR_HASH\";|" nix/infer.nix + echo "Updated vendorHash in nix/infer.nix" + + - name: Verify build + run: | + echo "Building with updated hashes to verify..." + nix-build nix/infer.nix --show-trace + + echo "Verifying binary..." + result/bin/infer version + + - name: Format Nix file + run: | + nix-shell -p nixpkgs-fmt --run "nixpkgs-fmt nix/infer.nix" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: 'chore(nix): Update package to v${{ steps.version.outputs.version }}' + title: 'chore(nix): Update package to v${{ steps.version.outputs.version }}' + body: | + ## Automated Nix Package Update + + This PR updates the Nix package expression to version **${{ steps.version.outputs.version }}**. + + ### Changes + - ✅ Updated `version` to `${{ steps.version.outputs.version }}` + - ✅ Updated source `hash` to `sha256-${{ steps.source-hash.outputs.hash }}` + - ✅ Updated `vendorHash` to `sha256-${{ steps.vendor-hash.outputs.hash }}` + - ✅ Verified build succeeds + - ✅ Formatted with nixpkgs-fmt + + ### Verification + ```bash + nix-build nix/infer.nix + result/bin/infer version + ``` + + ### Related + - Release: ${{ github.event.release.html_url || 'Manual trigger' }} + + --- + 🤖 Auto-generated by `.github/workflows/nix-version-sync.yml` + branch: chore/nix-update-v${{ steps.version.outputs.version }} + delete-branch: true + labels: | + nix + dependencies + automated + + - name: Summary + run: | + echo "## ✅ Nix Package Updated" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- **Version**: ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY + echo "- **Source Hash**: sha256-${{ steps.source-hash.outputs.hash }}" >> $GITHUB_STEP_SUMMARY + echo "- **Vendor Hash**: sha256-${{ steps.vendor-hash.outputs.hash }}" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "A pull request has been created to merge these changes." >> $GITHUB_STEP_SUMMARY diff --git a/.gitignore b/.gitignore index 8fb73c45..a2f47dfc 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,11 @@ flox.*-linux.* /.task infer +# Nix build artifacts +result +result-* +*.drv + # IDE's .vscode .idea diff --git a/README.md b/README.md index 5754e93b..2c21f195 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ and management of inference services. - [Installation](#installation) - [Using Go Install](#using-go-install) - [Using Container Image](#using-container-image) + - [Using NixOS / Nix Package Manager](#using-nixos--nix-package-manager) - [Using Install Script](#using-install-script) - [Manual Download](#manual-download) - [Verifying Release Binaries](#verifying-release-binaries) @@ -150,6 +151,52 @@ docker run --rm -it ghcr.io/inference-gateway/cli:0.48.12 **Available architectures:** `linux/amd64`, `linux/arm64` +### Using NixOS / Nix Package Manager + +For NixOS users or systems with the Nix package manager: + +**Install from nixpkgs (after submission is accepted):** + +```bash +# NixOS configuration +environment.systemPackages = with pkgs; [ + infer +]; + +# Or install to user profile +nix-env -iA nixpkgs.infer + +# Or with nix profile (flakes) +nix profile install nixpkgs#infer +``` + +**Build from source with Nix:** + +```bash +# Clone the repository +git clone https://github.com/inference-gateway/cli.git +cd cli + +# Build using the Nix expression +nix-build nix/infer.nix + +# Test the binary +./result/bin/infer version + +# Install to user profile +nix-env -if nix/infer.nix +``` + +**Benefits of using Nix:** + +- Reproducible builds across all platforms +- Automatic dependency management +- Shell completions automatically installed +- Easy rollback to previous versions +- Integration with NixOS system configuration + +See [nixpkgs submission guide](docs/nixpkgs-submission.md) for details on the official package submission process. + ### Using Install Script For quick installation, you can use our install script: diff --git a/docs/nix-distribution-overview.md b/docs/nix-distribution-overview.md new file mode 100644 index 00000000..d4321a39 --- /dev/null +++ b/docs/nix-distribution-overview.md @@ -0,0 +1,360 @@ +# NixOS Package Distribution - Implementation Overview + +This document provides a comprehensive overview of the NixOS package distribution setup for the Inference Gateway CLI. + +## What Was Implemented + +### 1. Nix Package Expression (`nix/infer.nix`) + +A complete Nix derivation that: + +- Uses `buildGoModule` for Go package building +- Fetches source from GitHub releases +- Handles CGO requirements for macOS (clipboard support) +- Generates shell completions (bash, fish, zsh) +- Sets proper ldflags for version information +- Includes comprehensive metadata for nixpkgs + +**Key Features:** + +- Cross-platform support (Linux amd64/arm64, macOS amd64/arm64) +- Automatic dependency management via Go modules +- Security through reproducible builds +- Shell completion installation + +### 2. CI/CD Integration + +#### Nix Build Verification (`.github/workflows/nix-build.yml`) + +Runs on every PR and push to verify: + +- ✅ Package builds on all supported platforms +- ✅ Binary executes correctly (`infer version`) +- ✅ Nix formatting is correct +- ✅ Nix expression evaluates without errors + +**Matrix Testing:** + +- ubuntu-latest (linux-amd64, linux-arm64) +- macos-13 (darwin-amd64, Intel Mac) +- macos-latest (darwin-arm64, Apple Silicon) + +**Optimizations:** + +- Cachix integration for faster builds +- Parallel platform testing +- Artifact uploads for verification + +#### Version Sync Automation (`.github/workflows/nix-version-sync.yml`) + +Automatically updates the Nix package on releases: + +- 🔄 Triggers on GitHub releases (or manual workflow dispatch) +- 🔢 Calculates source hash from GitHub tarball +- 📦 Determines vendorHash by building +- ✏️ Updates `nix/infer.nix` with new hashes +- 🎨 Formats with nixpkgs-fmt +- ✅ Verifies build succeeds +- 🔀 Creates PR with changes + +**Benefits:** + +- No manual hash calculation needed +- Automatic verification before PR +- Consistent formatting +- Clear audit trail + +### 3. Documentation + +#### nixpkgs Submission Guide (`docs/nixpkgs-submission.md`) + +Comprehensive guide covering: + +- Prerequisites and preparation +- Step-by-step submission process +- Local build verification +- Hash calculation methods +- Fork and PR workflow +- Review response guidelines +- Maintenance procedures +- Troubleshooting common issues + +#### Nix README (`nix/README.md`) + +Quick reference for: + +- Local building and testing +- Hash update procedures +- Automated workflow usage +- Platform-specific considerations +- Development tips +- Common troubleshooting + +#### README Updates + +Added NixOS installation section to main README.md: + +- Installation from nixpkgs (post-submission) +- Building from source with Nix +- Benefits of using Nix +- Link to submission guide + +## Architecture Decisions + +### Why These Choices? + +1. **nixpkgs submission only** (no standalone flake) + - Single source of truth + - Official distribution channel + - Discoverable via `nix search` + - Integrated with NixOS ecosystem + +2. **Automated version sync** + - Reduces human error + - Faster release cycle + - Consistent process + - Easy to audit + +3. **Multi-platform CI** + - Catches platform-specific issues early + - Verifies CGO requirements (macOS) + - Tests on actual target platforms + - Provides build artifacts for verification + +4. **`pkgs/by-name` structure** (for nixpkgs) + - Modern nixpkgs convention + - Better organization + - Faster evaluation + - Required for new packages + +## Current Status + +### ✅ Completed + +- [x] Nix package expression with proper structure +- [x] CI workflow for build verification +- [x] Automated version sync workflow +- [x] Comprehensive documentation +- [x] README updates with NixOS instructions +- [x] .gitignore updates for Nix artifacts + +### ⏳ Pending (Next Steps) + +1. **Calculate Actual Hashes** + - Replace placeholder hashes in `nix/infer.nix` + - Source hash: `nix-prefetch-url --unpack TARBALL_URL` + - Vendor hash: Build with empty string, extract from error + +2. **Verify Build Locally** + + ```bash + nix-build nix/infer.nix + ./result/bin/infer version + ``` + +3. **Test CI Workflows** + - Push changes to trigger nix-build.yml + - Verify all platforms build successfully + - Check Cachix integration (requires auth token) + +4. **Setup Cachix** (Optional but Recommended) + - Create account at + - Create `inference-gateway` cache + - Add `CACHIX_AUTH_TOKEN` to GitHub secrets + - Significantly speeds up CI builds + +5. **Submit to nixpkgs** + - Follow `docs/nixpkgs-submission.md` + - Fork NixOS/nixpkgs + - Copy to `pkgs/by-name/in/infer/package.nix` + - Add yourself to maintainers + - Create PR with template + - Respond to reviewer feedback + +## File Structure + +```text +inference-gateway/cli/ +├── .github/ +│ └── workflows/ +│ ├── nix-build.yml # CI verification +│ └── nix-version-sync.yml # Auto-update on release +├── docs/ +│ ├── nixpkgs-submission.md # Submission guide +│ └── nix-distribution-overview.md # This file +├── nix/ +│ ├── infer.nix # Nix package expression +│ └── README.md # Quick reference +├── .gitignore # Updated with Nix artifacts +└── README.md # Updated with NixOS section +``` + +## Maintenance Workflow + +### For Each Release + +1. **Automatic** (via GitHub Actions): + - Release gets published + - `nix-version-sync.yml` triggers + - Calculates hashes + - Creates PR with updates + - CI verifies build + +2. **Manual** (you do): + - Review and merge the auto-generated PR + - Wait for CI to pass + - Verify binary works + +3. **nixpkgs Update** (after initial submission): + - Create update PR in nixpkgs + - Use new version and hashes from CLI repo + - Follow same process as initial submission + +### Monitoring + +Keep an eye on: + +- **CI Build Status**: Ensure nix-build.yml passes +- **Hash Updates**: Verify auto-PRs are created on releases +- **nixpkgs Issues**: Watch for user-reported problems +- **Hydra Builds**: nixpkgs CI may catch platform issues + +## Benefits for Users + +### Why Users Should Use the Nix Package + +1. **Reproducibility** + - Same build every time + - Bit-for-bit identical across machines + - No "works on my machine" issues + +2. **Dependency Management** + - All dependencies included + - No conflicts with system packages + - Automatic cleanup of old versions + +3. **Easy Rollback** + + ```bash + nix-env --rollback + ``` + +4. **Multiple Versions** + + ```bash + nix-env -iA nixpkgs.infer # Latest + nix-env -f channel:nixos-23.11 -iA infer # Specific release + ``` + +5. **System Integration** + - Shell completions auto-installed + - Proper FHS paths + - Integrates with NixOS configuration + +6. **Security** + - Build from source, not pre-built binaries + - Verified dependencies + - No need to trust maintainer's build environment + +## Troubleshooting + +### Common Issues and Solutions + +#### Issue: "hash mismatch" on source + +**Solution:** + +```bash +# Recalculate the hash +nix-prefetch-url --unpack "https://github.com/inference-gateway/cli/archive/refs/tags/v0.76.1.tar.gz" + +# Update in nix/infer.nix +``` + +#### Issue: "vendor hash mismatch" + +**Solution:** + +```bash +# Set vendorHash to empty string +sed -i 's|vendorHash = ".*";|vendorHash = "";|' nix/infer.nix + +# Build and capture error +nix-build nix/infer.nix 2>&1 | grep "got:" | grep -oP "sha256-[A-Za-z0-9+/=]+" + +# Use that hash in infer.nix +``` + +#### Issue: CGO errors on macOS + +**Solution:** +Ensure: + +```nix +CGO_ENABLED = if stdenv.isDarwin then 1 else 0; + +buildInputs = lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Cocoa + darwin.apple_sdk.frameworks.UserNotifications +]; +``` + +#### Issue: Tests fail in Nix sandbox + +**Solution:** +Skip network-dependent tests: + +```nix +checkFlags = [ + "-skip=TestIntegration|TestNetwork" +]; +``` + +#### Issue: nix-version-sync workflow fails + +**Possible Causes:** + +1. GitHub token lacks permissions → Check workflow permissions +2. Version format incorrect → Ensure tags follow `vX.Y.Z` format +3. Build fails → Check Go module issues or missing dependencies + +## Resources + +### Official Documentation + +- [Nix Manual](https://nixos.org/manual/nix/stable/) +- [nixpkgs Manual](https://nixos.org/manual/nixpkgs/stable/) +- [NixOS Manual](https://nixos.org/manual/nixos/stable/) + +### Community + +- [NixOS Discourse](https://discourse.nixos.org/) +- [NixOS Wiki](https://nixos.wiki/) +- [r/NixOS](https://www.reddit.com/r/NixOS/) + +### Tools + +- [nix-prefetch-url](https://nixos.org/manual/nix/stable/command-ref/nix-prefetch-url.html) +- [nixpkgs-fmt](https://github.com/nix-community/nixpkgs-fmt) +- [Cachix](https://cachix.org/) +- [nix-output-monitor](https://github.com/maralorn/nix-output-monitor) + +### Related Projects + +- [gomod2nix](https://github.com/nix-community/gomod2nix) - Alternative Go packaging +- [nixpkgs-update](https://github.com/ryantm/nixpkgs-update) - Automated updates +- [niv](https://github.com/nmattia/niv) - Dependency management + +## Contact and Support + +For issues with the Nix packaging: + +- **Nix-specific issues**: Open in this repo with `nix` label +- **nixpkgs issues**: Open in NixOS/nixpkgs, mention `@maintainers/go` +- **General CLI issues**: Regular issue tracker + +--- + +**Last Updated**: 2025-12-01 +**Status**: Ready for hash calculation and submission +**Next Action**: Calculate actual hashes and verify local build diff --git a/docs/nixpkgs-submission.md b/docs/nixpkgs-submission.md new file mode 100644 index 00000000..7cc13a3a --- /dev/null +++ b/docs/nixpkgs-submission.md @@ -0,0 +1,345 @@ +# nixpkgs Submission Guide + +This guide walks you through submitting the Inference Gateway CLI to the official NixOS/nixpkgs repository. + +## Prerequisites + +Before submitting, ensure: + +- ✅ The Nix package builds successfully locally +- ✅ The CI workflow (`.github/workflows/nix-build.yml`) passes +- ✅ You have a GitHub account +- ✅ You're familiar with Git and GitHub pull requests +- ✅ You've reviewed the [nixpkgs contributing guidelines](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md) + +## Step 1: Verify Local Build + +First, test the Nix package builds correctly: + +```bash +# Build the package +nix-build nix/infer.nix + +# Test the binary +result/bin/infer version +result/bin/infer --help + +# Run a quick smoke test +result/bin/infer chat --help +``` + +If any issues arise, fix them before proceeding. + +## Step 2: Calculate Final Hashes + +The `nix/infer.nix` file contains placeholder hashes that need to be calculated: + +```bash +# Source hash (already calculated by nix-version-sync workflow) +# Verify it's correct: +nix-prefetch-url --unpack https://github.com/inference-gateway/cli/archive/refs/tags/v0.76.1.tar.gz + +# Vendor hash (also calculated by workflow) +# To manually verify: +sed -i 's|vendorHash = ".*";|vendorHash = "";|' nix/infer.nix +nix-build nix/infer.nix 2>&1 | grep "got:" | grep -oP "sha256-[A-Za-z0-9+/=]+" +``` + +## Step 3: Fork nixpkgs + +1. Go to +2. Click "Fork" in the top-right corner +3. Clone your fork: + +```bash +git clone https://github.com/YOUR_USERNAME/nixpkgs.git +cd nixpkgs +``` + +## Step 4: Create Package in nixpkgs + +nixpkgs now uses the `pkgs/by-name` structure for new packages: + +```bash +# Create the package directory +mkdir -p pkgs/by-name/in/infer + +# Copy the Nix expression +cp /path/to/cli/nix/infer.nix pkgs/by-name/in/infer/package.nix + +# Note: In nixpkgs, the file MUST be named "package.nix" +``` + +### Edit package.nix + +Update the file for nixpkgs conventions: + +```nix +{ lib +, buildGoModule +, fetchFromGitHub +, installShellFiles +, stdenv +, darwin +}: + +buildGoModule rec { + pname = "infer"; + version = "0.76.1"; + + src = fetchFromGitHub { + owner = "inference-gateway"; + repo = "cli"; + rev = "v${version}"; + hash = "sha256-ACTUAL_HASH_HERE"; # Use real hash + }; + + vendorHash = "sha256-ACTUAL_VENDOR_HASH_HERE"; # Use real hash + + # ... rest of the file +} +``` + +**Important changes for nixpkgs:** + +1. Remove any GitHub Actions or CI-specific comments +2. Ensure all hashes are correct (no placeholders) +3. Add yourself to `meta.maintainers`: + +```nix +maintainers = with maintainers; [ your-github-username ]; +``` + +## Step 5: Test the Package in nixpkgs + +Build and test from within the nixpkgs repository: + +```bash +# Build the package +nix-build -A infer + +# Test it +result/bin/infer version + +# Check metadata +nix-instantiate --eval -E 'with import ./. {}; infer.meta.description' + +# Run nixpkgs checks +nix-build -A infer.tests +``` + +## Step 6: Create Commit and Branch + +Follow nixpkgs commit conventions: + +```bash +# Create a branch +git checkout -b infer-init + +# Add the package +git add pkgs/by-name/in/infer/package.nix + +# Commit with proper message +git commit -m "infer: init at 0.76.1" +``` + +**Commit message format:** + +- For new packages: `: init at ` +- For updates: `: -> ` + +## Step 7: Push and Create Pull Request + +```bash +# Push to your fork +git push origin infer-init +``` + +Go to and create a pull request. + +### PR Template + +Use this template for your PR description: + +```markdown +#### Description of changes + +This PR adds the Inference Gateway CLI (`infer`), a command-line tool for managing AI model interactions. + +#### Package Details + +- **Package name**: `infer` +- **Version**: `0.76.1` +- **License**: MIT +- **Platforms**: Linux (x86_64, aarch64), macOS (x86_64, aarch64) +- **Homepage**: https://github.com/inference-gateway/cli + +#### Features + +- Interactive chat with AI models +- Autonomous agent execution with tool support +- Multiple storage backends (SQLite, PostgreSQL, Redis) +- Terminal UI with BubbleTea framework +- Extensive tool system + +#### Testing + +Tested on: +- [x] NixOS 24.11 (x86_64-linux) +- [x] macOS 14 Sonoma (aarch64-darwin) + +#### Checklist + +- [x] Built on NixOS +- [x] Built on macOS (if supported) +- [x] Binary runs and `infer version` works +- [x] Shell completions generated +- [x] All hashes are correct +- [x] `meta.description` is set +- [x] `meta.license` is correct +- [x] `meta.maintainers` includes me +- [x] Package follows [Go packaging guidelines](https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/go.section.md) + +#### Build instructions + +```bash +nix-build -A infer +result/bin/infer version +``` + +--- + +cc @NixOS/go-maintainers for review + +## Step 8: Respond to Review Feedback + +nixpkgs maintainers will review your PR. Common feedback: + +1. **Hash mismatches**: Recalculate and update +2. **Build failures**: Check build logs and fix +3. **Metadata issues**: Update `meta` attributes +4. **Naming conventions**: Ensure pname matches expectations +5. **Platform support**: Verify claimed platforms actually work + +Be responsive and make requested changes promptly. + +## Step 9: Maintenance After Merge + +Once merged, you're responsible for maintaining the package: + +### Updating to New Versions + +1. Wait for the nix-version-sync workflow to create a PR in the CLI repo +2. Merge that PR to update `nix/infer.nix` +3. Create an update PR in nixpkgs: + +```bash +cd nixpkgs +git checkout master +git pull upstream master +git checkout -b infer-0.77.0 + +# Update version and hashes in pkgs/by-name/in/infer/package.nix +# Copy from the updated nix/infer.nix in the CLI repo + +git add pkgs/by-name/in/infer/package.nix +git commit -m "infer: 0.76.1 -> 0.77.0" +git push origin infer-0.77.0 +``` + +4. Create PR with update + +### Automated Updates + +Consider using [nixpkgs-update](https://github.com/ryantm/nixpkgs-update) bot or setting up automation to detect new releases. + +### Handling Issues + +Monitor: + +- GitHub issues in the CLI repo that mention NixOS +- nixpkgs issues mentioning `infer` +- Build failures in Hydra (nixpkgs CI) + +## Useful Resources + +- [nixpkgs Manual - Go](https://nixos.org/manual/nixpkgs/stable/#sec-language-go) +- [nixpkgs Contributing Guide](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md) +- [Nix Pills](https://nixos.org/guides/nix-pills/) - Deep dive into Nix +- [nixpkgs Go Packaging](https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/go.section.md) +- [Ofborg Commands](https://github.com/NixOS/ofborg) - nixpkgs CI bot + +## Quick Reference + +### Build Commands + +```bash +# Local build in CLI repo +nix-build nix/infer.nix + +# Build in nixpkgs +nix-build -A infer + +# Build for specific platform +nix-build -A infer --arg system "aarch64-darwin" + +# Check what will be built +nix-instantiate -A infer +``` + +### Hash Calculation + +```bash +# Source hash +nix-prefetch-url --unpack https://github.com/inference-gateway/cli/archive/refs/tags/vVERSION.tar.gz + +# Vendor hash (build with empty string and read error) +nix-build -A infer 2>&1 | grep "got:" | grep -oP "sha256-[A-Za-z0-9+/=]+" +``` + +### Commit Messages + +```text +infer: init at 0.76.1 # New package +infer: 0.76.1 -> 0.77.0 # Version update +infer: fix build on aarch64 # Bug fix +infer: add shell completions # Enhancement +``` + +## Troubleshooting + +### Build fails with "hash mismatch" + +Recalculate the hash: + +```bash +nix-prefetch-url --unpack TARBALL_URL +``` + +### "vendor hash mismatch" + +Set `vendorHash = "";` and rebuild to get the correct hash from the error message. + +### "package not found" + +Ensure the package is in `pkgs/by-name/in/infer/package.nix` and the directory structure is correct. + +### CGO errors on macOS + +Ensure `darwin.apple_sdk.frameworks.Cocoa` is in `buildInputs` and `CGO_ENABLED = 1` for Darwin. + +### Tests fail in sandbox + +Some tests may require network or fail in the Nix sandbox. Use `checkFlags` to skip them: + +```nix +checkFlags = [ + "-skip=TestIntegration|TestNetwork" +]; +``` + +## Contact + +- **CLI Repository**: +- **nixpkgs Issues**: +- **NixOS Discourse**: diff --git a/nix/README.md b/nix/README.md new file mode 100644 index 00000000..ef9ecfc5 --- /dev/null +++ b/nix/README.md @@ -0,0 +1,206 @@ +# Nix Packaging for Inference Gateway CLI + +This directory contains the Nix package expression for building the Inference Gateway CLI with Nix. + +## Quick Start + +### Building Locally + +```bash +# Build the package +nix-build nix/infer.nix + +# Test the binary +./result/bin/infer version +./result/bin/infer --help + +# Install to user profile +nix-env -if nix/infer.nix +``` + +### Testing Before Release + +Before each release, ensure the Nix package builds correctly: + +```bash +# Clean build +nix-build nix/infer.nix --show-trace + +# Verify the binary works +./result/bin/infer version +./result/bin/infer chat --help + +# Check shell completions were generated +ls -la ./result/share/bash-completion/completions/ +ls -la ./result/share/fish/vendor_completions.d/ +ls -la ./result/share/zsh/site-functions/ +``` + +## Updating Hashes + +The package expression contains two hashes that must be updated for each release: + +### 1. Source Hash + +This is the hash of the GitHub source tarball: + +```bash +# Calculate for a specific version +VERSION="0.76.1" +nix-prefetch-url --unpack "https://github.com/inference-gateway/cli/archive/refs/tags/v${VERSION}.tar.gz" + +# Update in infer.nix: +# hash = "sha256-CALCULATED_HASH"; +``` + +### 2. Vendor Hash + +This is the hash of the Go module dependencies: + +```bash +# Set vendorHash to empty string in infer.nix +sed -i 's|vendorHash = "sha256-.*";|vendorHash = "";|' infer.nix + +# Attempt to build - it will fail with the correct hash +nix-build nix/infer.nix 2>&1 | tee build.log + +# Extract the hash from the error +grep "got:" build.log | grep -oP "sha256-[A-Za-z0-9+/=]+" + +# Update in infer.nix: +# vendorHash = "sha256-CALCULATED_HASH"; +``` + +## Automated Workflow + +The `.github/workflows/nix-version-sync.yml` workflow automatically: + +1. Triggers on new releases +2. Calculates both hashes +3. Updates `nix/infer.nix` +4. Creates a PR with the changes +5. Verifies the build succeeds + +You can also trigger it manually: + +```bash +# Via GitHub UI: Actions > Nix Version Sync > Run workflow +# Or via gh CLI: +gh workflow run nix-version-sync.yml -f version=0.76.1 +``` + +## CI Integration + +The `.github/workflows/nix-build.yml` workflow runs on every PR and push to verify: + +- Nix package builds on Linux (amd64, arm64) +- Nix package builds on macOS (amd64, arm64) +- Binary runs and `infer version` works +- Nix expression is properly formatted + +## Platform Support + +The package supports: + +- **Linux**: x86_64-linux, aarch64-linux +- **macOS**: x86_64-darwin, aarch64-darwin (requires CGO for clipboard) + +### macOS Notes + +macOS builds require CGO enabled for clipboard support (`golang.design/x/clipboard`): + +```nix +CGO_ENABLED = if stdenv.isDarwin then 1 else 0; + +buildInputs = lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Cocoa + darwin.apple_sdk.frameworks.UserNotifications +]; +``` + +## Submitting to nixpkgs + +Once the package builds successfully: + +1. Follow the [nixpkgs submission guide](../docs/nixpkgs-submission.md) +2. Ensure all hashes are correct (no placeholders) +3. Test on at least NixOS Linux and macOS +4. Submit PR to [NixOS/nixpkgs](https://github.com/NixOS/nixpkgs) + +## Troubleshooting + +### Build Fails with Hash Mismatch + +```bash +# Recalculate the hash +nix-prefetch-url --unpack "https://github.com/inference-gateway/cli/archive/refs/tags/vVERSION.tar.gz" +``` + +### Vendor Hash Mismatch + +```bash +# Set to empty string and rebuild to get correct hash +sed -i 's|vendorHash = ".*";|vendorHash = "";|' nix/infer.nix +nix-build nix/infer.nix 2>&1 | grep "got:" +``` + +### CGO Errors on macOS + +Ensure: + +- `CGO_ENABLED = 1` for Darwin +- `darwin.apple_sdk.frameworks.Cocoa` in buildInputs +- Xcode Command Line Tools are installed + +### Tests Fail in Sandbox + +Some tests may require network or fail in Nix sandbox. Use `checkFlags`: + +```nix +checkFlags = [ + "-skip=TestIntegration|TestNetwork" +]; +``` + +## Development + +### Local Testing with Different Go Versions + +```bash +# Override Go version +nix-build nix/infer.nix --arg go go_1_23 + +# With specific nixpkgs version +nix-build nix/infer.nix -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-24.11.tar.gz +``` + +### Formatting + +Format Nix files with nixpkgs-fmt: + +```bash +nix-shell -p nixpkgs-fmt --run "nixpkgs-fmt nix/" +``` + +### Checking Evaluation + +Ensure the expression evaluates without errors: + +```bash +nix-instantiate --eval --strict nix/infer.nix --show-trace +``` + +## Resources + +- [Nix Pills](https://nixos.org/guides/nix-pills/) +- [nixpkgs Manual - Go](https://nixos.org/manual/nixpkgs/stable/#sec-language-go) +- [nixpkgs Contributing](https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md) +- [Cachix](https://www.cachix.org/) - Binary cache for faster builds + +## Contact + +For issues with the Nix package: + +- Open an issue in this repository +- Tag with `nix` label +- Include build logs and system info diff --git a/nix/infer.nix b/nix/infer.nix new file mode 100644 index 00000000..8417e820 --- /dev/null +++ b/nix/infer.nix @@ -0,0 +1,84 @@ +{ lib +, buildGoModule +, fetchFromGitHub +, installShellFiles +, stdenv +, darwin +}: + +buildGoModule rec { + pname = "infer"; + version = "0.76.1"; + + src = fetchFromGitHub { + owner = "inference-gateway"; + repo = "cli"; + rev = "v${version}"; + hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # This will need to be updated with actual hash + }; + + vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # This will need to be calculated + + # macOS requires CGO for clipboard support (golang.design/x/clipboard) + CGO_ENABLED = if stdenv.isDarwin then 1 else 0; + + buildInputs = lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Cocoa + darwin.apple_sdk.frameworks.UserNotifications + ]; + + ldflags = [ + "-s" + "-w" + "-X github.com/inference-gateway/cli/cmd.version=${version}" + "-X github.com/inference-gateway/cli/cmd.commit=${src.rev}" + "-X github.com/inference-gateway/cli/cmd.date=1970-01-01T00:00:00Z" + ]; + + # Disable tests that require network or external dependencies + preCheck = '' + export HOME=$TMPDIR + ''; + + # Some tests may fail in the Nix sandbox due to networking requirements + checkFlags = [ + "-skip=TestIntegration" + ]; + + nativeBuildInputs = [ installShellFiles ]; + + postInstall = '' + # Rename binary from 'cli' to 'infer' if needed + if [ -f $out/bin/cli ]; then + mv $out/bin/cli $out/bin/infer + fi + + # Generate shell completions + installShellCompletion --cmd infer \ + --bash <($out/bin/infer completion bash) \ + --fish <($out/bin/infer completion fish) \ + --zsh <($out/bin/infer completion zsh) + ''; + + meta = with lib; { + description = "Command-line interface for the Inference Gateway - AI model interaction manager"; + longDescription = '' + The Inference Gateway CLI is a powerful command-line tool for managing AI model interactions. + It provides interactive chat, autonomous agent execution, and extensive tool integration for LLMs. + + Features: + - Interactive chat with various AI models + - Autonomous agent execution with tool support + - Clean Architecture with domain-driven design + - Multiple storage backends (SQLite, PostgreSQL, Redis) + - Terminal UI with BubbleTea framework + - Extensive tool system (Bash, Read, Write, Grep, A2A, etc.) + ''; + homepage = "https://github.com/inference-gateway/cli"; + changelog = "https://github.com/inference-gateway/cli/blob/main/CHANGELOG.md"; + license = licenses.mit; + maintainers = with maintainers; [ ]; # Add maintainer names here when submitting to nixpkgs + mainProgram = "infer"; + platforms = platforms.unix; + }; +} diff --git a/nix/update-hashes.sh b/nix/update-hashes.sh new file mode 100755 index 00000000..49053e3c --- /dev/null +++ b/nix/update-hashes.sh @@ -0,0 +1,147 @@ +#!/usr/bin/env bash +# +# Script to calculate and update Nix package hashes +# Usage: ./nix/update-hashes.sh [VERSION] +# Example: ./nix/update-hashes.sh 0.76.1 +# + +set -euo pipefail + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +# Get version from argument or extract from current infer.nix +if [ $# -eq 1 ]; then + VERSION="$1" +else + # Extract current version from infer.nix + VERSION=$(grep 'version = "' nix/infer.nix | head -1 | sed 's/.*version = "\(.*\)";/\1/') + echo -e "${YELLOW}No version specified, using current version from infer.nix: ${VERSION}${NC}" +fi + +# Validate version format +if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo -e "${RED}Error: Invalid version format. Expected X.Y.Z, got: ${VERSION}${NC}" + exit 1 +fi + +echo -e "${GREEN}Calculating hashes for version ${VERSION}...${NC}\n" + +# Check if nix-prefetch-url is available +if ! command -v nix-prefetch-url &> /dev/null; then + echo -e "${RED}Error: nix-prefetch-url not found. Please install Nix.${NC}" + exit 1 +fi + +# 1. Calculate source hash +echo -e "${YELLOW}[1/4] Calculating source hash...${NC}" +TARBALL_URL="https://github.com/inference-gateway/cli/archive/refs/tags/v${VERSION}.tar.gz" +echo "Fetching: ${TARBALL_URL}" + +SOURCE_HASH=$(nix-prefetch-url --unpack "$TARBALL_URL" 2>&1 | tail -1) + +if [ -z "$SOURCE_HASH" ]; then + echo -e "${RED}Error: Failed to calculate source hash${NC}" + exit 1 +fi + +echo -e "${GREEN}Source hash: sha256-${SOURCE_HASH}${NC}\n" + +# 2. Update version and source hash in infer.nix +echo -e "${YELLOW}[2/4] Updating version and source hash in infer.nix...${NC}" + +# Create backup +cp nix/infer.nix nix/infer.nix.bak + +# Update version +sed -i.tmp "s/version = \"[0-9.]*\";/version = \"${VERSION}\";/" nix/infer.nix + +# Update source hash +sed -i.tmp "s|hash = \"sha256-[A-Za-z0-9+/=]*\";|hash = \"sha256-${SOURCE_HASH}\";|" nix/infer.nix + +# Remove temp files +rm -f nix/infer.nix.tmp + +echo -e "${GREEN}Updated version and source hash${NC}\n" + +# 3. Calculate vendor hash +echo -e "${YELLOW}[3/4] Calculating vendor hash (this may take a minute)...${NC}" + +# Set vendorHash to empty to trigger the error with correct hash +sed -i.tmp 's|vendorHash = "sha256-[A-Za-z0-9+/=]*";|vendorHash = "";|' nix/infer.nix +rm -f nix/infer.nix.tmp + +# Try to build and capture the vendor hash from error +echo "Building to determine vendor hash..." +BUILD_OUTPUT=$(nix-build nix/infer.nix 2>&1 || true) + +# Extract vendor hash from the error message +VENDOR_HASH=$(echo "$BUILD_OUTPUT" | grep -oP "got:\s+sha256-\K[A-Za-z0-9+/=]+" | head -1) + +if [ -z "$VENDOR_HASH" ]; then + echo -e "${RED}Error: Failed to calculate vendor hash${NC}" + echo "Build output:" + echo "$BUILD_OUTPUT" + + # Restore backup + mv nix/infer.nix.bak nix/infer.nix + exit 1 +fi + +echo -e "${GREEN}Vendor hash: sha256-${VENDOR_HASH}${NC}\n" + +# 4. Update vendor hash in infer.nix +echo -e "${YELLOW}[4/4] Updating vendor hash in infer.nix...${NC}" + +sed -i.tmp "s|vendorHash = \"[^\"]*\";|vendorHash = \"sha256-${VENDOR_HASH}\";|" nix/infer.nix +rm -f nix/infer.nix.tmp + +# Remove backup if everything succeeded +rm -f nix/infer.nix.bak + +echo -e "${GREEN}✓ Successfully updated all hashes!${NC}\n" + +# Summary +echo "==========================================" +echo "Summary:" +echo "==========================================" +echo "Version: ${VERSION}" +echo "Source Hash: sha256-${SOURCE_HASH}" +echo "Vendor Hash: sha256-${VENDOR_HASH}" +echo "==========================================" +echo "" + +# Verify the build +echo -e "${YELLOW}Verifying build...${NC}" +if nix-build nix/infer.nix --show-trace; then + echo -e "${GREEN}✓ Build successful!${NC}\n" + + # Test the binary + echo -e "${YELLOW}Testing binary...${NC}" + if ./result/bin/infer version; then + echo -e "\n${GREEN}✓ Binary works correctly!${NC}\n" + + # Cleanup + echo -e "${YELLOW}Cleaning up build artifacts...${NC}" + rm -f result + + echo -e "${GREEN}==========================================" + echo "All done! ✓" + echo "==========================================${NC}" + echo "" + echo "Next steps:" + echo " 1. Review changes: git diff nix/infer.nix" + echo " 2. Commit changes: git add nix/infer.nix && git commit -m 'chore(nix): update to v${VERSION}'" + echo " 3. Push and verify CI: git push" + echo "" + else + echo -e "${RED}✗ Binary test failed${NC}" + exit 1 + fi +else + echo -e "${RED}✗ Build failed${NC}" + exit 1 +fi From c5ebea33063f96de59db38b48ecf38241a70e5f4 Mon Sep 17 00:00:00 2001 From: Eden Reich Date: Mon, 1 Dec 2025 11:53:55 +0200 Subject: [PATCH 2/6] chore: Use pinned versions Signed-off-by: Eden Reich --- .github/workflows/nix-build.yml | 6 +++--- .github/workflows/nix-version-sync.yml | 2 +- docs/nix-distribution-overview.md | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 6e591284..e1476b4c 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -29,9 +29,9 @@ jobs: fail-fast: false matrix: include: - - os: ubuntu-latest + - os: ubuntu-24.04 platform: linux-amd64 - - os: ubuntu-latest + - os: ubuntu-24.04 platform: linux-arm64 - os: macos-15-intel platform: darwin-amd64 @@ -104,7 +104,7 @@ jobs: summary: name: Build Summary - runs-on: ubuntu-latest + runs-on: ubuntu-24.0 needs: - nix-build - nix-fmt-check diff --git a/.github/workflows/nix-version-sync.yml b/.github/workflows/nix-version-sync.yml index 3fb374db..7dbd69b0 100644 --- a/.github/workflows/nix-version-sync.yml +++ b/.github/workflows/nix-version-sync.yml @@ -18,7 +18,7 @@ permissions: jobs: update-nix-version: name: Update Nix package version - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - name: Checkout repository diff --git a/docs/nix-distribution-overview.md b/docs/nix-distribution-overview.md index d4321a39..c655d4da 100644 --- a/docs/nix-distribution-overview.md +++ b/docs/nix-distribution-overview.md @@ -35,8 +35,8 @@ Runs on every PR and push to verify: **Matrix Testing:** -- ubuntu-latest (linux-amd64, linux-arm64) -- macos-13 (darwin-amd64, Intel Mac) +- ubuntu-24.04 (linux-amd64, linux-arm64) +- macos-15 (darwin-amd64, Intel Mac) - macos-latest (darwin-arm64, Apple Silicon) **Optimizations:** From 61d8ac731968ae34bd216472e9ddb0b248547cad Mon Sep 17 00:00:00 2001 From: Eden Reich Date: Mon, 1 Dec 2025 12:14:47 +0200 Subject: [PATCH 3/6] fix(nix): Fix build errors and update to modern Nix patterns - Add default.nix entry point for nix-build - Update workflow to use default.nix instead of infer.nix directly - Simplify Darwin framework handling (remove explicit framework dependencies) - Fix CGO_ENABLED to use env attribute set pattern - Update src hash: sha256-ObI6zG8noykPhPq6ESohbkHp6gvUY3Q0qYZl32Kj//I= - Update vendorHash: sha256-BUrb8mvktPPEbokccVEfc2UCLjWP0nTQbLeCxCCb32k= - Remove deprecated darwin.apple_sdk references These changes fix the Cachix build failures and follow modern Nix best practices for buildGoModule packages. Signed-off-by: Eden Reich --- .github/workflows/nix-build.yml | 4 ++-- nix/default.nix | 4 ++++ nix/infer.nix | 13 +++---------- 3 files changed, 9 insertions(+), 12 deletions(-) create mode 100644 nix/default.nix diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index e1476b4c..3f7d143e 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -59,7 +59,7 @@ jobs: - name: Build with Nix run: | - nix-build nix/infer.nix --show-trace + nix-build nix/default.nix --show-trace - name: Verify binary run: | @@ -100,7 +100,7 @@ jobs: - name: Evaluate Nix expression run: | - nix-instantiate --eval --strict nix/infer.nix --show-trace + nix-instantiate --eval --strict nix/default.nix --show-trace summary: name: Build Summary diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 00000000..9f01d3fb --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,4 @@ +# Default entry point for nix-build +{ pkgs ? import { } }: + +pkgs.callPackage ./infer.nix { } diff --git a/nix/infer.nix b/nix/infer.nix index 8417e820..443dc4d2 100644 --- a/nix/infer.nix +++ b/nix/infer.nix @@ -3,7 +3,6 @@ , fetchFromGitHub , installShellFiles , stdenv -, darwin }: buildGoModule rec { @@ -14,25 +13,19 @@ buildGoModule rec { owner = "inference-gateway"; repo = "cli"; rev = "v${version}"; - hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # This will need to be updated with actual hash + hash = "sha256-ObI6zG8noykPhPq6ESohbkHp6gvUY3Q0qYZl32Kj//I="; }; - vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; # This will need to be calculated + vendorHash = "sha256-BUrb8mvktPPEbokccVEfc2UCLjWP0nTQbLeCxCCb32k="; # macOS requires CGO for clipboard support (golang.design/x/clipboard) - CGO_ENABLED = if stdenv.isDarwin then 1 else 0; - - buildInputs = lib.optionals stdenv.isDarwin [ - darwin.apple_sdk.frameworks.Cocoa - darwin.apple_sdk.frameworks.UserNotifications - ]; + env.CGO_ENABLED = if stdenv.isDarwin then "1" else "0"; ldflags = [ "-s" "-w" "-X github.com/inference-gateway/cli/cmd.version=${version}" "-X github.com/inference-gateway/cli/cmd.commit=${src.rev}" - "-X github.com/inference-gateway/cli/cmd.date=1970-01-01T00:00:00Z" ]; # Disable tests that require network or external dependencies From 72be7831c2cf4c77fb2662ff797c49779ea5a66b Mon Sep 17 00:00:00 2001 From: Eden Reich Date: Mon, 1 Dec 2025 12:28:08 +0200 Subject: [PATCH 4/6] fix(ci): Fix ubuntu runner version typo in Build Summary job Change ubuntu-24.0 to ubuntu-24.04 to prevent job from hanging. Signed-off-by: Eden Reich --- .github/workflows/nix-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 3f7d143e..9972f1b5 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -104,7 +104,7 @@ jobs: summary: name: Build Summary - runs-on: ubuntu-24.0 + runs-on: ubuntu-24.04 needs: - nix-build - nix-fmt-check From 3b19f589c2d8068847ae008555fe20ce8fe88672 Mon Sep 17 00:00:00 2001 From: Eden Reich Date: Mon, 1 Dec 2025 13:01:17 +0200 Subject: [PATCH 5/6] refactor(nix): Simplify structure following nixpkgs conventions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename infer.nix → package.nix (standard nixpkgs name) - Update default.nix to reference package.nix - Remove redundant nixpkgs-submission/package.nix - Update submission README to reference ../package.nix - Add edenreich as maintainer Final structure: nix/package.nix - Main package definition nix/default.nix - Entry point wrapper nix/nixpkgs-submission/ - Submission guide Signed-off-by: Eden Reich --- nix/default.nix | 2 +- nix/nixpkgs-submission/README.md | 46 ++++++++++++++++++++++++++++++++ nix/{infer.nix => package.nix} | 4 +-- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 nix/nixpkgs-submission/README.md rename nix/{infer.nix => package.nix} (95%) diff --git a/nix/default.nix b/nix/default.nix index 9f01d3fb..dbe194e8 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,4 +1,4 @@ # Default entry point for nix-build { pkgs ? import { } }: -pkgs.callPackage ./infer.nix { } +pkgs.callPackage ./package.nix { } diff --git a/nix/nixpkgs-submission/README.md b/nix/nixpkgs-submission/README.md new file mode 100644 index 00000000..30f1e2f8 --- /dev/null +++ b/nix/nixpkgs-submission/README.md @@ -0,0 +1,46 @@ +# nixpkgs Submission + +Quick guide for submitting `inference-gateway-cli` to nixpkgs. + +## Steps + +```bash +# 1. Fork https://github.com/NixOS/nixpkgs +git clone https://github.com/YOUR_USERNAME/nixpkgs.git +cd nixpkgs +git checkout -b inference-gateway-cli-init + +# 2. Add maintainer info to maintainers/maintainer-list.nix +edenreich = { + email = "eden.reich@gmail.com"; + github = "edenreich"; + githubId = 16985712; + name = "Eden Reich"; +}; + +# 3. Copy package definition +mkdir -p pkgs/by-name/in/inference-gateway-cli +cp path/to/cli/nix/package.nix pkgs/by-name/in/inference-gateway-cli/package.nix + +# 4. Test build +nix-build -A inference-gateway-cli + +# 5. Commit and create PR +git add pkgs/by-name/in/inference-gateway-cli/package.nix maintainers/maintainer-list.nix +git commit -m "inference-gateway-cli: init at 0.76.1" +git push origin inference-gateway-cli-init +``` + +## Package Info + +- **Package**: `../package.nix` (use this file for submission) +- **Name**: `inference-gateway-cli` +- **Command**: `infer` +- **Version**: 0.76.1 +- **Status**: ✅ Builds on all platforms + +## Install After Merge + +```bash +nix profile install nixpkgs#inference-gateway-cli +``` diff --git a/nix/infer.nix b/nix/package.nix similarity index 95% rename from nix/infer.nix rename to nix/package.nix index 443dc4d2..d06454e4 100644 --- a/nix/infer.nix +++ b/nix/package.nix @@ -6,7 +6,7 @@ }: buildGoModule rec { - pname = "infer"; + pname = "inference-gateway-cli"; version = "0.76.1"; src = fetchFromGitHub { @@ -70,7 +70,7 @@ buildGoModule rec { homepage = "https://github.com/inference-gateway/cli"; changelog = "https://github.com/inference-gateway/cli/blob/main/CHANGELOG.md"; license = licenses.mit; - maintainers = with maintainers; [ ]; # Add maintainer names here when submitting to nixpkgs + maintainers = with maintainers; [ edenreich ]; mainProgram = "infer"; platforms = platforms.unix; }; From 9463c1b330c5dd0a390548d0d11bfadfaaa1ee75 Mon Sep 17 00:00:00 2001 From: Eden Reich Date: Mon, 1 Dec 2025 13:09:02 +0200 Subject: [PATCH 6/6] chore(ci): Remove Cachix setup from workflow Simplify CI by removing unused Cachix binary cache. Can be added back later if needed. Signed-off-by: Eden Reich --- .github/workflows/nix-build.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 9972f1b5..535422a8 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -50,13 +50,6 @@ jobs: experimental-features = nix-command flakes accept-flake-config = true - - name: Setup Cachix - uses: cachix/cachix-action@v15 - with: - name: inference-gateway - authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' - skipPush: ${{ github.event_name == 'pull_request' }} - - name: Build with Nix run: | nix-build nix/default.nix --show-trace