|
| 1 | +{ |
| 2 | + description = "OpenCode - Terminal-based AI assistant for software development"; |
| 3 | + |
| 4 | + inputs = { |
| 5 | + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; |
| 6 | + treefmt-nix.url = "github:numtide/treefmt-nix"; |
| 7 | + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; |
| 8 | + }; |
| 9 | + |
| 10 | + outputs = { |
| 11 | + self, |
| 12 | + nixpkgs, |
| 13 | + treefmt-nix, |
| 14 | + ... |
| 15 | + }: let |
| 16 | + supportedSystems = [ |
| 17 | + "x86_64-linux" |
| 18 | + "x86_64-darwin" |
| 19 | + "aarch64-linux" |
| 20 | + "aarch64-darwin" |
| 21 | + ]; |
| 22 | + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; |
| 23 | + in { |
| 24 | + packages = forAllSystems (system: let |
| 25 | + pkgs = import nixpkgs { |
| 26 | + inherit system; |
| 27 | + }; |
| 28 | + in { |
| 29 | + default = pkgs.buildGo124Module { |
| 30 | + pname = "opencode"; |
| 31 | + version = "0.1.0"; |
| 32 | + src = self; |
| 33 | + vendorHash = "sha256-Kcwd8deHug7BPDzmbdFqEfoArpXJb1JtBKuk+drdohM="; |
| 34 | + doCheck = false; |
| 35 | + |
| 36 | + ldflags = [ |
| 37 | + "-s" |
| 38 | + "-w" |
| 39 | + ]; |
| 40 | + |
| 41 | + meta = with pkgs.lib; { |
| 42 | + description = "OpenCode - Terminal-based AI assistant for software development"; |
| 43 | + homepage = "https://github.com/opencode-ai/opencode"; |
| 44 | + license = licenses.mit; |
| 45 | + }; |
| 46 | + }; |
| 47 | + }); |
| 48 | + |
| 49 | + devShells = forAllSystems (system: let |
| 50 | + pkgs = import nixpkgs { |
| 51 | + inherit system; |
| 52 | + }; |
| 53 | + |
| 54 | + scripts = { |
| 55 | + gen = { |
| 56 | + exec = ''go generate ./...''; |
| 57 | + description = "Run code generation"; |
| 58 | + }; |
| 59 | + lint = { |
| 60 | + exec = ''golangci-lint run''; |
| 61 | + description = "Run Linting Steps for go files"; |
| 62 | + }; |
| 63 | + build = { |
| 64 | + exec = ''go build -o opencode .''; |
| 65 | + description = "Build the OpenCode CLI"; |
| 66 | + }; |
| 67 | + run = { |
| 68 | + exec = ''go run .''; |
| 69 | + description = "Run the OpenCode CLI"; |
| 70 | + }; |
| 71 | + tests = { |
| 72 | + exec = ''go test ./...''; |
| 73 | + description = "Run all go tests"; |
| 74 | + }; |
| 75 | + }; |
| 76 | + |
| 77 | + scriptPackages = |
| 78 | + pkgs.lib.mapAttrs |
| 79 | + ( |
| 80 | + name: script: |
| 81 | + pkgs.writeShellApplication { |
| 82 | + inherit name; |
| 83 | + text = script.exec; |
| 84 | + runtimeInputs = script.deps or []; |
| 85 | + } |
| 86 | + ) |
| 87 | + scripts; |
| 88 | + |
| 89 | + buildWithSpecificGo = pkg: pkg.override {buildGoModule = pkgs.buildGo124Module;}; |
| 90 | + in { |
| 91 | + default = pkgs.mkShell { |
| 92 | + name = "opencode-dev"; |
| 93 | + |
| 94 | + packages = with pkgs; |
| 95 | + [ |
| 96 | + # Nix tools |
| 97 | + alejandra |
| 98 | + nixd |
| 99 | + statix |
| 100 | + deadnix |
| 101 | + |
| 102 | + # Go Tools |
| 103 | + go_1_24 |
| 104 | + air |
| 105 | + golangci-lint |
| 106 | + gopls |
| 107 | + (buildWithSpecificGo revive) |
| 108 | + (buildWithSpecificGo golines) |
| 109 | + (buildWithSpecificGo golangci-lint-langserver) |
| 110 | + (buildWithSpecificGo gomarkdoc) |
| 111 | + (buildWithSpecificGo gotests) |
| 112 | + (buildWithSpecificGo gotools) |
| 113 | + (buildWithSpecificGo reftools) |
| 114 | + pprof |
| 115 | + graphviz |
| 116 | + goreleaser |
| 117 | + cobra-cli |
| 118 | + |
| 119 | + # CLI development tools |
| 120 | + sqlite |
| 121 | + ] |
| 122 | + ++ builtins.attrValues scriptPackages; |
| 123 | + |
| 124 | + shellHook = '' |
| 125 | + export REPO_ROOT=$(git rev-parse --show-toplevel) |
| 126 | + echo "OpenCode development environment loaded" |
| 127 | + echo "Run 'build' to build the CLI" |
| 128 | + echo "Run 'run' to start the OpenCode CLI" |
| 129 | + echo "Run 'tests' to run all tests" |
| 130 | + ''; |
| 131 | + }; |
| 132 | + }); |
| 133 | + |
| 134 | + # Runnable with: > nix fmt |
| 135 | + formatter = forAllSystems (system: let |
| 136 | + pkgs = nixpkgs.legacyPackages.${system}; |
| 137 | + treefmtModule = { |
| 138 | + projectRootFile = "flake.nix"; |
| 139 | + programs = { |
| 140 | + alejandra.enable = true; # Nix formatter |
| 141 | + gofmt.enable = true; # Go formatter |
| 142 | + }; |
| 143 | + }; |
| 144 | + in |
| 145 | + treefmt-nix.lib.mkWrapper pkgs treefmtModule); |
| 146 | + }; |
| 147 | +} |
0 commit comments