Packaging Claude Code on NixOS

Packaging Claude Code on NixOS

4 Likes

Do you plan to submit your work on github.com/NixOS/nixpkgs ?

If it’d be appreciated sure :ok_hand:

1 Like

Definitely ! Submit a PR and you’ll get some feedback for sure!

claude-code: init at 0.2.9 by malob · Pull Request #384860 · NixOS/nixpkgs · GitHub was merged

7 Likes

Hello guys, we have a slight issue here:
I believe I am running version 0.2.30, which has a bug:

Error: No suitable shell found. Claude CLI requires a Posix shell environment. Please ensure you have a valid shell installed and the SHELL environment variable set.
    at i6.findSuitableShell (file:///nix/store/g2i9z5sij5gsgcly3fcsh9vw20q5ybk2-claude-code-0.2.30/lib/node_modules/@anthropic-ai/claude-code/cli.mjs:339:8036)
    at new i6 (file:///nix/store/g2i9z5sij5gsgcly3fcsh9vw20q5ybk2-claude-code-0.2.30/lib/node_modules/@anthropic-ai/claude-code/cli.mjs:339:5985)
    at i6.getInstance (file:///nix/store/g2i9z5sij5gsgcly3fcsh9vw20q5ybk2-claude-code-0.2.30/lib/node_modules/@anthropic-ai/claude-code/cli.mjs:339:8426)
    at process.<anonymous> (file:///nix/store/g2i9z5sij5gsgcly3fcsh9vw20q5ybk2-claude-code-0.2.30/lib/node_modules/@anthropic-ai/claude-code/cli.mjs:1167:5527)
    at process.emit (node:events:530:35)
    at process.emit (node:domain:489:12)
    at process.I [as emit] (file:///nix/store/g2i9z5sij5gsgcly3fcsh9vw20q5ybk2-claude-code-0.2.30/lib/node_modules/@anthropic-ai/claude-code/cli.mjs:139:26041)
    at process.exit (node:internal/process/per_thread:184:15)
    at Timeout._onTimeout (file:///nix/store/g2i9z5sij5gsgcly3fcsh9vw20q5ybk2-claude-code-0.2.30/lib/node_modules/@anthropic-ai/claude-code/cli.mjs:911:6268)
    at listOnTimeout (node:internal/timers:594:17)

according to this: Can't find $SHELL even though it exists · Issue #330 · anthropics/claude-code · GitHub , the workaround is to use latest version: 0.2.32

this seems to be resolvable with an overlay, my question is, if i can solve this myself, how do i upstream the latest version to nixpkgs so that nix folks who build from unstable channel will have version 0.2.32

thanks

Hi!

I think you could open up a PR to update it, looking at the files here: claude-code: init at 0.2.9 by malob · Pull Request #384860 · NixOS/nixpkgs · GitHub .

It looks like you’ll need to get the new hash and bump the version number. You might also see about adding yourself as a maintainer if you’d like. Then, tag the existing maintainers to review your PR. :slight_smile:

1 Like

hi,
its already done, i successfully applied overlay to run locally using nix-shell:

alice7@nixos ~/.d/c/claude-code> claude --version
0.2.32 (Claude Code)

i will be looking into the details of how to apply for PR. thanks for the information.

1 Like

Thanks for packaging this! It gives claude shell access, so I figured I’d at least run it in its own userspace and restrict its access. Not bulletproof, but force me to always diliberately grant it access to things rather than trusting it to do the right thing:

doas mkdir /opt/claude-code
doas chown claude:users /opt/claude-code
doas chmod 775 /opt/claude-code
doas su - claude
cd /opt/claude-code
claude

My plan is to just copy source directories there if I want to use claude-code to work on them.

Here’s my user definition:

      users.users.claude = {
        isNormalUser = true;
        packages = with pkgs; [
          unstable.claude-code
        ];
      };