Skip to content

aaronsox/utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

NixOS Utilities

Utility scripts for NixOS.


claude-nixos-patcher

Patches Claude Code binaries for NixOS after auto-updates.

NixOS setup

Steps 1 and 2 are the minimum. Step 3 automates patching on every rebuild.

1. Add claude-code to your packages in configuration.nix and rebuild:

  packages = with pkgs; [
    claude-code
  ];

2. Install and run the patcher:

cp claude-nixos-patcher ~/.local/bin/
chmod +x ~/.local/bin/claude-nixos-patcher

claude-nixos-patcher
claude

3. (Optional) Wire it into nixos-rebuild switch via an activation script so newly-downloaded versions are patched automatically after every rebuild:

system.activationScripts.claudeNixosPatcher = {
  text = ''
    if [ -x /home/yourname/.local/bin/claude-nixos-patcher ]; then
      /run/wrappers/bin/su - yourname -c '/home/yourname/.local/bin/claude-nixos-patcher' || true
    fi
  '';
  deps = [];
};

Why /run/wrappers/bin/su? Activation scripts run as root with a minimal PATH. su is a setuid binary that lives under /run/wrappers/bin/ on NixOS — full path required. The || true prevents a failed patch from aborting the entire rebuild.

The problem

Claude Code ships as a generic Linux ELF binary. Its ELF header hardcodes the dynamic linker path as /lib64/ld-linux-x86-64.so.2 — a path that doesn't exist on NixOS (where glibc lives in /nix/store/…). NixOS will refuse to execute any such binary:

Could not start dynamically linked executable: claude
NixOS cannot run dynamically linked executables intended for generic
linux environments out of the box.

patchelf rewrites the ELF interpreter field in-place to point at the correct glibc path in the nix store. After patching, the binary runs natively without any wrappers or FHS emulation.

Claude Code also self-updates: it downloads new versions to ~/.local/share/claude/versions/ and the newly-downloaded binaries are again un-patched generic Linux ELFs. This script handles all versions at once and is idempotent (skips already-patched binaries).

About

NixOS utility scripts — including claude-nixos-patcher for running Claude Code on NixOS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages