My collection of nix configurations
at main 124 lines 3.2 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 bun, 6 nodejs, 7 ast-grep, 8 makeWrapper, 9}: 10 11let 12 version = "3.12.3"; 13 14 # Fixed-output derivation to fetch node_modules with network access 15 nodeModules = stdenv.mkDerivation { 16 name = "oh-my-opencode-node-modules-${version}"; 17 18 src = fetchFromGitHub { 19 owner = "code-yeongyu"; 20 repo = "oh-my-openagent"; 21 rev = "v${version}"; 22 hash = "sha256-8iIpKs0R42NclKqNLfllByHNcKljRn33W8Ij7h0wYfw="; 23 }; 24 25 nativeBuildInputs = [ 26 bun 27 nodejs 28 ]; 29 30 buildPhase = '' 31 export HOME=$TMPDIR 32 export BUN_INSTALL_CACHE_DIR=$TMPDIR/bun-cache 33 # Install without optional dependencies (platform-specific binaries) 34 # We'll use ast-grep from nixpkgs instead 35 # Also ignore scripts to prevent build scripts from running with bad shebangs 36 bun install --frozen-lockfile --no-progress --no-optional --ignore-scripts 37 ''; 38 39 installPhase = '' 40 mkdir -p $out 41 cp -r node_modules $out/ 42 ''; 43 44 dontFixup = true; 45 46 outputHashMode = "recursive"; 47 outputHashAlgo = "sha256"; 48 outputHash = "sha256-P49FnMozYS1oTAfQEzh1bfayE0MiTJHAVcWcmsYc8I8="; 49 }; 50in 51stdenv.mkDerivation rec { 52 pname = "oh-my-opencode"; 53 inherit version; 54 55 src = fetchFromGitHub { 56 owner = "code-yeongyu"; 57 repo = "oh-my-openagent"; 58 rev = "v${version}"; 59 hash = "sha256-8iIpKs0R42NclKqNLfllByHNcKljRn33W8Ij7h0wYfw="; 60 }; 61 62 nativeBuildInputs = [ 63 bun 64 nodejs 65 ast-grep 66 makeWrapper 67 ]; 68 69 configurePhase = '' 70 runHook preConfigure 71 72 export HOME=$TMPDIR 73 # Copy pre-fetched node_modules 74 cp -r ${nodeModules}/node_modules . 75 chmod -R u+w node_modules 76 77 # Patch shebangs 78 patchShebangs node_modules/.bin 79 80 runHook postConfigure 81 ''; 82 83 buildPhase = '' 84 runHook preBuild 85 86 # Make ast-grep available during build 87 export PATH="${ast-grep}/bin:$PATH" 88 89 # Build: bun build src/index.ts --outdir dist --target bun --format esm --external @ast-grep/napi 90 # && tsc --emitDeclarationOnly 91 # && bun build src/cli/index.ts --outdir dist/cli --target bun --format esm --external @ast-grep/napi 92 # && bun run build:schema 93 94 # Run just the bun build commands, skip tsc and schema generation 95 bun build src/index.ts --outdir dist --target bun --format esm --external @ast-grep/napi 96 bun build src/cli/index.ts --outdir dist/cli --target bun --format esm --external @ast-grep/napi 97 98 runHook postBuild 99 ''; 100 101 installPhase = '' 102 runHook preInstall 103 104 mkdir -p $out/lib/node_modules/${pname} 105 cp -r dist package.json bin $out/lib/node_modules/${pname}/ 106 cp README.md LICENSE $out/lib/node_modules/${pname}/ 2>/dev/null || true 107 108 # The plugin includes a CLI - wrap it to ensure ast-grep is available 109 mkdir -p $out/bin 110 makeWrapper $out/lib/node_modules/${pname}/bin/oh-my-opencode.js \ 111 $out/bin/oh-my-opencode \ 112 --prefix PATH : ${ast-grep}/bin \ 113 --set NODE_PATH $out/lib/node_modules 114 115 runHook postInstall 116 ''; 117 118 meta = { 119 description = "Advanced orchestration plugin for OpenCode"; 120 homepage = "https://github.com/code-yeongyu/oh-my-openagent"; 121 license = lib.licenses.unfree; 122 mainProgram = "oh-my-opencode"; 123 }; 124}