This Nix configuration provides a user-local installation of claude-code that doesn't require root permissions and won't interfere with auto-update capabilities.
- User-local installation: Installs to
~/.local/share/claude-code/npminstead of system directories - No sudo required: Uses npm prefix configuration to avoid permission issues
- Auto-update friendly: Includes a
claude-updatecommand for easy updates - Preserves npm behavior: Similar to using
.npmrcwith custom prefix - Includes dependencies: Automatically includes Node.js 18, git, and ripgrep
- Clone or download these files to a directory
- Enter the Nix shell:
nix-shell
- Run claude-code (it will auto-install on first use):
claude
cd /path/to/this/directory
nix-shell
claudeAdd to your /etc/nixos/configuration.nix:
environment.systemPackages = [
(import /path/to/claude-code.nix {})
];Add to your home-manager configuration:
home.packages = [
(import /path/to/claude-code.nix {})
];nix-env -i -f claude-code.nix- Run Claude Code:
claude - Update Claude Code:
claude-update
claude-code.nix: Main Nix derivation that creates the wrappershell.nix: Development shell for quick testingREADME.md: This documentation
The Nix derivation creates a wrapper script that:
- Sets up a user-local npm prefix (
~/.local/share/claude-code/npm) - Checks if claude-code is installed
- Installs it on first run if needed
- Executes claude-code with all provided arguments
This approach ensures:
- No system-wide npm modifications
- No sudo requirements
- Easy updates via npm
- Clean separation from system packages
If you encounter issues:
- Ensure you have at least 30 credits in your Anthropic account
- Check that
~/.local/share/claude-codehas proper permissions - Try manually removing the installation and letting it reinstall:
rm -rf ~/.local/share/claude-code claude # Will reinstall
- Claude Code will be installed on first run, not during Nix build time
- Updates are handled through npm, preserving the auto-update functionality
- The installation is completely isolated to your user directory