Skip to content

Instantly share code, notes, and snippets.

@MatrixManAtYrService
Created March 16, 2025 04:54
Show Gist options
  • Save MatrixManAtYrService/47c83952acece37598778c67c29711e3 to your computer and use it in GitHub Desktop.
Save MatrixManAtYrService/47c83952acece37598778c67c29711e3 to your computer and use it in GitHub Desktop.
claude code in a nix devshell
{ pkgs, claude-code-tarball, claude-code-version }:
pkgs.stdenv.mkDerivation {
name = "claude-code";
version = claude-code-version;
src = claude-code-tarball;
dontConfigure = true;
dontBuild = true;
installPhase = ''
mkdir -p $out/bin
mkdir -p $out/lib/node_modules/@anthropic-ai/claude-code
ls ${claude-code-tarball}
cp -r ${claude-code-tarball}/* $out/lib/node_modules/@anthropic-ai/claude-code/
cat > $out/bin/claude-code << EOF
#!/bin/sh
exec ${pkgs.nodejs}/bin/node $out/lib/node_modules/@anthropic-ai/claude-code/cli.js "\$@"
EOF
# Make the wrapper script executable
chmod +x $out/bin/claude-code
# Make the ripgrep binaries executable for all platforms
chmod +x $out/lib/node_modules/@anthropic-ai/claude-code/vendor/ripgrep/*/rg*
'';
buildInputs = [ pkgs.nodejs ];
}
{
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
claude-code-tarball = {
url = "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-0.2.45.tgz";
flake = false;
};
};
outputs = { self, nixpkgs, flake-utils, claude-code-tarball }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
claude-code = import ./claude.nix {
inherit pkgs claude-code-tarball;
claude-code-version = "0.2.45";
};
in
{
devShells.default = pkgs.mkShell {
packages = [
claude-code
];
};
});
}
@MatrixManAtYrService
Copy link
Author

MatrixManAtYrService commented Mar 16, 2025

There might be some AI generated idiocy in here, I haven't scrutinized it much, but it does work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment