From 27a4764e00ee58597223f3904c2b072fa80f94b3 Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Fri, 17 Oct 2025 21:09:27 +0000 Subject: [PATCH] claude-code-acp: init --- pkgs/by-name/cl/claude-code-acp/info.json | 5 ++ pkgs/by-name/cl/claude-code-acp/package.nix | 36 ++++++++++ pkgs/by-name/cl/claude-code-acp/update.mjs | 77 +++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 pkgs/by-name/cl/claude-code-acp/info.json create mode 100644 pkgs/by-name/cl/claude-code-acp/package.nix create mode 100755 pkgs/by-name/cl/claude-code-acp/update.mjs diff --git a/pkgs/by-name/cl/claude-code-acp/info.json b/pkgs/by-name/cl/claude-code-acp/info.json new file mode 100644 index 0000000..380453d --- /dev/null +++ b/pkgs/by-name/cl/claude-code-acp/info.json @@ -0,0 +1,5 @@ +{ + "version": "0.6.7", + "srcHash": "sha256-v32Q02ALWw6Upd4rrHGZH7Vt25+xSnKJCNGJob/irgM=", + "npmDepsHash": "sha256-oUAHkB4EPuo8YCxi9Y/Lc8cipjJQ05o51MpdUsCjiiQ=" +} diff --git a/pkgs/by-name/cl/claude-code-acp/package.nix b/pkgs/by-name/cl/claude-code-acp/package.nix new file mode 100644 index 0000000..3364fe0 --- /dev/null +++ b/pkgs/by-name/cl/claude-code-acp/package.nix @@ -0,0 +1,36 @@ +{ + lib, + buildNpmPackage, + fetchFromGitHub, +}: +let + info = lib.importJSON ./info.json; +in +buildNpmPackage { + pname = "claude-code-acp"; + version = info.version; + + src = fetchFromGitHub { + owner = "zed-industries"; + repo = "claude-code-acp"; + rev = "v${info.version}"; + hash = info.srcHash; + }; + + npmDepsHash = info.npmDepsHash; + + # The package uses TypeScript and builds before publishing + npmBuildScript = "build"; + + passthru = { + updateScript = ./update.mjs; + }; + + meta = { + description = "Use Claude Code from any ACP client such as Zed"; + homepage = "https://github.com/zed-industries/claude-code-acp"; + license = lib.licenses.asl20; + maintainers = with lib.maintainers; [ ]; + mainProgram = "claude-code-acp"; + }; +} diff --git a/pkgs/by-name/cl/claude-code-acp/update.mjs b/pkgs/by-name/cl/claude-code-acp/update.mjs new file mode 100755 index 0000000..b8675e3 --- /dev/null +++ b/pkgs/by-name/cl/claude-code-acp/update.mjs @@ -0,0 +1,77 @@ +#! /usr/bin/env nix-shell +/* +#! nix-shell -i zx -p nix-prefetch-github -p zx +*/ + +import { readFileSync, writeFileSync } from "fs"; +import { dirname, join } from "path"; +import { fileURLToPath } from "url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +// GitHub API endpoint for latest release +const GITHUB_API = "https://api.github.com/repos/zed-industries/claude-code-acp/releases/latest"; + +// Read current info.json +const infoPath = join(__dirname, "info.json"); +const currentInfo = JSON.parse(readFileSync(infoPath, "utf-8")); + +console.log(`Current version: ${currentInfo.version}`); + +// Fetch latest release from GitHub +console.log("Fetching latest release from GitHub..."); +const response = await fetch(GITHUB_API); +const release = await response.json(); + +const latestVersion = release.tag_name.replace(/^v/, ""); // Remove 'v' prefix +console.log(`Latest version: ${latestVersion}`); + +if (currentInfo.version === latestVersion) { + console.log("Already up to date!"); + process.exit(0); +} + +// Update version +currentInfo.version = latestVersion; + +// Prefetch source hash +console.log("Prefetching source hash..."); +const srcHashOutput = await $`nix-prefetch-github zed-industries claude-code-acp --rev v${latestVersion}`; +const srcPrefetch = JSON.parse(srcHashOutput.stdout); +currentInfo.srcHash = srcPrefetch.hash; + +console.log(`Source hash: ${currentInfo.srcHash}`); + +// Write temporary info.json to get npmDepsHash +writeFileSync(infoPath, JSON.stringify(currentInfo, null, 2) + "\n"); + +// Prefetch npm dependencies hash +console.log("Prefetching npm dependencies hash..."); +try { + // This will fail with the expected hash in the error message + await $`nix build .#claude-code-acp`; + +} catch (error) { + // Extract hash from error message + const errorOutput = error.stderr; + const hashMatch = errorOutput.match(/got:\s+(sha256-[A-Za-z0-9+/=]+)/); + + if (hashMatch) { + currentInfo.npmDepsHash = hashMatch[1]; + console.log(`npm deps hash: ${currentInfo.npmDepsHash}`); + } else { + console.error("Failed to extract npmDepsHash from build output"); + console.error("You may need to update it manually by running:"); + console.error(` nix-build -A claude-code-acp`); + console.error("and copying the hash from the error message"); + } +} + +// Write final info.json +writeFileSync(infoPath, JSON.stringify(currentInfo, null, 2) + "\n"); + +console.log("\nUpdate complete!"); +console.log(`Version: ${currentInfo.version}`); +console.log(`Source hash: ${currentInfo.srcHash}`); +console.log(`npm deps hash: ${currentInfo.npmDepsHash}`);