nix-hashlisted
Install: claude install-skill atvari-eu/nix-skills
# Nix Hash
## Hash Formats in Nix
Nix uses several hash encodings:
- **SRI** (`sha256-BASE64`) — The modern standard, used in `fetchFromGitHub`, `fetchurl`, etc. Format: `<algo>-<base64>`
- **Hex / base16** (`84a5d14c...`) — The encoding most upstream projects publish
- **Base32** (`020ay2q1...`) — Nix-specific legacy encoding; still printed by default by `nix-prefetch-url`
SRI is the preferred format. Always use SRI hashes in new derivations.
## Flat vs NAR Hashes
Which bytes get hashed depends on how the fetcher consumes the source:
- Raw file bytes ("flat") — matches plain `fetchurl` (no `unpack = true`). Compute with `nix hash file`.
- NAR serialisation of an unpacked tree — matches `fetchFromGitHub`, `fetchzip`, and any fetcher with `unpack = true`. Compute with `nix hash path`.
Prefetch accordingly: without unpacking for plain `fetchurl`, with unpacking when the fetcher extracts the archive. Getting this wrong is the most common cause of hash mismatches.
## Common Commands
### Converting Hashes
```bash
# Convert any hash to SRI (hex/base32 input auto-detected)
nix hash to-sri --type sha256 <hash>
# Convert SRI to hex
nix hash to-base16 --type sha256 <sri-hash>
```
On upstream Nix ≥ 2.19 these conversions also exist as `nix hash convert --to sri|base16|base32 --hash-algo sha256 <hash>`. Lix does not provide `nix hash convert`.
### Computing Hashes
```bash
# Raw bytes of a file (matches plain fetchurl); add --base16 for hex output
nix hash file --type sha25