-
Notifications
You must be signed in to change notification settings - Fork 1
feat: milestone 1 - basic nix run setup #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, macos-latest] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: DeterminateSystems/nix-installer-action@main | ||
|
|
||
| - name: Check flake | ||
| run: nix flake check --accept-flake-config | ||
|
|
||
| - name: Build package | ||
| run: nix build . --accept-flake-config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Update Flake | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 0 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| update: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: DeterminateSystems/nix-installer-action@main | ||
|
|
||
| - uses: DeterminateSystems/update-flake-lock@main | ||
| id: update | ||
| with: | ||
| pr-title: "flake: update inputs" | ||
| pr-labels: dependencies | ||
| pr-assignees: ${{ github.repository_owner }} | ||
|
|
||
| - name: Enable auto-merge | ||
| if: steps.update.outputs.pull-request-number != '' | ||
| run: | | ||
| gh pr merge --auto --merge "${{ steps.update.outputs.pull-request-number }}" | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
|
|
||
| - name: Wait for CI | ||
| if: steps.update.outputs.pull-request-number != '' | ||
| run: | | ||
| gh pr checks "${{ steps.update.outputs.pull-request-number }}" --watch --fail-fast | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| # OpenCode Nix | ||
|
|
||
| > **Status: Work In Progress** - This project is under active development. | ||
|
|
||
| A Nix flake for running OpenCode with company-specific LiteLLM configuration. | ||
|
|
||
| ## Quick Start (Milestone 1 - Planned) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After this PR is merged, this is functional, no longer "Planned" |
||
|
|
||
| ```bash | ||
| nix run github:juspay/oc | ||
| ``` | ||
|
|
||
| ## Project Overview | ||
|
|
||
| This project provides a `nix run` way to quickly spin up [OpenCode](https://opencode.ai) using company-specific LiteLLM configuration. The implementation references [srid/nixos-config PR #103](https://github.com/srid/nixos-config/pull/103) (home-manager module). | ||
|
|
||
| ## Milestones | ||
|
|
||
| ### Milestone 1: Basic `nix run` Launch | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since milestone 1 is implemented, you can remove this detail or compress it to 1-line. |
||
|
|
||
| **Goal:** `nix run` launches opencode using [numtide/llm-agents.nix](https://github.com/numtide/llm-agents.nix). | ||
|
|
||
| **Tasks:** | ||
|
|
||
| 1. **Create `flake.nix` with llm-agents.nix input** | ||
| - Add `llm-agents.nix` as flake input | ||
| - Configure binary cache (required for pre-built packages): | ||
| ```nix | ||
| nixConfig = { | ||
| extra-substituters = [ "https://numtide.cachix.org" ]; | ||
| extra-trusted-public-keys = [ "numtide.cachix.org-1:2ps1kLBUWjxIneOy1Ik6cQjb41X0iXVXeHigGmycPPE=" ]; | ||
| }; | ||
| ``` | ||
| - Export opencode package as default app | ||
|
|
||
| 2. **GitHub Workflow for Daily Flake Updates** | ||
| - Create `.github/workflows/update-flake.yml` | ||
| - Use `DeterminateSystems/update-flake-lock` action | ||
| - Configure auto-merge when CI passes | ||
| - **Edge Cases:** | ||
| - Concurrent updates: Use rebase strategy to avoid conflicts | ||
| - CI failures: Do NOT auto-merge; create PR for manual review | ||
| - Token permissions: Need `contents: write` and `pull-requests: write` | ||
| - Branch protection: Auto-merge requires bypass or admin token | ||
| - **Workflow Schedule:** Daily at midnight UTC (`cron: '0 0 * * *'`) | ||
|
|
||
| 3. **Platform Support** | ||
| - Supported: `x86_64-linux`, `aarch64-linux`, `aarch64-darwin` | ||
| - Runtime dependencies (wrapped by llm-agents.nix): `fzf`, `ripgrep` | ||
|
|
||
| **Verification:** | ||
| ```bash | ||
| nix run . -- --help | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### Milestone 2: Company Configuration | ||
|
|
||
| **Goal:** Add Juspay-specific LiteLLM configuration from [PR #103](https://github.com/srid/nixos-config/pull/103). | ||
|
|
||
| **Tasks:** | ||
|
|
||
| 1. **Create home-manager module for opencode** | ||
| - The `programs.opencode` module is provided by [home-manager upstream](https://github.com/nix-community/home-manager/blob/master/modules/programs/opencode.nix) | ||
| - Available options: | ||
| - `programs.opencode.settings` - JSON config for opencode.json | ||
| - `programs.opencode.commands` - Custom slash commands | ||
| - `programs.opencode.agents` - Custom agent definitions | ||
| - Custom agent definitions | ||
| - `Custom agent definitions | ||
| - `programs = location gettingettings` | ||
| - `programs opencode | ||
| - Listrollup | ||
| żroll | ||
| - `Addition | ||
| - `agents` grams` commands | ||
|
|
||
| - `programs.opencode.skills` - Custom skills | ||
| - `programs.opencode.themes` - Custom themes | ||
| - `programs.opencode.tools` - Custom tools | ||
|
|
||
| 2. **Define Juspay Provider Configuration** | ||
| - Create `modules/juspay.nix` with provider settings: | ||
| ```nix | ||
| { | ||
| npm = "@ai-sdk/openai-compatible"; | ||
| name = "Juspay"; | ||
| options = { | ||
| baseURL = "https://grid.ai.juspay.net"; | ||
| apiKey = "{env:JUSPAY_API_KEY}"; # Environment variable | ||
| timeout = 600000; | ||
| }; | ||
| models = { ... }; # Import from models.nix | ||
| } | ||
| ``` | ||
| - **Edge Case:** The reference implementation uses `{file:...}` syntax with agenix secrets. For `nix run` standalone, use `{env:JUSPAY_API_KEY}` and require user to set the environment variable. | ||
|
|
||
| 3. **Define Available Models** | ||
| - Create `modules/models.nix` with model definitions: | ||
| - `open-large`, `open-fast`, `open-vision` | ||
| - `claude-opus-4-5`, `claude-opus-4-6`, `claude-sonnet-4-5`, `claude-sonnet-4-6` | ||
| - `glm-latest`, `glm-flash-experimental` | ||
| - `gemini-3-pro-preview`, `gemini-3-flash-preview` | ||
| - `minimax-m2`, `kimi-latest` | ||
| - Each model needs: `name`, `modalities`, `limit.context`, `limit.output` | ||
|
|
||
| 4. **Configure Default Settings** | ||
| - Default model: `litellm/glm-latest` | ||
| - Explore agent with `litellm/open-fast` for fast codebase search | ||
| - MCP: Enable deepwiki remote server | ||
| - **Edge Case:** The `agent.explore` configuration uses subagent mode for parallel search tasks. | ||
|
|
||
| 5. **Secret Handling** | ||
| - **Option A (Recommended for `nix run`):** Environment variable | ||
| - User sets: `export JUSPAY_API_KEY="..."` | ||
| - Config uses: `apiKey = "{env:JUSPAY_API_KEY}"` | ||
| - **Option B (For home-manager integration):** Agenix secrets | ||
| - Use `{file:/run/user/1000/agenix/juspay-anthropic-api-key}` | ||
| - Requires agenix setup in host config | ||
|
|
||
| 6. **Create Wrapper Script** | ||
| - Wrap opencode with environment setup | ||
| - Check for `JUSPAY_API_KEY` and warn if not set | ||
| - **Edge Case:** Some users may have multiple API keys; consider supporting `OPENCODE_API_KEY` as fallback. | ||
|
|
||
| **Verification:** | ||
| ```bash | ||
| export JUSPAY_API_KEY="your-key" | ||
| nix run . -- --help | ||
| # Verify config is generated at ~/.config/opencode/opencode.json | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Architecture | ||
|
|
||
| ``` | ||
| oc/ | ||
| ├── flake.nix # Main flake with inputs and outputs | ||
| ├── flake.lock # Locked dependencies | ||
| ├── modules/ | ||
| │ ├── default.nix # Default opencode configuration | ||
| │ ├── juspay.nix # Juspay provider + models | ||
| │ └── models.nix # Model definitions | ||
| ├── .github/ | ||
| │ └── workflows/ | ||
| │ └── update-flake.yml # Daily flake updates | ||
| └── README.md | ||
| ``` | ||
|
|
||
| ## Dependencies | ||
|
|
||
| - **Runtime:** `opencode` (from llm-agents.nix), `fzf`, `ripgrep` | ||
|
|
||
| ## Configuration Reference | ||
|
|
||
| The opencode configuration is written to `~/.config/opencode/opencode.json`. Key settings: | ||
|
|
||
| | Setting | Description | Default | | ||
| |---------|-------------|---------| | ||
| | `model` | Default model to use | `litellm/glm-latest` | | ||
| | `autoupdate` | Auto-update opencode | `true` | | ||
| | `provider.litellm` | Juspay LiteLLM provider | See modules/juspay.nix | | ||
| | `mcp.deepwiki` | DeepWiki MCP server | enabled | | ||
| | `agent.explore` | Fast explore subagent | `litellm/open-fast` | | ||
|
|
||
| ## Related | ||
|
|
||
| - [OpenCode Documentation](https://opencode.ai/docs/) | ||
| - [home-manager opencode module](https://github.com/nix-community/home-manager/blob/master/modules/programs/opencode.nix) | ||
| - [llm-agents.nix](https://github.com/numtide/llm-agents.nix) | ||
| - [Reference Implementation PR #103](https://github.com/srid/nixos-config/pull/103) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"with company-specific LiteLLM configuration" should not be in blurb.
Much preferably to use a generic description like "One-click access to OpenCode for Nix users"