nixcfg/overlays/unstable/claude-code/package.nix

112 lines
3.1 KiB
Nix

# NOTE: Use the following command to update the package
# ```sh
# nix-shell maintainers/scripts/update.nix --argstr commit true --arg predicate '(path: pkg: builtins.elem path [["claude-code"] ["vscode-extensions" "anthropic" "claude-code"]])'
# ```
{
lib,
stdenvNoCC,
fetchurl,
installShellFiles,
makeBinaryWrapper,
autoPatchelfHook,
procps,
ripgrep,
bubblewrap,
socat,
versionCheckHook,
writableTmpDirAsHomeHook,
}:
let
stdenv = stdenvNoCC;
baseUrl = "https://storage.googleapis.com/claude-code-dist-86c565f3-f756-42ad-8dfa-d59b1c096819/claude-code-releases";
manifest = lib.importJSON ./manifest.json;
platformKey = "${stdenv.hostPlatform.node.platform}-${stdenv.hostPlatform.node.arch}";
platformManifestEntry = manifest.platforms.${platformKey};
in
stdenv.mkDerivation (finalAttrs: {
pname = "claude-code";
inherit (manifest) version;
src = fetchurl {
url = "${baseUrl}/${finalAttrs.version}/${platformKey}/claude";
sha256 = platformManifestEntry.checksum;
};
dontUnpack = true;
dontBuild = true;
__noChroot = stdenv.hostPlatform.isDarwin;
# otherwise the bun runtime is executed instead of the binary
dontStrip = true;
nativeBuildInputs = [
installShellFiles
makeBinaryWrapper
]
++ lib.optionals stdenv.hostPlatform.isElf [ autoPatchelfHook ];
strictDeps = true;
installPhase = ''
runHook preInstall
installBin $src
wrapProgram $out/bin/claude \
--set DISABLE_AUTOUPDATER 1 \
--set-default FORCE_AUTOUPDATE_PLUGINS 1 \
--set DISABLE_INSTALLATION_CHECKS 1 \
--set USE_BUILTIN_RIPGREP 0 \
--prefix PATH : ${
lib.makeBinPath (
[
# claude-code uses [node-tree-kill](https://github.com/pkrumins/node-tree-kill) which requires procps's pgrep(darwin) or ps(linux)
procps
# https://code.claude.com/docs/en/troubleshooting#search-and-discovery-issues
ripgrep
]
# the following packages are required for the sandbox to work (Linux only)
++ lib.optionals stdenv.hostPlatform.isLinux [
bubblewrap
socat
]
)
}
runHook postInstall
'';
doInstallCheck = true;
nativeInstallCheckInputs = [
writableTmpDirAsHomeHook
versionCheckHook
];
versionCheckKeepEnvironment = [ "HOME" ];
versionCheckProgramArg = "--version";
passthru.updateScript = ./update.sh;
meta = {
description = "Agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster";
homepage = "https://github.com/anthropics/claude-code";
downloadPage = "https://claude.com/product/claude-code";
changelog = "https://github.com/anthropics/claude-code/blob/main/CHANGELOG.md";
license = lib.licenses.unfree;
sourceProvenance = with lib.sourceTypes; [ binaryNativeCode ];
platforms = [
"aarch64-darwin"
"x86_64-darwin"
"aarch64-linux"
"x86_64-linux"
];
maintainers = with lib.maintainers; [
adeci
malo
markus1189
mirkolenz
omarjatoi
oskarwires
xiaoxiangmoe
];
mainProgram = "claude";
};
})